Skip to content

Commit

Permalink
Merge pull request #992 from OpenFn/default-show-last-30-days
Browse files Browse the repository at this point in the history
Show workorders with runs in last 30 days by default
  • Loading branch information
taylordowns2000 authored Jul 28, 2023
2 parents 83c69f0 + e6687f8 commit 10b80f9
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 180 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ and this project adheres to

### Changed

- Unless otherwise specified, only show workorders with activity in last 14 days
[#968](https://github.com/OpenFn/Lightning/issues/968)

### Fixed

## [v0.7.0-pre4] - 2023-07-27
Expand Down
7 changes: 5 additions & 2 deletions lib/lightning/invocation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -346,8 +346,11 @@ defmodule Lightning.Invocation do

def filter_run_finished_after_where(date_after) do
case date_after do
d when d in ["", nil] -> dynamic(true)
_ -> dynamic([runs: r], r.finished_at >= ^date_after)
d when d in ["", nil] ->
dynamic(true)

_ ->
dynamic([runs: r], r.finished_at >= ^date_after or is_nil(r.finished_at))
end
end

Expand Down
36 changes: 11 additions & 25 deletions lib/lightning_web/live/run_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ defmodule LightningWeb.RunLive.Index do
do: %{
"body" => "true",
"crash" => "true",
"date_after" => "",
"date_after" =>
Timex.now() |> Timex.shift(days: -30) |> DateTime.to_string(),
"date_before" => "",
"failure" => "true",
"log" => "true",
Expand All @@ -101,33 +102,18 @@ defmodule LightningWeb.RunLive.Index do

@impl true
def handle_params(params, _url, socket) do
if is_nil(Map.get(params, "filters")) do
params = Map.put(params, "filters", socket.assigns.filters)

{:noreply,
socket
|> assign(
page_title: "History",
run: %Run{},
filters_changeset: filters_changeset(socket.assigns.filters)
)
|> push_patch(
to: ~p"/projects/#{socket.assigns.project.id}/runs?#{params}"
)}
else
{:noreply,
socket
|> assign(
page_title: "History",
run: %Run{},
filters_changeset: filters_changeset(socket.assigns.filters)
)
|> apply_action(socket.assigns.live_action, params)}
end
{:noreply,
socket
|> assign(
page_title: "History",
run: %Run{},
filters_changeset: filters_changeset(socket.assigns.filters)
)
|> apply_action(socket.assigns.live_action, params)}
end

defp apply_action(socket, :index, params) do
filters = Map.get(params, "filters") |> SearchParams.new()
filters = Map.get(params, "filters", init_filters()) |> SearchParams.new()

socket
|> assign(
Expand Down
42 changes: 21 additions & 21 deletions lib/lightning_web/live/run_live/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,29 @@
/>
</div>
<div>
<div class="font-semibold my-4">
<div class="font-semibold mt-4">
Filter workorders by last run date
</div>
<div class="flex justify-between text-sm text-gray-500">
<div>
<label>After</label>
<%= datetime_local_input(f, :date_after,
class:
"mt-1 block w-44 rounded-md border-secondary-300 shadow-sm focus:border-primary-300 focus:ring focus:ring-primary-200 focus:ring-opacity-50"
) %>
</div>
<div>
<label>Before</label>
<%= datetime_local_input(f, :date_before,
class:
"mt-1 block w-44 rounded-md border-secondary-300 shadow-sm focus:border-primary-300 focus:ring focus:ring-primary-200 focus:ring-opacity-50"
) %>
</div>
</div>
<div class="font-semibold mt-4">
Filter workorders by date received
</div>
<div class="flex justify-between">
<div class="flex justify-between text-sm text-gray-500">
<div>
<label>After</label>
<%= datetime_local_input(f, :wo_date_after,
Expand All @@ -186,25 +205,6 @@
</div>
</div>
</div>
<div class="font-semibold my-4">
Filter workorders by last run date
</div>
<div class="flex justify-between">
<div>
<label>After</label>
<%= datetime_local_input(f, :date_after,
class:
"mt-1 block w-44 rounded-md border-secondary-300 shadow-sm focus:border-primary-300 focus:ring focus:ring-primary-200 focus:ring-opacity-50"
) %>
</div>
<div>
<label>Before</label>
<%= datetime_local_input(f, :date_before,
class:
"mt-1 block w-44 rounded-md border-secondary-300 shadow-sm focus:border-primary-300 focus:ring focus:ring-primary-200 focus:ring-opacity-50"
) %>
</div>
</div>
<div id="status_options-container">
<div class="font-semibold mt-4">
Filter by workorder status
Expand Down
Loading

0 comments on commit 10b80f9

Please sign in to comment.