mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-06 00:07:44 +01:00
29 lines
806 B
TypeScript
29 lines
806 B
TypeScript
|
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,
|
||
|
]);
|
||
|
};
|