From 293caec0c7770705722db90a503d3b70d0e87e08 Mon Sep 17 00:00:00 2001 From: Syed Ali Abbas Zaidi <88369802+Syed-Ali-Abbas-Zaidi@users.noreply.github.com> Date: Wed, 20 Dec 2023 04:06:32 +0500 Subject: [PATCH] [MM-56293] Convert `./components/admin_console/filter/filter_list.tsx` from Class Component to Function Component (#25765) --- .../admin_console/filter/filter_list.tsx | 77 ++++++++++--------- 1 file changed, 39 insertions(+), 38 deletions(-) diff --git a/webapp/channels/src/components/admin_console/filter/filter_list.tsx b/webapp/channels/src/components/admin_console/filter/filter_list.tsx index 37102d674d..1f5d1bc425 100644 --- a/webapp/channels/src/components/admin_console/filter/filter_list.tsx +++ b/webapp/channels/src/components/admin_console/filter/filter_list.tsx @@ -1,7 +1,7 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import React from 'react'; +import React, {memo, useCallback} from 'react'; import type {FilterOption, FilterValues} from './filter'; import FilterCheckbox from './filter_checkbox'; @@ -14,51 +14,52 @@ type Props = { updateValues: (values: FilterValues, optionKey: string) => void; } -class FilterList extends React.PureComponent { - updateOption = async (value: boolean, key: string) => { +const FilterList = ({ + option, + optionKey, + updateValues, +}: Props) => { + const updateOption = useCallback(async (value: boolean, key: string) => { const values = { - ...this.props.option.values, + ...option.values, [key]: { - ...this.props.option.values[key], + ...option.values[key], value, }, }; - await this.props.updateValues(values, this.props.optionKey); - }; + await updateValues(values, optionKey); + }, [option.values, optionKey, updateValues]); - render() { - const {option} = this.props; - const valuesToRender = option.keys.map((optionKey: string, index: number) => { - const currentValue = option.values[optionKey]; - const {value, name} = currentValue; - const FilterItem = option.type || FilterCheckbox; - - return ( -
- -
- ); - }); + const valuesToRender = option.keys.map((optionKey: string, index: number) => { + const currentValue = option.values[optionKey]; + const {value, name} = currentValue; + const FilterItem = option.type || FilterCheckbox; return ( -
-
- {option.name} -
- - {valuesToRender} +
+
); - } -} + }); -export default FilterList; + return ( +
+
+ {option.name} +
+ + {valuesToRender} +
+ ); +}; + +export default memo(FilterList);