-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
112 additions
and
76 deletions.
There are no files selected for viewing
107 changes: 71 additions & 36 deletions
107
enterprise/frontend/src/metabase-enterprise/content_verification/ModelFilterControls.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,81 @@ | ||
import { useCallback } from "react"; | ||
import { t } from "ttag"; | ||
import _ from "underscore"; | ||
|
||
import type { ModelFilterControlsProps } from "metabase/browse/utils"; | ||
import { Switch, Text } from "metabase/ui"; | ||
import type { | ||
ActualModelFilters, | ||
ModelFilterControlsProps, | ||
} from "metabase/browse/utils"; | ||
import { useUserSetting } from "metabase/common/hooks"; | ||
import { Button, Icon, Popover, Switch, Text } from "metabase/ui"; | ||
|
||
export const ModelFilterControls = ({ | ||
actualModelFilters, | ||
handleModelFilterChange, | ||
setActualModelFilters, | ||
}: ModelFilterControlsProps) => { | ||
const [__, setVerifiedFilterStatus] = useUserSetting( | ||
"browse-filter-only-verified-models", | ||
{ shouldRefresh: false }, | ||
); | ||
const setVerifiedFilterStatusDebounced = _.debounce( | ||
setVerifiedFilterStatus, | ||
200, | ||
); | ||
|
||
const handleModelFilterChange = useCallback( | ||
(modelFilterName: string, active: boolean) => { | ||
// For now, only one filter is supported | ||
setVerifiedFilterStatusDebounced(active); | ||
setActualModelFilters((prev: ActualModelFilters) => { | ||
return { ...prev, [modelFilterName]: active }; | ||
}); | ||
}, | ||
[setActualModelFilters, setVerifiedFilterStatusDebounced], | ||
); | ||
|
||
const checked = actualModelFilters.onlyShowVerifiedModels; | ||
return ( | ||
<Switch | ||
label={ | ||
<Text | ||
align="end" | ||
weight="bold" | ||
lh="1rem" | ||
px=".75rem" | ||
>{t`Only show verified models`}</Text> | ||
} | ||
role="switch" | ||
checked={checked} | ||
aria-checked={checked} | ||
onChange={e => { | ||
handleModelFilterChange("onlyShowVerifiedModels", e.target.checked); | ||
}} | ||
size="sm" | ||
labelPosition="left" | ||
styles={{ | ||
root: { | ||
marginInlineStart: "auto", | ||
display: "flex", | ||
alignItems: "center", | ||
}, | ||
body: { | ||
alignItems: "center", | ||
// Align with tab labels: | ||
position: "relative", | ||
top: "-.5px", | ||
}, | ||
labelWrapper: { justifyContent: "center", padding: 0 }, | ||
track: { marginTop: "-1.5px" }, | ||
}} | ||
/> | ||
<Popover position="bottom-end"> | ||
<Popover.Target> | ||
<Button p="sm" variant="subtle" color="text-dark"> | ||
<Icon name="filter" /> | ||
</Button> | ||
</Popover.Target> | ||
<Popover.Dropdown p="lg"> | ||
<Switch | ||
label={ | ||
<Text | ||
align="end" | ||
weight="bold" | ||
lh="1rem" | ||
px=".75rem" | ||
>{t`Only show verified models`}</Text> | ||
} | ||
role="switch" | ||
checked={checked} | ||
aria-checked={checked} | ||
onChange={e => { | ||
handleModelFilterChange("onlyShowVerifiedModels", e.target.checked); | ||
}} | ||
size="sm" | ||
labelPosition="left" | ||
styles={{ | ||
root: { | ||
marginInlineStart: "auto", | ||
display: "flex", | ||
alignItems: "center", | ||
}, | ||
body: { | ||
alignItems: "center", | ||
// Align with tab labels: | ||
position: "relative", | ||
top: "-.5px", | ||
}, | ||
labelWrapper: { justifyContent: "center", padding: 0 }, | ||
track: { marginTop: "-1.5px" }, | ||
}} | ||
/> | ||
</Popover.Dropdown> | ||
</Popover> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters