mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-28 00:17:12 +01:00
96 lines
3.2 KiB
TypeScript
96 lines
3.2 KiB
TypeScript
|
import { ConditionallyRender } from '../../../../common/ConditionallyRender/ConditionallyRender';
|
||
|
import { Box, IconButton, Popover, styled, useTheme } from '@mui/material';
|
||
|
import { flexRow } from '../../../../../themes/themeStyles';
|
||
|
import { PlaygroundResultChip } from '../../PlaygroundResultsTable/PlaygroundResultChip/PlaygroundResultChip';
|
||
|
import { InfoOutlined } from '@mui/icons-material';
|
||
|
import React, { useState } from 'react';
|
||
|
import { AdvancedPlaygroundEnvironmentFeatureSchema } from 'openapi';
|
||
|
import { PlaygroundEnvironmentTable } from '../../PlaygroundEnvironmentTable/PlaygroundEnvironmentTable';
|
||
|
|
||
|
const StyledContainer = styled(
|
||
|
'div',
|
||
|
{}
|
||
|
)(({ theme }) => ({
|
||
|
flexGrow: 0,
|
||
|
...flexRow,
|
||
|
justifyContent: 'flex-start',
|
||
|
margin: theme.spacing(0, 1.5),
|
||
|
}));
|
||
|
|
||
|
const StyledPlaygroundChipContainer = styled(Box)(({ theme }) => ({
|
||
|
display: 'flex',
|
||
|
flexDirection: 'row',
|
||
|
gap: theme.spacing(1),
|
||
|
}));
|
||
|
|
||
|
export interface IAdvancedPlaygroundEnvironmentCellProps {
|
||
|
value: AdvancedPlaygroundEnvironmentFeatureSchema[];
|
||
|
}
|
||
|
|
||
|
export const AdvancedPlaygroundEnvironmentCell = ({
|
||
|
value,
|
||
|
}: IAdvancedPlaygroundEnvironmentCellProps) => {
|
||
|
const theme = useTheme();
|
||
|
const [anchor, setAnchorEl] = useState<null | Element>(null);
|
||
|
|
||
|
const onOpen = (event: React.FormEvent<HTMLButtonElement>) =>
|
||
|
setAnchorEl(event.currentTarget);
|
||
|
|
||
|
const onClose = () => setAnchorEl(null);
|
||
|
|
||
|
const open = Boolean(anchor);
|
||
|
|
||
|
const enabled = (value || []).filter(evaluation => evaluation.isEnabled);
|
||
|
const disabled = (value || []).filter(evaluation => !evaluation.isEnabled);
|
||
|
|
||
|
return (
|
||
|
<StyledContainer>
|
||
|
<StyledPlaygroundChipContainer>
|
||
|
<ConditionallyRender
|
||
|
condition={enabled.length > 0}
|
||
|
show={
|
||
|
<PlaygroundResultChip
|
||
|
enabled={true}
|
||
|
label={`${enabled.length}`}
|
||
|
showIcon={true}
|
||
|
/>
|
||
|
}
|
||
|
/>
|
||
|
<ConditionallyRender
|
||
|
condition={disabled.length > 0}
|
||
|
show={
|
||
|
<PlaygroundResultChip
|
||
|
enabled={false}
|
||
|
label={`${disabled.length}`}
|
||
|
showIcon={true}
|
||
|
/>
|
||
|
}
|
||
|
/>
|
||
|
</StyledPlaygroundChipContainer>
|
||
|
<>
|
||
|
<IconButton onClick={onOpen}>
|
||
|
<InfoOutlined />
|
||
|
</IconButton>
|
||
|
|
||
|
<Popover
|
||
|
open={open}
|
||
|
id={`${value}-result-details`}
|
||
|
PaperProps={{
|
||
|
sx: {
|
||
|
borderRadius: `${theme.shape.borderRadiusLarge}px`,
|
||
|
},
|
||
|
}}
|
||
|
onClose={onClose}
|
||
|
anchorEl={anchor}
|
||
|
anchorOrigin={{
|
||
|
vertical: 'bottom',
|
||
|
horizontal: -320,
|
||
|
}}
|
||
|
>
|
||
|
<PlaygroundEnvironmentTable features={value} />
|
||
|
</Popover>
|
||
|
</>
|
||
|
</StyledContainer>
|
||
|
);
|
||
|
};
|