-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dashboard): new tab display w/ SelectionLink
- Loading branch information
Showing
7 changed files
with
188 additions
and
13 deletions.
There are no files selected for viewing
24 changes: 17 additions & 7 deletions
24
dashboard/src/app/[tenantId]/(diagram)/wfSpec/[...props]/actions/getScheduleWfSpec.ts
This file contains 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 |
---|---|---|
@@ -1,20 +1,30 @@ | ||
'use server' | ||
|
||
import { lhClient } from '@/app/lhClient' | ||
import { WithTenant } from '@/types' | ||
import { ScheduledWfRunIdList } from 'littlehorse-client/proto' | ||
import { ScheduledWfRun } from '../../../../../../../../sdk-js/dist/proto/scheduled_wf_run' | ||
|
||
type GetWfSpecProps = { | ||
name: string | ||
version: string | ||
} & WithTenant | ||
|
||
export const getScheduleWfSpec = async ({ name, version, tenantId }: GetWfSpecProps): Promise<ScheduledWfRunIdList> => { | ||
export const getScheduleWfSpec = async ({ name, version, tenantId }: GetWfSpecProps): Promise<ScheduledWfRun[]> => { | ||
const client = await lhClient({ tenantId }) | ||
|
||
const [majorVersion, revision] = version.split('.') | ||
return client.searchScheduledWfRun({ | ||
wfSpecName: name, | ||
majorVersion: parseInt(majorVersion) || 0, | ||
revision: parseInt(revision) | 0, | ||
}) | ||
|
||
return Promise.all( | ||
( | ||
await client.searchScheduledWfRun({ | ||
wfSpecName: name, | ||
majorVersion: parseInt(majorVersion) || 0, | ||
revision: parseInt(revision) | 0, | ||
}) | ||
).results.map(async scheduledWfRun => { | ||
return await client.getScheduledWfRun({ | ||
id: scheduledWfRun.id, | ||
}) | ||
}) | ||
) | ||
} |
64 changes: 64 additions & 0 deletions
64
dashboard/src/app/[tenantId]/(diagram)/wfSpec/[...props]/components/ScheduledWfRuns.tsx
This file contains 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,64 @@ | ||
import { ScheduledWfRunIdList, WfSpec } from 'littlehorse-client/proto' | ||
import { getScheduleWfSpec } from '../actions/getScheduleWfSpec' | ||
import { SelectionLink } from '@/app/[tenantId]/components/SelectionLink' | ||
import { ScheduledWfRun } from '../../../../../../../../sdk-js/dist/proto/scheduled_wf_run' | ||
import { FUTURE_TIME_RANGES, TimeRange } from '@/app/constants' | ||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' | ||
import { ClockIcon } from 'lucide-react' | ||
import { useEffect, useState } from 'react' | ||
import { getCronTimeWindow } from '@/app/utils/getCronTimeWindow' | ||
import { parseExpression } from 'cron-parser' | ||
import { utcToLocalDateTime } from '@/app/utils' | ||
import { SearchVariableDialog } from './SearchVariableDialog' | ||
|
||
export const ScheduledWfRuns = ({ scheduledWfRuns, spec }: { scheduledWfRuns: ScheduledWfRun[]; spec: WfSpec }) => { | ||
const [currentWindow, setWindow] = useState<TimeRange>(-1) | ||
const [filteredScheduledWfRuns, setFilteredScheduledWfRuns] = useState<ScheduledWfRun[]>(scheduledWfRuns) | ||
|
||
useEffect(() => { | ||
setFilteredScheduledWfRuns( | ||
scheduledWfRuns.filter(scheduledWfRun => { | ||
if (currentWindow === -1) return true | ||
|
||
const timeWindow = getCronTimeWindow(scheduledWfRun.cronExpression) | ||
return timeWindow && timeWindow <= currentWindow | ||
}) | ||
) | ||
}, [currentWindow, scheduledWfRuns]) | ||
|
||
return ( | ||
<div className="flex min-h-[500px] flex-col"> | ||
<div className="flex gap-4"> | ||
<Select value={currentWindow.toString()} onValueChange={value => setWindow(parseInt(value) as TimeRange)}> | ||
<SelectTrigger className="w-[150px] min-w-fit"> | ||
<div className="flex items-center gap-2"> | ||
<ClockIcon className="h-5 w-5 fill-none stroke-black" /> | ||
<SelectValue>{FUTURE_TIME_RANGES.find(time => time.value === currentWindow)?.label}</SelectValue> | ||
</div> | ||
</SelectTrigger> | ||
<SelectContent> | ||
{FUTURE_TIME_RANGES.map(time => ( | ||
<SelectItem key={time.value} value={time.value.toString()}> | ||
{time.label} | ||
</SelectItem> | ||
))} | ||
</SelectContent> | ||
</Select> | ||
{/* {Object.keys(spec.threadSpecs).flatMap(threadSpec => | ||
spec.threadSpecs[threadSpec].variableDefs.filter(variableDef => variableDef.searchable) | ||
).length > 0 && <SearchVariableDialog spec={spec} />} */} | ||
</div> | ||
<div className="mt-4 flex flex-col"> | ||
{filteredScheduledWfRuns.map(scheduledWfRun => ( | ||
<SelectionLink aria-disabled key={scheduledWfRun.id?.id} href={undefined}> | ||
<p>{scheduledWfRun.id?.id}</p> | ||
<div className="flex items-center gap-2 rounded-md bg-gray-200 p-1 text-sm"> | ||
<ClockIcon className="h-5 w-5 fill-none stroke-black" /> | ||
<p>{utcToLocalDateTime(parseExpression(scheduledWfRun.cronExpression).next().toDate().toISOString())}</p> | ||
</div> | ||
</SelectionLink> | ||
))} | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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,18 @@ | ||
import { parseExpression } from 'cron-parser' | ||
|
||
import { FUTURE_TIME_RANGES } from '@/app/constants' | ||
export function getCronTimeWindow(cronExpression: string): number | undefined { | ||
try { | ||
const interval = parseExpression(cronExpression) | ||
const nextExecution = interval.next().toDate() | ||
const now = new Date() | ||
const minutesUntil = (nextExecution.getTime() - now.getTime()) / (1000 * 60) | ||
|
||
const timeWindow = FUTURE_TIME_RANGES.find(range => minutesUntil <= range.value) | ||
|
||
return timeWindow?.value ?? undefined | ||
} catch (error) { | ||
console.error('Invalid cron expression:', error) | ||
return undefined | ||
} | ||
} |
This file contains 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,55 @@ | ||
'use client' | ||
|
||
import * as React from 'react' | ||
import * as TabsPrimitive from '@radix-ui/react-tabs' | ||
|
||
import { cn } from '@/components/utils' | ||
|
||
const Tabs = TabsPrimitive.Root | ||
|
||
const TabsList = React.forwardRef< | ||
React.ElementRef<typeof TabsPrimitive.List>, | ||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List> | ||
>(({ className, ...props }, ref) => ( | ||
<TabsPrimitive.List | ||
ref={ref} | ||
className={cn( | ||
'inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground', | ||
className | ||
)} | ||
{...props} | ||
/> | ||
)) | ||
TabsList.displayName = TabsPrimitive.List.displayName | ||
|
||
const TabsTrigger = React.forwardRef< | ||
React.ElementRef<typeof TabsPrimitive.Trigger>, | ||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger> | ||
>(({ className, ...props }, ref) => ( | ||
<TabsPrimitive.Trigger | ||
ref={ref} | ||
className={cn( | ||
'inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm', | ||
className | ||
)} | ||
{...props} | ||
/> | ||
)) | ||
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName | ||
|
||
const TabsContent = React.forwardRef< | ||
React.ElementRef<typeof TabsPrimitive.Content>, | ||
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content> | ||
>(({ className, ...props }, ref) => ( | ||
<TabsPrimitive.Content | ||
ref={ref} | ||
className={cn( | ||
'mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2', | ||
className | ||
)} | ||
{...props} | ||
/> | ||
)) | ||
TabsContent.displayName = TabsPrimitive.Content.displayName | ||
|
||
export { Tabs, TabsList, TabsTrigger, TabsContent } |