From 9bad524908d6be270be18e68dee7815b03187abb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20F=C3=B6rg?= Date: Tue, 7 Nov 2023 10:41:13 +0100 Subject: [PATCH] fix: storybook external filters --- docs/stories/bExternalFilters.stories.tsx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/docs/stories/bExternalFilters.stories.tsx b/docs/stories/bExternalFilters.stories.tsx index 1203f81..43d60da 100644 --- a/docs/stories/bExternalFilters.stories.tsx +++ b/docs/stories/bExternalFilters.stories.tsx @@ -20,6 +20,24 @@ export const Primary = () => { const [jobTitle, setJobTitle] = useState(new Set()); const [birthday, setBirthday] = useState(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 ( @@ -32,7 +50,7 @@ export const Primary = () => {