Skip to content

Commit

Permalink
fix: storybook external filters (#99)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Förg <[email protected]>
  • Loading branch information
fer0n and Michael Förg authored Nov 7, 2023
1 parent 95b45bb commit 64563d9
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion docs/stories/bExternalFilters.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ export const Primary = () => {
const [jobTitle, setJobTitle] = useState(new Set<string>());
const [birthday, setBirthday] = useState<Date | DateRange | null>(null);

const filteredData = data.filter((x) => {
if (firstName && !x.first_name.includes(firstName)) return false;
if (lastName && !x.last_name.includes(lastName)) return false;
if (jobTitle.size > 0 && !jobTitle.has(x.job_title)) return false;

const birthdayDate = new Date(x.birthday);
if (birthday instanceof Date) {
if (birthdayDate && birthdayDate !== birthday) return false;
} else if (
birthday?.min &&
birthday?.max &&
(birthdayDate < birthday.min || birthdayDate > birthday.max)
) {
return false;
}
return true;
});

return (
<Box>
<Box>
Expand All @@ -32,7 +50,7 @@ export const Primary = () => {
</Box>

<Table
items={data}
items={filteredData}
id="id"
virtual
stickyHeader
Expand Down

0 comments on commit 64563d9

Please sign in to comment.