From 884080a9dafe3ccc2dd88ec82c76167057c43451 Mon Sep 17 00:00:00 2001 From: Sammy Teillet Date: Wed, 26 Apr 2023 17:38:05 +0200 Subject: [PATCH] refactor: extract render into methods (#81) --- .../table-header/FilterDropdownButton.tsx | 140 +++++++++--------- 1 file changed, 74 insertions(+), 66 deletions(-) diff --git a/front/src/components/table/table-header/FilterDropdownButton.tsx b/front/src/components/table/table-header/FilterDropdownButton.tsx index bd9e5e46f5..ffb78f5c4d 100644 --- a/front/src/components/table/table-header/FilterDropdownButton.tsx +++ b/front/src/components/table/table-header/FilterDropdownButton.tsx @@ -53,6 +53,77 @@ export function FilterDropdownButton({ setSelectedFilterOperand(filterOperands[0]); }, []); + const renderSelectOptionItems = filterOperands.map((filterOperand, index) => ( + { + setSelectedFilterOperand(filterOperand); + setIsOptionUnfolded(false); + }} + > + {filterOperand.label} + + )); + + const renderSelectFilterITems = availableFilters.map((filter, index) => ( + { + setSelectedFilter(filter); + }} + > + + {filter.icon && } + + {filter.label} + + )); + + function renderFilterDropdown(selectedFilter: FilterType) { + return [ + setSelectedFilter(undefined)} + > + + {selectedFilter.icon && ( + + )} + + {selectedFilter.label} + + , + setIsOptionUnfolded(true)} + > + {selectedFilterOperand.label} + + + , + someFieldRandomValue.map((value, index) => ( + { + setFilters([ + { + id: value, + operand: selectedFilterOperand, + label: selectedFilter.label, + value: value, + icon: selectedFilter.icon, + }, + ]); + setIsUnfolded(false); + setSelectedFilter(undefined); + }} + > + {value} + + )), + ]; + } + return ( {selectedFilter ? isOptionUnfolded - ? filterOperands.map((filterOperand, index) => ( - { - setSelectedFilterOperand(filterOperand); - setIsOptionUnfolded(false); - }} - > - {filterOperand.label} - - )) - : [ - setSelectedFilter(undefined)} - > - - {selectedFilter.icon && ( - - )} - - {selectedFilter.label} - - , - setIsOptionUnfolded(true)} - > - {selectedFilterOperand.label} - - - , - someFieldRandomValue.map((value, index) => ( - { - setFilters([ - { - id: value, - operand: selectedFilterOperand, - label: selectedFilter.label, - value: value, - icon: selectedFilter.icon, - }, - ]); - setIsUnfolded(false); - setSelectedFilter(undefined); - }} - > - {value} - - )), - ] - : availableFilters.map((filter, index) => ( - { - setSelectedFilter(filter); - }} - > - - {filter.icon && } - - {filter.label} - - ))} + ? renderSelectOptionItems + : renderFilterDropdown(selectedFilter) + : renderSelectFilterITems} ); }