MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / UserFilter

Function UserFilter

console/src/platform/query-history/UserFilter.tsx:38–104  ·  view source on GitHub ↗
({ submitForm, variant }: UserFilterProps)

Source from the content-addressed store, hash-verified

36};
37
38const UserFilter = ({ submitForm, variant }: UserFilterProps) => {
39 const { colors, shadows } = useTheme<MaterializeTheme>();
40 const { data: users, isError, isLoading } = useFetchQueryHistoryUsers();
41
42 const { formState } = useFormContext<QueryHistoryListSchema>();
43 const { field: userField } = useController<QueryHistoryListSchema, "user">({
44 name: "user",
45 });
46
47 const { ref, onMenuOpen } = useReactSelectForceFocus();
48
49 const handleOptionChange = (option: SelectOptionKind | null) => {
50 if (!option || !("id" in option)) return;
51 userField.onChange(option.id);
52 submitForm();
53 };
54
55 const defaultSelectedValue =
56 formState.defaultValues?.user ?? ALL_USERS_OPTION.id;
57
58 const defaultOptions =
59 defaultSelectedValue === ALL_USERS_OPTION.id
60 ? [ALL_USERS_OPTION]
61 : [
62 {
63 id: defaultSelectedValue,
64 name: defaultSelectedValue,
65 },
66 ALL_USERS_OPTION,
67 ];
68
69 const options =
70 users?.reduce((accum, user) => {
71 if (user.id !== defaultSelectedValue) {
72 accum.push(user);
73 }
74
75 return accum;
76 }, defaultOptions) ?? defaultOptions;
77
78 const currentValue =
79 options?.find((option) => option.id === userField.value) ??
80 defaultOptions[0];
81
82 const isDisabled = isError || isLoading;
83
84 return (
85 <SearchableSelect<SelectOptionKind, false>
86 ariaLabel="User filter"
87 isDisabled={isDisabled}
88 options={options}
89 leftIcon={<Text color={colors.foreground.secondary}>User</Text>}
90 value={currentValue}
91 onChange={(value) => handleOptionChange(value)}
92 onMenuOpen={onMenuOpen}
93 ref={ref as RefObject<any>}
94 styles={buildSearchableSelectFilterStyles(
95 {

Callers

nothing calls this directly

Calls 8

useReactSelectForceFocusFunction · 0.90
handleOptionChangeFunction · 0.70
reduceMethod · 0.45
pushMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected