From 94b1b9bc5cf72436ed88145359943b6c020db064 Mon Sep 17 00:00:00 2001 From: Alex Tideman Date: Tue, 3 Oct 2023 13:49:58 -0500 Subject: [PATCH] Timeline Improvements (#1658) * Add event filters, lock view from start to end * Make it better with tooltips, collapse vertical, event filters, label improvements * Don't follow mouse * Add togglebuttons group, add displayName to group, cleanup * Add Timeline to Accordion, use start/endOfMinute for min/max to provide a little zoomout ability to see all events * Remove paginated-table changes * Update snapshots and pass testid * Fix float tests * Remove event type filter in timeline * Add types * Fix strings to single quotes --- .../event/event-category-filter.svelte | 10 +- .../event/event-history-timeline-helpers.ts | 126 ++++++++++ .../event/event-history-timeline.svelte | 238 +++++++++++------- .../components/event/event-summary-row.svelte | 6 +- .../event/event-summary-table.svelte | 2 +- src/lib/components/event/event-summary.svelte | 2 +- src/lib/holocene/menu/menu-button.svelte | 10 +- src/lib/holocene/menu/menu-container.svelte | 2 +- src/lib/i18n/locales/en/common.ts | 1 + src/lib/i18n/locales/en/workflows.ts | 4 +- .../layouts/workflow-history-layout.svelte | 17 +- .../models/event-groups/create-event-group.ts | 11 +- src/lib/models/event-groups/event-groups.d.ts | 2 + src/lib/models/event-groups/get-group-name.ts | 61 ++++- .../models/event-groups/group-events.test.ts | 22 +- .../get-event-categorization.test.ts | 14 ++ .../event-history/get-event-categorization.ts | 4 + src/lib/pages/import-events-view.svelte | 2 +- src/lib/stores/workflow-run.ts | 5 + src/lib/utilities/get-float-style.test.ts | 4 +- src/lib/utilities/get-float-style.ts | 2 +- .../[run]/history/compact/+page.svelte | 2 +- .../[run]/history/feed/+page.svelte | 2 +- .../[workflow]/[run]/history/+page.svelte | 3 - 24 files changed, 412 insertions(+), 140 deletions(-) create mode 100644 src/lib/components/event/event-history-timeline-helpers.ts diff --git a/src/lib/components/event/event-category-filter.svelte b/src/lib/components/event/event-category-filter.svelte index d0df07671..1e4784d2a 100644 --- a/src/lib/components/event/event-category-filter.svelte +++ b/src/lib/components/event/event-category-filter.svelte @@ -8,6 +8,7 @@ MenuContainer, MenuItem, } from '$lib/holocene/menu'; + import type { MenuButtonVariant } from '$lib/holocene/menu/menu-button.svelte'; import { translate } from '$lib/i18n/translate'; import { allEventTypeOptions, @@ -19,6 +20,7 @@ import { isVersionNewer } from '$lib/utilities/version-check'; export let compact = false; + export let variant: MenuButtonVariant = 'table-header'; $: label = compact ? translate('events', 'event-type') @@ -27,8 +29,10 @@ let parameter = 'category'; let options = compact ? compactEventTypeOptions : allEventTypeOptions; - if (isVersionNewer('1.21', $temporalVersion)) { - options = options.filter(({ option }) => option !== 'update'); + $: { + if (isVersionNewer('1.21', $temporalVersion)) { + options = options.filter(({ option }) => option !== 'update'); + } } $: visibleOption = options.find( @@ -48,7 +52,7 @@ diff --git a/src/lib/components/event/event-history-timeline-helpers.ts b/src/lib/components/event/event-history-timeline-helpers.ts new file mode 100644 index 000000000..27bb1a5e5 --- /dev/null +++ b/src/lib/components/event/event-history-timeline-helpers.ts @@ -0,0 +1,126 @@ +import { get } from 'svelte/store'; + +import { endOfMinute, startOfMinute } from 'date-fns'; +import type { TimelineOptionsZoomKey } from 'vis-timeline'; + +import { relativeTime, timeFormat } from '$lib/stores/time-format'; +import type { WorkflowExecution } from '$lib/types/workflows'; +import { formatDate } from '$lib/utilities/format-date'; +import { formatDistanceAbbreviated } from '$lib/utilities/format-time'; + +type TimelineOptionsTooltipOverflow = 'flip' | 'none' | 'cap'; + +export const getTimelineOptions = (workflow: WorkflowExecution) => ({ + stackSubgroups: true, + maxHeight: 520, + min: startOfMinute(new Date(workflow.startTime)), + max: workflow?.endTime + ? endOfMinute(new Date(workflow?.endTime)) + : Date.now(), + horizontalScroll: true, + verticalScroll: true, + zoomKey: 'ctrlKey' as TimelineOptionsZoomKey, + orientation: { + axis: 'both', + item: 'center', + }, + tooltip: { + delay: 0, + overflowMethod: 'flip' as TimelineOptionsTooltipOverflow, + followMouse: false, + template: tooltipTemplate, + }, + rollingMode: { + follow: false, + }, + format: { + majorLabels: { + millisecond: 'D MMMM HH:mm:ss', + second: 'D MMMM HH:mm', + minute: 'ddd D MMMM', + hour: 'ddd D MMMM', + weekday: 'MMMM YYYY', + day: 'MMMM YYYY', + week: 'MMMM YYYY', + month: 'YYYY', + year: '', + }, + }, + xss: { + disabled: true, + filterOptions: { + whiteList: { + div: ['class'], + }, + }, + }, +}); + +export const tooltipTemplate = (item, _parsedItems): string => { + if (!item?.data?.eventList) return workflowExecutionTooltipTemplate(item); + if (item?.data.eventList.length === 1) + return singleEventTooltipTemplate(item); + return groupEventTooltipTemplate(item); +}; + +const workflowExecutionTooltipTemplate = (item): string => { + return `
+
Start
+
${formatDate(item.start, get(timeFormat), { + relative: get(relativeTime), + })} +
+
+
+
End
+
${formatDate(item.end, get(timeFormat), { + relative: get(relativeTime), + })}
+
+
Duration
${formatDistanceAbbreviated( + { + start: item.start, + end: item.end, + includeMilliseconds: true, + }, + )}
+
+
`; +}; + +const singleEventTooltipTemplate = (item): string => { + return `
+
Event Time
+
${formatDate(item.start, get(timeFormat), { + relative: get(relativeTime), + })} +
+
+
+ `; +}; + +const groupEventTooltipTemplate = (item): string => { + return `
+
Start
+
${formatDate(item.start, get(timeFormat), { + relative: get(relativeTime), + })} +
+
+
+
End
+
${formatDate(item.end, get(timeFormat), { + relative: get(relativeTime), + })}
+
+
Duration
${formatDistanceAbbreviated( + { + start: item.start, + end: item.end, + includeMilliseconds: true, + }, + )}
+
+
`; +}; diff --git a/src/lib/components/event/event-history-timeline.svelte b/src/lib/components/event/event-history-timeline.svelte index 9ffc013f7..f15711eae 100644 --- a/src/lib/components/event/event-history-timeline.svelte +++ b/src/lib/components/event/event-history-timeline.svelte @@ -1,76 +1,103 @@ -
{ + $workflowTimelineViewOpen = !$workflowTimelineViewOpen; + }} > -
-

Timeline

-
- - - +
+
+
+ + timeline.zoomIn(1)}>+ + timeline.zoomOut(1)}>- + timeline.focus('workflow')}>Fit + +
+
-
-
+