-
Notifications
You must be signed in to change notification settings - Fork 2
feat: build trigger ui #389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0dfab6a
feat: build trigger ui
Scr4tch587 b7c078a
docs: document build trigger in frontend spec
Scr4tch587 fa63c4d
Merge branch 'kai/build-api-client' into kai/build-ui
Scr4tch587 21bf5fc
Merge branch 'kai/build-ui' into kai/build-ui-docs
Scr4tch587 0a28182
Merge branch 'kai/build-api-client' into kai/build-ui
Scr4tch587 3ceed3e
Merge branch 'kai/build-ui' into kai/build-ui-docs
Scr4tch587 fe0b865
Merge pull request #390 from Wat-Street/kai/build-ui-docs
Scr4tch587 19b08fb
fix: default to dry run, confirm real builds, guard inverted ranges
Scr4tch587 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,148 @@ | ||
| import { useMutation, useQueryClient } from "@tanstack/react-query"; | ||
| import { useState } from "react"; | ||
| import { toast } from "sonner"; | ||
|
|
||
| import type { BuildResponse, DataRow, DryRunBuildResponse } from "@/lib/api"; | ||
|
|
||
| import { DataTable } from "@/components/data-table"; | ||
| import { JsonModal } from "@/components/json-modal"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { Checkbox } from "@/components/ui/checkbox"; | ||
| import { Input } from "@/components/ui/input"; | ||
| import { Label } from "@/components/ui/label"; | ||
| import { dryRunBuild, triggerBuild } from "@/lib/api"; | ||
| import { toISODate } from "@/lib/format"; | ||
|
|
||
| // dry-run output is previewed inline, not paginated; cap it to keep the dom sane | ||
| const DRY_RUN_PREVIEW_LIMIT = 50; | ||
|
|
||
| // builds are heavier than reads, so default to a month instead of the 5-year browse window | ||
| function defaultBuildRange(): { start: string; end: string } { | ||
| const end = new Date(); | ||
| const start = new Date(end); | ||
| start.setDate(start.getDate() - 30); | ||
| return { start: toISODate(start), end: toISODate(end) }; | ||
| } | ||
|
|
||
| interface BuildPanelProps { | ||
| name: string; | ||
| version: string; | ||
| } | ||
|
|
||
| /** | ||
| * triggers builds for a date range. real builds write missing timestamps to | ||
| * the db and refresh the data table; dry runs preview the produced rows | ||
| * without writing anything. | ||
| */ | ||
| export function BuildPanel({ name, version }: BuildPanelProps) { | ||
| const [startDate, setStartDate] = useState(() => defaultBuildRange().start); | ||
| const [endDate, setEndDate] = useState(() => defaultBuildRange().end); | ||
| const [dryRun, setDryRun] = useState(false); | ||
| const [dryRunRows, setDryRunRows] = useState<DataRow[] | null>(null); | ||
| const [selectedRow, setSelectedRow] = useState<Record< | ||
| string, | ||
| unknown | ||
| > | null>(null); | ||
|
|
||
| const queryClient = useQueryClient(); | ||
|
|
||
| const mutation = useMutation< | ||
| BuildResponse | DryRunBuildResponse, | ||
| Error, | ||
| { dryRun: boolean } | ||
| >({ | ||
| mutationFn: (opts) => | ||
| opts.dryRun | ||
| ? dryRunBuild(name, version, startDate, endDate) | ||
| : triggerBuild(name, version, startDate, endDate), | ||
| onSuccess: (result) => { | ||
| if ("rows" in result) { | ||
| setDryRunRows(result.rows); | ||
| toast.success(`dry run produced ${result.rows.length} timestamps`); | ||
| return; | ||
| } | ||
| setDryRunRows(null); | ||
| toast.success(`build complete for ${name}/${version}`); | ||
| // refetch the data table and the has_data dot on the list view | ||
| void queryClient.invalidateQueries({ queryKey: ["data", name, version] }); | ||
| void queryClient.invalidateQueries({ queryKey: ["datasets"] }); | ||
| }, | ||
| }); | ||
|
|
||
| const previewRows = dryRunRows?.slice(0, DRY_RUN_PREVIEW_LIMIT); | ||
|
|
||
| return ( | ||
| <div className="space-y-3 rounded-md border p-4"> | ||
| <h3 className="text-sm font-medium">build data</h3> | ||
| <div className="flex flex-wrap items-end gap-4"> | ||
| <div className="space-y-1.5"> | ||
| <Label htmlFor="build-start">start</Label> | ||
| <Input | ||
| id="build-start" | ||
| type="date" | ||
| value={startDate} | ||
| onChange={(e) => setStartDate(e.target.value)} | ||
| className="w-40" | ||
| /> | ||
| </div> | ||
| <div className="space-y-1.5"> | ||
| <Label htmlFor="build-end">end</Label> | ||
| <Input | ||
| id="build-end" | ||
| type="date" | ||
| value={endDate} | ||
| onChange={(e) => setEndDate(e.target.value)} | ||
| className="w-40" | ||
| /> | ||
| </div> | ||
| <div className="flex items-center gap-2 pb-2.5"> | ||
| <Checkbox | ||
| id="build-dry-run" | ||
| checked={dryRun} | ||
| onCheckedChange={(checked) => setDryRun(checked === true)} | ||
| /> | ||
| <Label htmlFor="build-dry-run">dry run</Label> | ||
| </div> | ||
| <Button | ||
| size="sm" | ||
| className="mb-0.5" | ||
| disabled={mutation.isPending || !startDate || !endDate} | ||
|
Scr4tch587 marked this conversation as resolved.
Outdated
|
||
| onClick={() => mutation.mutate({ dryRun })} | ||
| > | ||
| {mutation.isPending | ||
| ? "building..." | ||
| : dryRun | ||
| ? "preview build" | ||
| : "build"} | ||
| </Button> | ||
| </div> | ||
|
|
||
| {mutation.isPending && ( | ||
| <p className="text-muted-foreground text-sm"> | ||
| builds run synchronously on the server — large ranges can take a | ||
| while... | ||
| </p> | ||
| )} | ||
|
|
||
| {mutation.isError && ( | ||
| <div className="border-destructive/50 rounded-md border p-3"> | ||
| <p className="text-destructive text-sm">{mutation.error.message}</p> | ||
| </div> | ||
| )} | ||
|
|
||
| {previewRows && dryRunRows && ( | ||
| <div className="space-y-2"> | ||
| <p className="text-muted-foreground text-sm"> | ||
| dry run produced {dryRunRows.length} timestamps — nothing was | ||
| written to the database | ||
| {dryRunRows.length > DRY_RUN_PREVIEW_LIMIT && | ||
| ` (showing first ${DRY_RUN_PREVIEW_LIMIT})`} | ||
| </p> | ||
| <DataTable rows={previewRows} onRowClick={setSelectedRow} /> | ||
| </div> | ||
| )} | ||
|
|
||
| <JsonModal data={selectedRow} onClose={() => setSelectedRow(null)} /> | ||
| </div> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.