1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/frontend/src/component/feature/FeatureToggleList/FeatureToggleListTable.tsx

251 lines
8.5 KiB
TypeScript
Raw Normal View History

import { useEffect, useMemo, useState, VFC } from 'react';
import { Link, useMediaQuery, useTheme } from '@mui/material';
import { Link as RouterLink, useSearchParams } from 'react-router-dom';
import { SortingRule, useGlobalFilter, useSortBy, useTable } from 'react-table';
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
import {
Table,
SortableTableHeader,
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
TableBody,
TableCell,
TableRow,
TablePlaceholder,
TableSearch,
} from 'component/common/Table';
import { useFeatures } from 'hooks/api/getters/useFeatures/useFeatures';
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
import { SearchHighlightProvider } from 'component/common/Table/SearchHighlightContext/SearchHighlightContext';
import { DateCell } from 'component/common/Table/cells/DateCell/DateCell';
import { LinkCell } from 'component/common/Table/cells/LinkCell/LinkCell';
import { FeatureSeenCell } from 'component/common/Table/cells/FeatureSeenCell/FeatureSeenCell';
import { FeatureTypeCell } from 'component/common/Table/cells/FeatureTypeCell/FeatureTypeCell';
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { PageContent } from 'component/common/PageContent/PageContent';
import { PageHeader } from 'component/common/PageHeader/PageHeader';
import { sortTypes } from 'utils/sortTypes';
import { useLocalStorage } from 'hooks/useLocalStorage';
import { FeatureSchema } from 'openapi';
import { CreateFeatureButton } from '../CreateFeatureButton/CreateFeatureButton';
import { FeatureStaleCell } from './FeatureStaleCell/FeatureStaleCell';
import { FeatureNameCell } from 'component/common/Table/cells/FeatureNameCell/FeatureNameCell';
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
const featuresPlaceholder: FeatureSchema[] = Array(15).fill({
name: 'Name of the feature',
description: 'Short description of the feature',
type: '-',
createdAt: new Date(2022, 1, 1),
project: 'projectID',
});
type PageQueryType = Partial<Record<'sort' | 'order' | 'search', string>>;
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
const columns = [
{
Header: 'Seen',
accessor: 'lastSeenAt',
Cell: FeatureSeenCell,
sortType: 'date',
align: 'center',
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
},
{
Header: 'Type',
accessor: 'type',
Cell: FeatureTypeCell,
align: 'center',
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
},
{
Header: 'Feature toggle name',
accessor: 'name',
maxWidth: 300,
width: '67%',
Cell: FeatureNameCell,
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
sortType: 'alphanumeric',
},
{
Header: 'Created on',
accessor: 'createdAt',
Cell: DateCell,
sortType: 'date',
},
{
Header: 'Project ID',
accessor: 'project',
Cell: ({ value }: { value: string }) => (
<LinkCell title={value} to={`/projects/${value}`} />
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
),
sortType: 'alphanumeric',
},
{
Header: 'State',
accessor: 'stale',
Cell: FeatureStaleCell,
sortType: 'boolean',
},
// Always hidden -- for search
{
accessor: 'description',
},
];
const defaultSort: SortingRule<string> = { id: 'createdAt', desc: false };
export const FeatureToggleListTable: VFC = () => {
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
const theme = useTheme();
const isSmallScreen = useMediaQuery(theme.breakpoints.down('md'));
const isMediumScreen = useMediaQuery(theme.breakpoints.down('lg'));
const [searchParams, setSearchParams] = useSearchParams();
const [storedParams, setStoredParams] = useLocalStorage(
'FeatureToggleListTable:v1',
defaultSort
);
const { features = [], loading } = useFeatures();
const data = useMemo(
() =>
features?.length === 0 && loading ? featuresPlaceholder : features,
[features, loading]
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
);
const [initialState] = useState(() => ({
sortBy: [
{
id: searchParams.get('sort') || storedParams.id,
desc: searchParams.has('order')
? searchParams.get('order') === 'desc'
: storedParams.desc,
},
],
hiddenColumns: ['description'],
globalFilter: searchParams.get('search') || '',
}));
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
const {
getTableProps,
getTableBodyProps,
headerGroups,
rows,
prepareRow,
state: { globalFilter, sortBy },
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
setGlobalFilter,
setHiddenColumns,
} = useTable(
{
// @ts-expect-error -- fix in react-table v8
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
columns,
// @ts-expect-error -- fix in react-table v8
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
data,
initialState,
sortTypes,
autoResetGlobalFilter: false,
autoResetSortBy: false,
disableSortRemove: true,
disableMultiSort: true,
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
},
useGlobalFilter,
useSortBy
);
useEffect(() => {
if (isSmallScreen) {
setHiddenColumns([
'lastSeenAt',
'type',
'stale',
'description',
'createdAt',
]);
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
} else if (isMediumScreen) {
setHiddenColumns(['lastSeenAt', 'stale', 'description']);
} else {
setHiddenColumns(['description']);
}
}, [setHiddenColumns, isSmallScreen, isMediumScreen]);
useEffect(() => {
const tableState: PageQueryType = {};
tableState.sort = sortBy[0].id;
if (sortBy[0].desc) {
tableState.order = 'desc';
}
if (globalFilter) {
tableState.search = globalFilter;
}
setSearchParams(tableState, {
replace: true,
});
setStoredParams({ id: sortBy[0].id, desc: sortBy[0].desc || false });
}, [sortBy, globalFilter, setSearchParams, setStoredParams]);
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
return (
<PageContent
isLoading={loading}
header={
<PageHeader
title={`Feature toggles (${data.length})`}
actions={
<>
<TableSearch
initialValue={globalFilter}
onChange={setGlobalFilter}
/>
<PageHeader.Divider />
<Link
component={RouterLink}
to="/archive"
underline="always"
sx={{ marginRight: 3 }}
>
View archive
</Link>
<CreateFeatureButton
loading={false}
filter={{ query: '', project: 'default' }}
/>
</>
}
/>
}
>
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
<SearchHighlightProvider value={globalFilter}>
<Table {...getTableProps()}>
{/* @ts-expect-error -- fix in react-table v8 */}
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
<SortableTableHeader headerGroups={headerGroups} />
<TableBody {...getTableBodyProps()}>
{rows.map(row => {
prepareRow(row);
return (
<TableRow hover {...row.getRowProps()}>
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
{row.cells.map(cell => (
<TableCell {...cell.getCellProps()}>
{cell.render('Cell')}
</TableCell>
))}
</TableRow>
);
})}
</TableBody>
</Table>
</SearchHighlightProvider>
<ConditionallyRender
condition={rows.length === 0}
show={
<ConditionallyRender
condition={globalFilter?.length > 0}
show={
<TablePlaceholder>
No features or projects found matching &ldquo;
{globalFilter}
&rdquo;
</TablePlaceholder>
}
elseShow={
<TablePlaceholder>
No features available. Get started by adding a
new feature toggle.
</TablePlaceholder>
}
/>
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
}
/>
</PageContent>
Feature list table (#908) * experiment with generic table * feat: example implementation of sortable table interfaces * add enhanced table header Co-authored-by: Nuno Góis <github@nunogois.com> * table cleanup Co-authored-by: Nuno Góis Co-authored-by: Fredrik Strand Oseberg * useSort hook interface surface Co-authored-by: Nuno Góis <github@nunogois.com> * sort handler initial implementation Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com> * new table unified components * feature flags table components Co-authored-by: Nuno Góis <github@nunogois.com> * feat: new table sort hook * feat: table sort * useSearch hook implementation * update new sort hook tests * sortable headers hook * feat: add sort to other table features * move experimental table hooks to a directory * update new table header styles * fix: header, tableActions * add some details like pagination and highlighter so we keep them in mind * feature table cells * update new table sort logic * new pagination * fix formatting and remove unused component * fix: adapt useSearch default search to text instead of regex (PR #924) * fix: update table title based on visible rows * fix: remove test route * refactor: move table experiment files * features table experimentation * feat: enhanced feature flags table * fix: features default sort * feat: enhanced table loading * fix: table theme after mui5 update * features list placeholder * add react-table * update snapshots after theme change * remove unused files * fix: improve features table after review * refactor: rename feature type cell variables Co-authored-by: Fredrik Oseberg <fredrik.no@gmail.com> Co-authored-by: Nuno Góis <github@nunogois.com> Co-authored-by: Tymoteusz Czech <Tymek@users.noreply.github.com>
2022-05-05 15:34:46 +02:00
);
};