Skip to content

Commit

Permalink
[ui] Disable runs feed “Show runs within backfills” when filtering by…
Browse files Browse the repository at this point in the history
… ”Launched By”
  • Loading branch information
bengotow committed Oct 16, 2024
1 parent a118eeb commit 0b218b5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const PipelineRunsFeedRoot = (props: {repoAddress?: RepoAddress}) => {
].filter(Boolean) as TokenizingFieldValue[];
}, [isJob, pipelineName, snapshotId]);

const includeRunsFromBackfills = useIncludeRunsFromBackfillsOption();
const includeRunsFromBackfills = useIncludeRunsFromBackfillsOption(filterTokens);

const runsFilter: RunsFilter = useMemo(() => {
const allTokens = [...filterTokens, ...permanentTokens];
Expand Down
16 changes: 13 additions & 3 deletions js_modules/dagster-ui/packages/ui-core/src/runs/RunsFeedRoot.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Box, Checkbox, Colors, tokenToString} from '@dagster-io/ui-components';
import partition from 'lodash/partition';
import {useCallback, useMemo} from 'react';
import {useCallback, useEffect, useMemo} from 'react';

import {RunsQueryRefetchContext} from './RunUtils';
import {RunsFeedError} from './RunsFeedError';
Expand All @@ -9,6 +9,7 @@ import {useRunsFeedTabs, useSelectedRunsFeedTab} from './RunsFeedTabs';
import {
RunFilterToken,
RunFilterTokenType,
isCreatedByTag,
runsFilterForSearchTokens,
useQueryPersistedRunFilters,
useRunsFilterInput,
Expand Down Expand Up @@ -36,18 +37,26 @@ const filters: RunFilterTokenType[] = [
'status',
];

export function useIncludeRunsFromBackfillsOption() {
export function useIncludeRunsFromBackfillsOption(filterTokens: RunFilterToken[]) {
const [value, setValue] = useQueryPersistedState<boolean>({
queryKey: 'show_runs_within_backfills',
defaults: {show_runs_within_backfills: false},
});

const someCreatedByTag = filterTokens.some(isCreatedByTag)
useEffect(() => {
if (someCreatedByTag && value) {
setValue(false);
}
}, [someCreatedByTag, value]);

return {
value,
setValue,
element: (
<Checkbox
label={<span>Show runs within backfills</span>}
disabled={someCreatedByTag}
checked={value}
onChange={() => {
setValue(!value);
Expand Down Expand Up @@ -104,7 +113,7 @@ export const RunsFeedRoot = () => {
enabledFilters: filters,
});

const includeRunsFromBackfills = useIncludeRunsFromBackfillsOption();
const includeRunsFromBackfills = useIncludeRunsFromBackfillsOption(mutableTokens);
const {tabs, queryResult: runQueryResult} = useRunsFeedTabs(
filter,
includeRunsFromBackfills.value,
Expand Down Expand Up @@ -187,3 +196,4 @@ export const RunsFeedRoot = () => {
// Imported via React.lazy, which requires a default export.
// eslint-disable-next-line import/no-default-export
export default RunsFeedRoot;
;;;;;;;;;;
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,17 @@ const StatusFilterValues = Object.keys(RunStatus).map((x) => ({
value: x,
match: [x],
}));

const CREATED_BY_TAGS = [
DagsterTag.Automaterialize,
DagsterTag.SensorName,
DagsterTag.ScheduleName,
DagsterTag.User,
];

export const isCreatedByTag = ({token, value}: RunFilterToken) =>
token === 'tag' && CREATED_BY_TAGS.includes(value.split('=')[0] as DagsterTag);

// Exclude these tags from the "tag" filter because they're already being fetched by other filters.
const tagsToExclude = [...CREATED_BY_TAGS, DagsterTag.Backfill, DagsterTag.Partition];

Expand Down Expand Up @@ -516,23 +520,11 @@ export const useRunsFilterInput = ({tokens, onChange, enabledFilters}: RunsFilte
return x.value!;
},
state: useMemo(() => {
return new Set(
tokens
.filter(
({token, value}) =>
token === 'tag' && CREATED_BY_TAGS.includes(value.split('=')[0] as DagsterTag),
)
.map(({value}) => tagValueToFilterObject(value)),
);
return new Set(tokens.filter(isCreatedByTag).map(({value}) => tagValueToFilterObject(value)));
}, [tokens]),
onStateChanged: (values) => {
onChange([
...tokens.filter((token) => {
if (token.token !== 'tag') {
return true;
}
return !CREATED_BY_TAGS.includes(token.value.split('=')[0] as DagsterTag);
}),
...tokens.filter((token) => !isCreatedByTag(token)),
...Array.from(values).map((value) => ({
token: 'tag' as const,
value: `${value.type}=${value.value}`,
Expand Down

0 comments on commit 0b218b5

Please sign in to comment.