1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00
unleash.unleash/frontend/src/hooks/useConditionallyHiddenColumns.ts

29 lines
806 B
TypeScript
Raw Normal View History

import { useEffect } from 'react';
interface IConditionallyHiddenColumns {
condition: boolean;
columns: string[];
}
export const useConditionallyHiddenColumns = (
conditionallyHiddenColumns: IConditionallyHiddenColumns[],
setHiddenColumns: (param: string[]) => void,
columnsDefinition: unknown[]
) => {
useEffect(() => {
const hiddenColumnsSet = new Set<string>();
conditionallyHiddenColumns
.filter(({ condition }) => condition)
.forEach(({ columns }) =>
columns.forEach(column => hiddenColumnsSet.add(column))
);
setHiddenColumns([...hiddenColumnsSet]);
}, [
...conditionallyHiddenColumns.map(({ condition }) => condition),
setHiddenColumns,
columnsDefinition,
]);
};