mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-04 00:18:01 +01:00
Playground result info modal initial
This commit is contained in:
parent
5ea9de021e
commit
1d83643e15
@ -1,13 +1,21 @@
|
|||||||
import { Box } from '@mui/material';
|
import { Box } from '@mui/material';
|
||||||
import { ReactNode } from 'react';
|
import React, { ReactNode } from 'react';
|
||||||
|
|
||||||
interface IIconCellProps {
|
interface IIconCellProps {
|
||||||
icon: ReactNode;
|
icon: ReactNode;
|
||||||
|
onClick?: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const IconCell = ({ icon }: IIconCellProps) => {
|
export const IconCell = ({ icon, onClick }: IIconCellProps) => {
|
||||||
|
const handleClick =
|
||||||
|
onClick &&
|
||||||
|
((event: React.SyntheticEvent) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
onClick();
|
||||||
|
});
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box
|
||||||
|
onClick={handleClick}
|
||||||
sx={{
|
sx={{
|
||||||
pl: 2,
|
pl: 2,
|
||||||
pr: 1,
|
pr: 1,
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
import { PlaygroundFeatureSchema } from '../../../../hooks/api/actions/usePlayground/playground.model';
|
||||||
|
import { Modal } from '@mui/material';
|
||||||
|
|
||||||
|
interface PlaygroundFeatureResultInfoModalProps {
|
||||||
|
feature?: PlaygroundFeatureSchema;
|
||||||
|
open: boolean;
|
||||||
|
setOpen: (open: boolean) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const PlaygroundFeatureResultInfoModal = ({
|
||||||
|
feature,
|
||||||
|
open,
|
||||||
|
setOpen,
|
||||||
|
}: PlaygroundFeatureResultInfoModalProps) => {
|
||||||
|
if (!feature) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal open={open} onClose={() => setOpen(false)}>
|
||||||
|
<p>Test</p>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
};
|
@ -23,6 +23,9 @@ import { PlaygroundFeatureSchema } from 'hooks/api/actions/usePlayground/playgro
|
|||||||
import { Box, Typography, useMediaQuery, useTheme } from '@mui/material';
|
import { Box, Typography, useMediaQuery, useTheme } from '@mui/material';
|
||||||
import useLoading from 'hooks/useLoading';
|
import useLoading from 'hooks/useLoading';
|
||||||
import { VariantCell } from './VariantCell/VariantCell';
|
import { VariantCell } from './VariantCell/VariantCell';
|
||||||
|
import { IconCell } from '../../../common/Table/cells/IconCell/IconCell';
|
||||||
|
import { InfoOutlined } from '@mui/icons-material';
|
||||||
|
import { PlaygroundFeatureResultInfoModal } from '../PlaygroundFeatureResultInfoModal/PlaygroundFeatureResultInfoModal';
|
||||||
|
|
||||||
const defaultSort: SortingRule<string> = { id: 'name' };
|
const defaultSort: SortingRule<string> = { id: 'name' };
|
||||||
const { value, setValue } = createLocalStorage(
|
const { value, setValue } = createLocalStorage(
|
||||||
@ -48,11 +51,87 @@ export const PlaygroundResultsTable = ({
|
|||||||
const isExtraSmallScreen = useMediaQuery(theme.breakpoints.down('sm'));
|
const isExtraSmallScreen = useMediaQuery(theme.breakpoints.down('sm'));
|
||||||
const isSmallScreen = useMediaQuery(theme.breakpoints.down('md'));
|
const isSmallScreen = useMediaQuery(theme.breakpoints.down('md'));
|
||||||
|
|
||||||
|
const [selectedFeature, setSelectedFeature] = useState<
|
||||||
|
PlaygroundFeatureSchema | undefined
|
||||||
|
>();
|
||||||
|
const [showResultInfoModal, setShowResultInfoModal] = useState(false);
|
||||||
|
|
||||||
|
const columns = useMemo(
|
||||||
|
() => [
|
||||||
|
{
|
||||||
|
Header: 'Name',
|
||||||
|
accessor: 'name',
|
||||||
|
searchable: true,
|
||||||
|
minWidth: 160,
|
||||||
|
Cell: ({ value, row: { original } }: any) => (
|
||||||
|
<LinkCell
|
||||||
|
title={value}
|
||||||
|
to={`/projects/${original?.projectId}/features/${value}`}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Header: 'Project ID',
|
||||||
|
accessor: 'projectId',
|
||||||
|
sortType: 'alphanumeric',
|
||||||
|
filterName: 'projectId',
|
||||||
|
searchable: true,
|
||||||
|
maxWidth: 170,
|
||||||
|
Cell: ({ value }: any) => (
|
||||||
|
<LinkCell title={value} to={`/projects/${value}`} />
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Header: 'Variant',
|
||||||
|
id: 'variant',
|
||||||
|
accessor: 'variant.name',
|
||||||
|
sortType: 'alphanumeric',
|
||||||
|
filterName: 'variant',
|
||||||
|
searchable: true,
|
||||||
|
width: 200,
|
||||||
|
Cell: ({
|
||||||
|
value,
|
||||||
|
row: {
|
||||||
|
original: { variant, feature, variants, isEnabled },
|
||||||
|
},
|
||||||
|
}: any) => (
|
||||||
|
<VariantCell
|
||||||
|
variant={variant?.enabled ? value : ''}
|
||||||
|
variants={variants}
|
||||||
|
feature={feature}
|
||||||
|
isEnabled={isEnabled}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Header: 'isEnabled',
|
||||||
|
accessor: 'isEnabled',
|
||||||
|
filterName: 'isEnabled',
|
||||||
|
filterParsing: (value: boolean) => (value ? 'true' : 'false'),
|
||||||
|
Cell: ({ value }: any) => <FeatureStatusCell enabled={value} />,
|
||||||
|
sortType: 'boolean',
|
||||||
|
sortInverted: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Header: '',
|
||||||
|
id: 'info',
|
||||||
|
Cell: ({ row }: any) => (
|
||||||
|
<IconCell
|
||||||
|
icon={<InfoOutlined />}
|
||||||
|
onClick={() => onFeatureResultInfoClick(row.original)}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
//eslint-disable-next-line
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: searchedData,
|
data: searchedData,
|
||||||
getSearchText,
|
getSearchText,
|
||||||
getSearchContext,
|
getSearchContext,
|
||||||
} = useSearch(COLUMNS, searchValue, features || []);
|
} = useSearch(columns, searchValue, features || []);
|
||||||
|
|
||||||
const data = useMemo(() => {
|
const data = useMemo(() => {
|
||||||
return loading
|
return loading
|
||||||
@ -87,7 +166,7 @@ export const PlaygroundResultsTable = ({
|
|||||||
} = useTable(
|
} = useTable(
|
||||||
{
|
{
|
||||||
initialState,
|
initialState,
|
||||||
columns: COLUMNS as any,
|
columns: columns as any,
|
||||||
data: data as any,
|
data: data as any,
|
||||||
sortTypes,
|
sortTypes,
|
||||||
autoResetGlobalFilter: false,
|
autoResetGlobalFilter: false,
|
||||||
@ -138,8 +217,18 @@ export const PlaygroundResultsTable = ({
|
|||||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- don't re-render after search params change
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- don't re-render after search params change
|
||||||
}, [loading, sortBy, searchValue]);
|
}, [loading, sortBy, searchValue]);
|
||||||
|
|
||||||
|
const onFeatureResultInfoClick = (feature: PlaygroundFeatureSchema) => {
|
||||||
|
setSelectedFeature(feature);
|
||||||
|
setShowResultInfoModal(true);
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
<PlaygroundFeatureResultInfoModal
|
||||||
|
feature={selectedFeature}
|
||||||
|
open={showResultInfoModal}
|
||||||
|
setOpen={setShowResultInfoModal}
|
||||||
|
/>
|
||||||
<Box
|
<Box
|
||||||
sx={{
|
sx={{
|
||||||
display: 'flex',
|
display: 'flex',
|
||||||
@ -235,60 +324,3 @@ export const PlaygroundResultsTable = ({
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const COLUMNS = [
|
|
||||||
{
|
|
||||||
Header: 'Name',
|
|
||||||
accessor: 'name',
|
|
||||||
searchable: true,
|
|
||||||
minWidth: 160,
|
|
||||||
Cell: ({ value, row: { original } }: any) => (
|
|
||||||
<LinkCell
|
|
||||||
title={value}
|
|
||||||
to={`/projects/${original?.projectId}/features/${value}`}
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Header: 'Project ID',
|
|
||||||
accessor: 'projectId',
|
|
||||||
sortType: 'alphanumeric',
|
|
||||||
filterName: 'projectId',
|
|
||||||
searchable: true,
|
|
||||||
maxWidth: 170,
|
|
||||||
Cell: ({ value }: any) => (
|
|
||||||
<LinkCell title={value} to={`/projects/${value}`} />
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Header: 'Variant',
|
|
||||||
id: 'variant',
|
|
||||||
accessor: 'variant.name',
|
|
||||||
sortType: 'alphanumeric',
|
|
||||||
filterName: 'variant',
|
|
||||||
searchable: true,
|
|
||||||
width: 200,
|
|
||||||
Cell: ({
|
|
||||||
value,
|
|
||||||
row: {
|
|
||||||
original: { variant, feature, variants, isEnabled },
|
|
||||||
},
|
|
||||||
}: any) => (
|
|
||||||
<VariantCell
|
|
||||||
variant={variant?.enabled ? value : ''}
|
|
||||||
variants={variants}
|
|
||||||
feature={feature}
|
|
||||||
isEnabled={isEnabled}
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Header: 'isEnabled',
|
|
||||||
accessor: 'isEnabled',
|
|
||||||
filterName: 'isEnabled',
|
|
||||||
filterParsing: (value: boolean) => (value ? 'true' : 'false'),
|
|
||||||
Cell: ({ value }: any) => <FeatureStatusCell enabled={value} />,
|
|
||||||
sortType: 'boolean',
|
|
||||||
sortInverted: true,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
Loading…
Reference in New Issue
Block a user