diff --git a/frontend/src/component/project/Project/ExperimentalProjectFeatures/ExperimentalProjectFeatures.tsx b/frontend/src/component/project/Project/ExperimentalProjectFeatures/ExperimentalProjectFeatures.tsx index 00f817c5b357..f07211159a92 100644 --- a/frontend/src/component/project/Project/ExperimentalProjectFeatures/ExperimentalProjectFeatures.tsx +++ b/frontend/src/component/project/Project/ExperimentalProjectFeatures/ExperimentalProjectFeatures.tsx @@ -45,7 +45,6 @@ const PaginatedProjectOverview = () => { diff --git a/frontend/src/component/project/Project/ExperimentalProjectFeatures/ExperimentalProjectTable/ExperimentalProjectTable.tsx b/frontend/src/component/project/Project/ExperimentalProjectFeatures/ExperimentalProjectTable/ExperimentalProjectTable.tsx index f103fb6c07cf..aaeb15bda78e 100644 --- a/frontend/src/component/project/Project/ExperimentalProjectFeatures/ExperimentalProjectTable/ExperimentalProjectTable.tsx +++ b/frontend/src/component/project/Project/ExperimentalProjectFeatures/ExperimentalProjectTable/ExperimentalProjectTable.tsx @@ -89,18 +89,84 @@ import { FeatureToggleCell } from './FeatureToggleCell/FeatureToggleCell'; interface IExperimentalProjectFeatureTogglesProps { environments: IProject['environments']; - style?: CSSProperties; refreshInterval?: number; storageKey?: string; } -const staticColumns = ['Select', 'Actions', 'name', 'favorite']; +const staticColumns = ['select', 'actions', 'name', 'favorite']; + +const useColumnVisibility = (allColumnIds: string[], state?: string[]) => { + const theme = useTheme(); + const isTinyScreen = useMediaQuery(theme.breakpoints.down('sm')); + const isSmallScreen = useMediaQuery(theme.breakpoints.down('md')); + const isMediumScreen = useMediaQuery(theme.breakpoints.down('lg')); + + const allColumns = useMemo( + () => + allColumnIds.reduce( + (acc, columnId) => ({ + ...acc, + [columnId]: staticColumns.includes(columnId), + }), + {}, + ), + [allColumnIds], + ); + + const showEnvironments = useCallback( + (environmentsToShow: number = 0) => { + const visibleEnvColumns = allColumnIds + .filter((id) => id.startsWith('environment:') !== false) + .slice(0, environmentsToShow); + return visibleEnvColumns.reduce( + (acc, columnId) => ({ + ...acc, + [columnId]: true, + }), + {}, + ); + }, + [allColumnIds], + ); + + if (isTinyScreen) { + return { + ...allColumns, + createdAt: true, + }; + } + if (isSmallScreen) { + return { + ...allColumns, + createdAt: true, + ...showEnvironments(1), + }; + } + if (isMediumScreen) { + return { + ...allColumns, + createdAt: true, + type: true, + ...showEnvironments(1), + }; + } + + return { + ...allColumns, + lastSeenAt: true, + createdAt: true, + type: true, + ...showEnvironments(2), + }; +}; + +const formatEnvironmentColumnId = (environment: string) => + `environment:${environment}`; const columnHelper = createColumnHelper(); export const ExperimentalProjectFeatureToggles = ({ environments, - style, refreshInterval = 15 * 1000, storageKey = 'project-feature-toggles', }: IExperimentalProjectFeatureTogglesProps) => { @@ -146,7 +212,7 @@ export const ExperimentalProjectFeatureToggles = ({ const columns = useMemo( () => [ columnHelper.display({ - id: 'Select', + id: 'select', header: ({ table }) => ( ( ( columns.map((column) => column.id).filter(Boolean) as string[], + [columns], + ); + + const defaultVisibleColumns = useColumnVisibility(allColumnIds); + + const columnVisibility = defaultVisibleColumns; + const table = useReactTable( withTableState(tableState, setTableState, { columns, data, enableRowSelection: true, + state: { + columnVisibility, + }, }), ); return ( <> + void; dataToExport?: Pick[]; environmentsToExport?: string[]; + actions?: ReactNode; } const StyledResponsiveButton = styled(ResponsiveButton)(() => ({ @@ -43,6 +44,7 @@ export const ProjectFeatureTogglesHeader: VFC< onChangeSearchQuery, dataToExport, environmentsToExport, + actions, }) => { const projectId = useRequiredPathParam('projectId'); const headerLoadingRef = useLoading(isLoading || false); @@ -91,16 +93,7 @@ export const ProjectFeatureTogglesHeader: VFC< /> } /> - {/* FIXME: columns menu */} - {/* setIsCustomColumns(true)} - /> */} + {actions}