Skip to content

Commit

Permalink
fix: Column filtering logic based on filteredData (#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
praveen5959 authored Dec 18, 2024
1 parent 78ab65c commit 910fd4f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/pages/Stream/components/Column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ const Column: FC<Column> = (props) => {
const [uniqueValues, setUniqueValues] = useState<string[]>([]);
const [filteredValues, setFilteredValues] = useState<string[]>([]);
const [selectedValues, setSelectedValues] = useState<string[]>([]);
const [rawData, setLogsStore] = useLogsStore((store) => store.data.rawData);
const [{ rawData, filteredData }, setLogsStore] = useLogsStore((store) => store.data);
const [wrapDisabledColumns] = useLogsStore((store) => store.tableOpts.wrapDisabledColumns);
const inputValueRef = useRef('');

useEffect(() => {
const uniqueValues = getUniqueValues(rawData, columnName);
const uniqueValues = getUniqueValues(filteredData || rawData, columnName);
setUniqueValues(uniqueValues);
}, [rawData]);
}, [rawData, filteredData]);

const onSearch = useCallback(
(e: ChangeEvent<HTMLInputElement>) => {
Expand Down
10 changes: 2 additions & 8 deletions src/pages/Stream/providers/LogsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -466,16 +466,10 @@ const filterAndSortData = (
data: Log[],
) => {
const { sortOrder, sortKey, filters } = opts;
const filterSets = _.mapValues(filters, (values) => new Set(values));
const filteredData = _.isEmpty(filters)
? data
: (_.reduce(
data,
(acc: Log[], d: Log) => {
const doesMatch = _.some(filters, (value, key) => _.includes(value, _.toString(d[key])));
return doesMatch ? [...acc, d] : acc;
},
[],
) as Log[]);
: _.filter(data, (item) => _.every(filterSets, (valueSet, key) => valueSet.has(_.toString(item[key]))));
const sortedData = _.orderBy(filteredData, [sortKey], [sortOrder]);
return sortedData;
};
Expand Down

0 comments on commit 910fd4f

Please sign in to comment.