1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-07 01:16:28 +02:00
unleash.unleash/frontend/src/component/common/ApiTokenTable/ApiTokenTable.tsx
NicolaeUnleash 705462f0cf
feat: dark theme v1 (#3298)
## About the changes

Creating the first version of the Dark theme

Refactor: colors variables
Refactor: use theme variable instead 
- this change will help us to use MuiCssBaseline, and we can use classes
directly for easy customization when we can't identify MUI classes

Refactor: adjusting some files components
- i’ve touched also the structure of some files, not only the colors
variables (but only to adjust the style, not functionality)

Fix: dark mode persistence on refresh (by Nuno)

Feat: dark mode sees light logos, and light mode sees dark logos (by
Nuno)

---------

Co-authored-by: Nuno Góis <github@nunogois.com>
2023-03-22 16:37:40 +02:00

144 lines
4.6 KiB
TypeScript

import {
Row,
TablePropGetter,
TableProps,
TableBodyPropGetter,
TableBodyProps,
HeaderGroup,
} from 'react-table';
import {
SortableTableHeader,
TableCell,
TablePlaceholder,
} from 'component/common/Table';
import {
Box,
Table,
TableBody,
TableRow,
useMediaQuery,
Link,
} from '@mui/material';
import { SearchHighlightProvider } from 'component/common/Table/SearchHighlightContext/SearchHighlightContext';
import { ApiTokenDocs } from 'component/admin/apiToken/ApiTokenDocs/ApiTokenDocs';
import theme from 'themes/theme';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { useConditionallyHiddenColumns } from 'hooks/useConditionallyHiddenColumns';
const hiddenColumnsSmall = ['Icon', 'createdAt'];
const hiddenColumnsCompact = ['Icon', 'project', 'seenAt'];
interface IApiTokenTableProps {
compact?: boolean;
loading: boolean;
setHiddenColumns: (param: any) => void;
columns: any[];
rows: Row<object>[];
prepareRow: (row: Row<object>) => void;
getTableProps: (
propGetter?: TablePropGetter<object> | undefined
) => TableProps;
getTableBodyProps: (
propGetter?: TableBodyPropGetter<object> | undefined
) => TableBodyProps;
headerGroups: HeaderGroup<object>[];
globalFilter: any;
}
export const ApiTokenTable = ({
compact = false,
setHiddenColumns,
columns,
loading,
rows,
getTableProps,
getTableBodyProps,
headerGroups,
globalFilter,
prepareRow,
}: IApiTokenTableProps) => {
const isSmallScreen = useMediaQuery(theme.breakpoints.down('md'));
useConditionallyHiddenColumns(
[
{
condition: isSmallScreen,
columns: hiddenColumnsSmall,
},
{
condition: compact,
columns: hiddenColumnsCompact,
},
],
setHiddenColumns,
columns
);
return (
<>
<ConditionallyRender
condition={rows.length > 0}
show={
<Box sx={{ mb: 4 }}>
<ApiTokenDocs />
</Box>
}
/>
<Box sx={{ overflowX: 'auto' }}>
<SearchHighlightProvider value={globalFilter}>
<Table {...getTableProps()}>
<SortableTableHeader
headerGroups={headerGroups as any}
/>
<TableBody {...getTableBodyProps()}>
{rows.map(row => {
prepareRow(row);
return (
<TableRow hover {...row.getRowProps()}>
{row.cells.map(cell => (
<TableCell {...cell.getCellProps()}>
{cell.render('Cell')}
</TableCell>
))}
</TableRow>
);
})}
</TableBody>
</Table>
</SearchHighlightProvider>
</Box>
<ConditionallyRender
condition={rows.length === 0 && !loading}
show={
<ConditionallyRender
condition={globalFilter?.length > 0}
show={
<TablePlaceholder>
No tokens found matching &ldquo;
{globalFilter}
&rdquo;
</TablePlaceholder>
}
elseShow={
<TablePlaceholder>
<span>
{'No tokens available. Read '}
<Link
href="https://docs.getunleash.io/how-to/api"
target="_blank"
rel="noreferrer"
>
API How-to guides
</Link>{' '}
{' to learn more.'}
</span>
</TablePlaceholder>
}
/>
}
/>
</>
);
};