From c4a6be7698251f5b29960b4dfcec5ea95bf6b6cd Mon Sep 17 00:00:00 2001 From: balanza Date: Fri, 2 Aug 2024 15:24:04 +0200 Subject: [PATCH] add date options to composed filter --- .../common/ComposedFilter/ComposedFilter.jsx | 15 +++++++++---- .../ComposedFilter/ComposedFilter.stories.jsx | 21 +++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/assets/js/common/ComposedFilter/ComposedFilter.jsx b/assets/js/common/ComposedFilter/ComposedFilter.jsx index 7ea9692d70..f39fb0ec85 100644 --- a/assets/js/common/ComposedFilter/ComposedFilter.jsx +++ b/assets/js/common/ComposedFilter/ComposedFilter.jsx @@ -1,11 +1,18 @@ import React, { useState } from 'react'; import Button from '@common/Button'; import Filter from '@common/Filter'; +import DateFilter from '@common/DateFilter'; -const renderFilter = ({ type, ...filterProps }, value, onChange) => - type === 'select' ? ( - - ) : null; +const renderFilter = ({ type, ...filterProps }, value, onChange) => { + switch (type) { + case 'select': + return ; + case 'date': + return ; + default: + return null; + } +}; /** * Define a filter which is the composition of several filters. diff --git a/assets/js/common/ComposedFilter/ComposedFilter.stories.jsx b/assets/js/common/ComposedFilter/ComposedFilter.stories.jsx index 9523c538db..3d4c229dda 100644 --- a/assets/js/common/ComposedFilter/ComposedFilter.stories.jsx +++ b/assets/js/common/ComposedFilter/ComposedFilter.stories.jsx @@ -68,3 +68,24 @@ export const Default = { onChange: action('onChange'), }, }; + +export const WithDateFilter = { + args: { + filters: [ + { + key: 'filter1', + type: 'select', + title: 'Pasta', + options: ['Carbonara', 'Amatriciana', 'Ajo & Ojo', 'Gricia'], + }, + { + key: 'filter2', + type: 'date', + title: 'Date', + prefill: true, + options: [['My birthday', () => new Date(1986, 0, 24)]], + }, + ], + onChange: action('onChange'), + }, +};