-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(facets): add persistence for selected items
- Loading branch information
Showing
13 changed files
with
356 additions
and
55 deletions.
There are no files selected for viewing
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
30 changes: 24 additions & 6 deletions
30
packages/pinorama-studio/src/components/pinorama-docs-table/hooks/use-docs.ts
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
40 changes: 40 additions & 0 deletions
40
packages/pinorama-studio/src/components/pinorama-facets/components/facet-factory-input.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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { Checkbox } from "@/components/ui/checkbox" | ||
import { facetFilterOperationsFactory } from "../lib/operations" | ||
import type { OramaPropType, SearchFilters } from "../types" | ||
|
||
export function FacetFactoryInput(props: { | ||
id: string | ||
type: OramaPropType | ||
name: string | ||
value: string | number | ||
filters: SearchFilters | ||
onFiltersChange: (filters: SearchFilters) => void | ||
}) { | ||
const operations: any = facetFilterOperationsFactory(props.type) | ||
|
||
const criteria = props.filters[props.name] || operations.create() | ||
const checked = operations.exists(props.value, criteria) | ||
|
||
const handleCheckedChange = (checked: boolean) => { | ||
const newCriteria = checked | ||
? operations.add(criteria, props.value) | ||
: operations.remove(criteria, props.value) | ||
|
||
const filters = { ...props.filters, [props.name]: newCriteria } | ||
|
||
if (operations.length(newCriteria) === 0) { | ||
delete filters[props.name] | ||
} | ||
|
||
props.onFiltersChange(filters) | ||
} | ||
|
||
return ( | ||
<Checkbox | ||
id={props.id} | ||
className="hover:bg-muted border-muted-foreground" | ||
checked={checked} | ||
onCheckedChange={handleCheckedChange} | ||
/> | ||
) | ||
} |
125 changes: 101 additions & 24 deletions
125
packages/pinorama-studio/src/components/pinorama-facets/components/facet.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
Oops, something went wrong.