Skip to content

Commit

Permalink
feat: allow reset filter
Browse files Browse the repository at this point in the history
  • Loading branch information
lawvs committed Aug 5, 2024
1 parent 3b7f8e1 commit 38a6eb0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"dependencies": {
"@emotion/react": "^11.13.0",
"@emotion/styled": "^11.13.0",
"@fn-sphere/filter": "^0.3.1",
"@fn-sphere/filter": "^0.3.2",
"@mui/material": "^5.16.6",
"@radix-ui/react-dialog": "^1.1.1",
"@radix-ui/react-dropdown-menu": "^2.1.1",
Expand Down
18 changes: 9 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions src/components/filter-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function FilterButton() {
const [open, setOpen] = useState(false);
const updateFilterPredicate = useUpdateFilterPredicate();
const countOfFilterData = useFilterCount();
const { context, getPredicate } = useFilterSphere({
const { getPredicate, reset, context } = useFilterSphere({
schema,
defaultRule: createFlattenFilterGroup(),
});
Expand Down Expand Up @@ -62,13 +62,22 @@ export function FilterButton() {
setOpen(false);
updateFilter();
}}
onReset={() => {
reset();
}}
/>
</Dialog>
</FilterSphereProvider>
);
}

function FilterDialog({ onConfirm }: { onConfirm: () => void }) {
function FilterDialog({
onConfirm,
onReset,
}: {
onConfirm: () => void;
onReset: () => void;
}) {
return (
<DialogContent>
<DialogHeader>
Expand All @@ -79,6 +88,14 @@ function FilterDialog({ onConfirm }: { onConfirm: () => void }) {
<FilterBuilder />
</div>
<DialogFooter>
<Button
variant="secondary"
onClick={() => {
onReset();
}}
>
Reset
</Button>
<Button
onClick={() => {
onConfirm();
Expand Down

0 comments on commit 38a6eb0

Please sign in to comment.