Skip to content

Commit

Permalink
fix(plugin-chart-table): table clear x-filtering highlighting (#1222)
Browse files Browse the repository at this point in the history
* fix(plugin-chart-table): fix table clear x-filtering highlighting issue

* fix(plugin-chart-table): fix lint
  • Loading branch information
stephenLYZ authored and zhaoyongjie committed Nov 26, 2021
1 parent db71620 commit 4051fda
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import React, { CSSProperties, useCallback, useMemo, useState } from 'react';
import React, { CSSProperties, useCallback, useMemo } from 'react';
import { ColumnInstance, ColumnWithLooseAccessor, DefaultSortTypes } from 'react-table';
import { extent as d3Extent, max as d3Max } from 'd3-array';
import { FaSort, FaSortDown as FaSortDesc, FaSortUp as FaSortAsc } from 'react-icons/fa';
Expand Down Expand Up @@ -161,12 +161,10 @@ export default function TableChart<D extends DataRecord = DataRecord>(
showCellBars = true,
emitFilter = false,
sortDesc = false,
filters: initialFilters = {},
filters,
sticky = true, // whether to use sticky header
} = props;

const [filters, setFilters] = useState(initialFilters);

const handleChange = useCallback(
(filters: { [x: string]: DataRecordValue[] }) => {
if (!emitFilter) {
Expand Down Expand Up @@ -196,6 +194,7 @@ export default function TableChart<D extends DataRecord = DataRecord>(
},
filterState: {
value: groupByValues.length ? groupByValues : null,
filters: filters && Object.keys(filters).length ? filters : null,
},
});
},
Expand Down Expand Up @@ -241,7 +240,6 @@ export default function TableChart<D extends DataRecord = DataRecord>(
if (Array.isArray(updatedFilters[key]) && updatedFilters[key].length === 0) {
delete updatedFilters[key];
}
setFilters(updatedFilters);
handleChange(updatedFilters);
},
[filters, handleChange, isActiveFilterValue],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ const transformProps = (chartProps: TableChartProps): TableChartTransformedProps
width,
rawFormData: formData,
queriesData = [],
initialValues: filters = {},
filterState,
ownState: serverPaginationData = {},
hooks: { onAddFilter: onChangeFilter, setDataMask = () => {} },
} = chartProps;
Expand Down Expand Up @@ -242,7 +242,7 @@ const transformProps = (chartProps: TableChartProps): TableChartTransformedProps
pageSize: serverPagination
? serverPageLength
: getPageSize(pageLength, data.length, columns.length),
filters,
filters: filterState.filters,
emitFilter: tableFilter,
onChangeFilter,
};
Expand Down

0 comments on commit 4051fda

Please sign in to comment.