From 1d83643e15c2f3814b11d57521362d9dbb9e0a9b Mon Sep 17 00:00:00 2001 From: andreas-unleash <104830839+andreas-unleash@users.noreply.github.com> Date: Wed, 27 Jul 2022 18:48:17 +0300 Subject: [PATCH] Playground result info modal initial --- .../common/Table/cells/IconCell/IconCell.tsx | 12 +- .../PlaygroundFeatureResultInfoModal.tsx | 24 +++ .../PlaygroundResultsTable.tsx | 150 +++++++++++------- 3 files changed, 125 insertions(+), 61 deletions(-) create mode 100644 frontend/src/component/playground/Playground/PlaygroundFeatureResultInfoModal/PlaygroundFeatureResultInfoModal.tsx diff --git a/frontend/src/component/common/Table/cells/IconCell/IconCell.tsx b/frontend/src/component/common/Table/cells/IconCell/IconCell.tsx index 5c44952b07..16527d50e0 100644 --- a/frontend/src/component/common/Table/cells/IconCell/IconCell.tsx +++ b/frontend/src/component/common/Table/cells/IconCell/IconCell.tsx @@ -1,13 +1,21 @@ import { Box } from '@mui/material'; -import { ReactNode } from 'react'; +import React, { ReactNode } from 'react'; interface IIconCellProps { 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 ( void; +} + +export const PlaygroundFeatureResultInfoModal = ({ + feature, + open, + setOpen, +}: PlaygroundFeatureResultInfoModalProps) => { + if (!feature) { + return null; + } + + return ( + setOpen(false)}> +

Test

+
+ ); +}; diff --git a/frontend/src/component/playground/Playground/PlaygroundResultsTable/PlaygroundResultsTable.tsx b/frontend/src/component/playground/Playground/PlaygroundResultsTable/PlaygroundResultsTable.tsx index 2e695ce979..f7dafea0a3 100644 --- a/frontend/src/component/playground/Playground/PlaygroundResultsTable/PlaygroundResultsTable.tsx +++ b/frontend/src/component/playground/Playground/PlaygroundResultsTable/PlaygroundResultsTable.tsx @@ -23,6 +23,9 @@ import { PlaygroundFeatureSchema } from 'hooks/api/actions/usePlayground/playgro import { Box, Typography, useMediaQuery, useTheme } from '@mui/material'; import useLoading from 'hooks/useLoading'; 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 = { id: 'name' }; const { value, setValue } = createLocalStorage( @@ -48,11 +51,87 @@ export const PlaygroundResultsTable = ({ const isExtraSmallScreen = useMediaQuery(theme.breakpoints.down('sm')); 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) => ( + + ), + }, + { + Header: 'Project ID', + accessor: 'projectId', + sortType: 'alphanumeric', + filterName: 'projectId', + searchable: true, + maxWidth: 170, + Cell: ({ value }: any) => ( + + ), + }, + { + Header: 'Variant', + id: 'variant', + accessor: 'variant.name', + sortType: 'alphanumeric', + filterName: 'variant', + searchable: true, + width: 200, + Cell: ({ + value, + row: { + original: { variant, feature, variants, isEnabled }, + }, + }: any) => ( + + ), + }, + { + Header: 'isEnabled', + accessor: 'isEnabled', + filterName: 'isEnabled', + filterParsing: (value: boolean) => (value ? 'true' : 'false'), + Cell: ({ value }: any) => , + sortType: 'boolean', + sortInverted: true, + }, + { + Header: '', + id: 'info', + Cell: ({ row }: any) => ( + } + onClick={() => onFeatureResultInfoClick(row.original)} + /> + ), + }, + ], + //eslint-disable-next-line + [] + ); + const { data: searchedData, getSearchText, getSearchContext, - } = useSearch(COLUMNS, searchValue, features || []); + } = useSearch(columns, searchValue, features || []); const data = useMemo(() => { return loading @@ -87,7 +166,7 @@ export const PlaygroundResultsTable = ({ } = useTable( { initialState, - columns: COLUMNS as any, + columns: columns as any, data: data as any, sortTypes, 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 }, [loading, sortBy, searchValue]); + const onFeatureResultInfoClick = (feature: PlaygroundFeatureSchema) => { + setSelectedFeature(feature); + setShowResultInfoModal(true); + }; + return ( <> + ); }; - -const COLUMNS = [ - { - Header: 'Name', - accessor: 'name', - searchable: true, - minWidth: 160, - Cell: ({ value, row: { original } }: any) => ( - - ), - }, - { - Header: 'Project ID', - accessor: 'projectId', - sortType: 'alphanumeric', - filterName: 'projectId', - searchable: true, - maxWidth: 170, - Cell: ({ value }: any) => ( - - ), - }, - { - Header: 'Variant', - id: 'variant', - accessor: 'variant.name', - sortType: 'alphanumeric', - filterName: 'variant', - searchable: true, - width: 200, - Cell: ({ - value, - row: { - original: { variant, feature, variants, isEnabled }, - }, - }: any) => ( - - ), - }, - { - Header: 'isEnabled', - accessor: 'isEnabled', - filterName: 'isEnabled', - filterParsing: (value: boolean) => (value ? 'true' : 'false'), - Cell: ({ value }: any) => , - sortType: 'boolean', - sortInverted: true, - }, -];