Skip to content
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

[RFC] Context to allow cloud to sort filter values #17084

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ type LaunchpadHooksContextValue = {
error: GenericError | PythonErrorFragment;
fallback?: React.ReactNode;
}>;
// TODO (salazarm): Remove this prop after cloud PR lands to override UserDisplay instead
RunCreatedByCell?: any;
StaticFilterSorter?: Record<string, (a: any, b: any) => number>;
};

export const LaunchpadHooksContext = React.createContext<LaunchpadHooksContextValue>({
LaunchRootExecutionButton: undefined,
useLaunchWithTelemetry: undefined,
StaticFilterSorter: undefined,
});

export function useLaunchPadHooks() {
Expand All @@ -33,6 +33,7 @@ export function useLaunchPadHooks() {
MaterializeButton: OverrideMaterializeButton,
UserDisplay: OverrideUserDisplay,
PythonErrorInfoHeader,
StaticFilterSorter,
} = React.useContext(LaunchpadHooksContext);

return {
Expand All @@ -41,5 +42,6 @@ export function useLaunchPadHooks() {
MaterializeButton: OverrideMaterializeButton ?? Button,
PythonErrorInfoHeader,
UserDisplay: OverrideUserDisplay ?? UserDisplay,
StaticFilterSorter,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {Box, Checkbox, IconName, Popover} from '@dagster-io/ui-components';
import React from 'react';

import {useUpdatingRef} from '../../hooks/useUpdatingRef';
import {LaunchpadHooksContext} from '../../launchpad/LaunchpadHooksContext';

import {FilterObject, FilterTag, FilterTagHighlightedText} from './useFilter';

Expand Down Expand Up @@ -33,7 +34,7 @@ export function useStaticSetFilter<TValue>({
name,
icon,
getKey,
allValues,
allValues: _unsortedValues,
renderLabel,
renderActiveStateLabel,
initialState,
Expand All @@ -43,6 +44,16 @@ export function useStaticSetFilter<TValue>({
allowMultipleSelections = true,
matchType = 'any-of',
}: Args<TValue>): StaticSetFilter<TValue> {
const {StaticFilterSorter} = React.useContext(LaunchpadHooksContext);

const allValues = React.useMemo(() => {
const sorter = StaticFilterSorter?.[name];
if (sorter) {
return _unsortedValues.sort(sorter);
}
return _unsortedValues;
}, [StaticFilterSorter, name, _unsortedValues]);

const [state, setState] = React.useState(() => new Set(initialState || []));

React.useEffect(() => {
Expand Down