From e2f652dc631bd45b73907101ac4f89f7d5c0b0f1 Mon Sep 17 00:00:00 2001 From: prha Date: Tue, 20 Aug 2024 17:43:45 -0700 Subject: [PATCH] switch tick filters to contained set rather than every permutation --- .../ui-core/src/instigation/TickHistory.tsx | 126 ++++++++++-------- 1 file changed, 71 insertions(+), 55 deletions(-) diff --git a/js_modules/dagster-ui/packages/ui-core/src/instigation/TickHistory.tsx b/js_modules/dagster-ui/packages/ui-core/src/instigation/TickHistory.tsx index c1949f0531cd4..b7768959385f0 100644 --- a/js_modules/dagster-ui/packages/ui-core/src/instigation/TickHistory.tsx +++ b/js_modules/dagster-ui/packages/ui-core/src/instigation/TickHistory.tsx @@ -3,15 +3,18 @@ import 'chartjs-adapter-date-fns'; import {gql, useQuery} from '@apollo/client'; import { Box, + Button, ButtonLink, Caption, - Checkbox, Colors, CursorHistoryControls, FontFamily, Icon, IconWrapper, + Menu, + MenuItem, NonIdealState, + Select, Spinner, Subheading, Table, @@ -55,24 +58,22 @@ Chart.register(zoomPlugin); type InstigationTick = HistoryTickFragment; const PAGE_SIZE = 25; -interface ShownStatusState { - [InstigationTickStatus.SUCCESS]: boolean; - [InstigationTickStatus.FAILURE]: boolean; - [InstigationTickStatus.STARTED]: boolean; - [InstigationTickStatus.SKIPPED]: boolean; + +enum TickStatusDisplay { + ALL, + FAILED, + SUCCESS, } -const DEFAULT_SHOWN_STATUS_STATE = { - [InstigationTickStatus.SUCCESS]: true, - [InstigationTickStatus.FAILURE]: true, - [InstigationTickStatus.STARTED]: true, - [InstigationTickStatus.SKIPPED]: true, -}; -const STATUS_TEXT_MAP = { - [InstigationTickStatus.SUCCESS]: 'Requested', - [InstigationTickStatus.FAILURE]: 'Failed', - [InstigationTickStatus.STARTED]: 'In progress', - [InstigationTickStatus.SKIPPED]: 'Skipped', +const STATUS_DISPLAY_MAP = { + [TickStatusDisplay.ALL]: [ + InstigationTickStatus.SUCCESS, + InstigationTickStatus.FAILURE, + InstigationTickStatus.STARTED, + InstigationTickStatus.SKIPPED, + ], + [TickStatusDisplay.FAILED]: [InstigationTickStatus.FAILURE], + [TickStatusDisplay.SUCCESS]: [InstigationTickStatus.SUCCESS], }; export const TicksTable = ({ @@ -88,33 +89,15 @@ export const TicksTable = ({ setTimerange?: (range?: [number, number]) => void; setParentStatuses?: (statuses?: InstigationTickStatus[]) => void; }) => { - const [shownStates, setShownStates] = useQueryPersistedState({ - encode: (states) => { - const queryState = {}; - Object.keys(states).map((state) => { - (queryState as any)[state.toLowerCase()] = String(states[state as keyof typeof states]); - }); - return queryState; - }, - decode: (queryState) => { - const status: ShownStatusState = {...DEFAULT_SHOWN_STATUS_STATE}; - Object.keys(DEFAULT_SHOWN_STATUS_STATE).forEach((state) => { - if (state.toLowerCase() in queryState) { - (status as any)[state] = !(queryState[state.toLowerCase()] === 'false'); - } - }); - - return status; - }, + const [tickStatus, setTickStatus] = useQueryPersistedState({ + queryKey: 'status', + defaults: {status: TickStatusDisplay.ALL}, }); const instigationSelector = {...repoAddressToSelector(repoAddress), name}; const statuses = React.useMemo( - () => - Object.keys(shownStates) - .filter((status) => shownStates[status as keyof typeof shownStates]) - .map((status) => status as InstigationTickStatus), - [shownStates], + () => STATUS_DISPLAY_MAP[tickStatus] || STATUS_DISPLAY_MAP[TickStatusDisplay.ALL], + [tickStatus], ); const {queryResult, paginationProps} = useCursorPaginatedQuery< @@ -205,20 +188,10 @@ export const TicksTable = ({ const {instigationType} = data.instigationStateOrError; - if (!ticks.length && statuses.length === Object.keys(DEFAULT_SHOWN_STATUS_STATE).length) { + if (!ticks.length && tickStatus === TickStatusDisplay.ALL) { return null; } - const StatusFilter = ({status}: {status: InstigationTickStatus}) => ( - ) => { - setShownStates({...shownStates, [status]: e.target.checked}); - }} - /> - ); - return ( <> {logTick ? ( @@ -232,10 +205,7 @@ export const TicksTable = ({ {tabs} - - - - + @@ -277,6 +247,52 @@ export const TicksTable = ({ ); }; +const StatusFilter = ({ + status, + onChange, +}: { + status: TickStatusDisplay; + onChange: (value: TickStatusDisplay) => void; +}) => { + const items = [ + {key: TickStatusDisplay.ALL, label: 'All ticks'}, + {key: TickStatusDisplay.SUCCESS, label: 'Requested'}, + {key: TickStatusDisplay.FAILED, label: 'Failed'}, + ]; + const activeItem = items.find(({key}) => key === status); + return ( + + popoverProps={{position: 'bottom-right'}} + filterable={false} + activeItem={activeItem} + items={items} + itemRenderer={(item, props) => { + return ( + + ); + }} + itemListRenderer={({renderItem, filteredItems}) => { + const renderedItems = filteredItems.map(renderItem).filter(Boolean); + return {renderedItems}; + }} + onItemSelect={(item) => onChange(item.key)} + > + + + ); +}; + export const TickHistoryTimeline = ({ name, repoAddress,