1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-04-15 01:16:22 +02:00

feat: advanced playground UI tweaks (#4136)

This commit is contained in:
Mateusz Kwasniewski 2023-07-04 11:37:50 +02:00 committed by GitHub
parent 13def9a3a3
commit 1bee81b475
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 34 deletions

View File

@ -234,8 +234,6 @@ export const AdvancedPlayground: VFC<{
sx={{ sx={{
px: 4, px: 4,
py: 3, py: 3,
mb: 4,
mt: 2,
background: theme.palette.background.elevation2, background: theme.palette.background.elevation2,
transition: 'width 0.4s ease', transition: 'width 0.4s ease',
minWidth: matches ? 'auto' : '500px', minWidth: matches ? 'auto' : '500px',
@ -260,7 +258,7 @@ export const AdvancedPlayground: VFC<{
sx={theme => ({ sx={theme => ({
width: resultsWidth, width: resultsWidth,
transition: 'width 0.4s ease', transition: 'width 0.4s ease',
padding: theme.spacing(4, 2), padding: theme.spacing(4, 4),
})} })}
> >
<ConditionallyRender <ConditionallyRender

View File

@ -26,7 +26,6 @@ import useUnleashContext from 'hooks/api/getters/useUnleashContext/useUnleashCon
import { formatUnknownError } from 'utils/formatUnknownError'; import { formatUnknownError } from 'utils/formatUnknownError';
import useToast from 'hooks/useToast'; import useToast from 'hooks/useToast';
import { PlaygroundEditor } from './PlaygroundEditor/PlaygroundEditor'; import { PlaygroundEditor } from './PlaygroundEditor/PlaygroundEditor';
import { GuidanceIndicator } from 'component/common/GuidanceIndicator/GuidanceIndicator';
import { parseDateValue, parseValidDate } from 'component/common/util'; import { parseDateValue, parseValidDate } from 'component/common/util';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { isStringOrStringArray } from '../../playground.utils'; import { isStringOrStringArray } from '../../playground.utils';
@ -188,6 +187,7 @@ export const PlaygroundCodeFieldset: VFC<IPlaygroundCodeFieldsetProps> = ({
return ( return (
<Autocomplete <Autocomplete
disablePortal disablePortal
limitTags={3}
id="context-legal-values" id="context-legal-values"
freeSolo freeSolo
filterSelectedOptions filterSelectedOptions
@ -196,10 +196,11 @@ export const PlaygroundCodeFieldset: VFC<IPlaygroundCodeFieldsetProps> = ({
onChange={changeContextValue} onChange={changeContextValue}
options={options} options={options}
multiple={isAdvancedPlayground} multiple={isAdvancedPlayground}
sx={{ width: 200, maxWidth: '100%' }} sx={{ width: 370, maxWidth: '100%' }}
renderInput={(params: any) => ( renderInput={(params: any) => (
<TextField {...params} label="Value" /> <TextField {...params} label="Value" />
)} )}
disableCloseOnSelect={isAdvancedPlayground!}
/> />
); );
} }
@ -208,7 +209,10 @@ export const PlaygroundCodeFieldset: VFC<IPlaygroundCodeFieldsetProps> = ({
<TextField <TextField
label="Value" label="Value"
id="context-value" id="context-value"
sx={{ width: 200, maxWidth: '100%' }} sx={{ width: 370, maxWidth: '100%' }}
placeholder={
isAdvancedPlayground ? 'value1,value2,value3' : 'value1'
}
size="small" size="small"
value={contextValue} value={contextValue}
onChange={event => setContextValue(event.target.value || '')} onChange={event => setContextValue(event.target.value || '')}
@ -229,10 +233,9 @@ export const PlaygroundCodeFieldset: VFC<IPlaygroundCodeFieldsetProps> = ({
return ( return (
<Box> <Box>
<Box sx={{ display: 'flex', alignItems: 'center', mb: 2 }}> <Box sx={{ display: 'flex', alignItems: 'center', mb: 2 }}>
<GuidanceIndicator type="secondary">2</GuidanceIndicator>
<Typography <Typography
variant="body2" variant="body2"
color={theme.palette.text.secondary} color={theme.palette.text.primary}
sx={{ ml: 1 }} sx={{ ml: 1 }}
> >
Unleash context Unleash context

View File

@ -114,7 +114,7 @@ export const PlaygroundEditor: VFC<IPlaygroundEditorProps> = ({
</StyledEditorHeader> </StyledEditorHeader>
<CodeMirror <CodeMirror
value={context} value={context}
height="200px" height="150px"
theme={themeMode === 'dark' ? duotoneDark : duotoneLight} theme={themeMode === 'dark' ? duotoneDark : duotoneLight}
extensions={[json()]} extensions={[json()]}
onChange={onCodeFieldChange} onChange={onCodeFieldChange}

View File

@ -1,4 +1,4 @@
import { ComponentProps, VFC } from 'react'; import React, { ComponentProps, VFC } from 'react';
import { import {
Autocomplete, Autocomplete,
Box, Box,
@ -7,8 +7,8 @@ import {
useTheme, useTheme,
} from '@mui/material'; } from '@mui/material';
import useProjects from 'hooks/api/getters/useProjects/useProjects'; import useProjects from 'hooks/api/getters/useProjects/useProjects';
import { GuidanceIndicator } from 'component/common/GuidanceIndicator/GuidanceIndicator';
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig';
import { renderOption } from '../renderOption';
interface IPlaygroundConnectionFieldsetProps { interface IPlaygroundConnectionFieldsetProps {
environments: string[]; environments: string[];
@ -109,10 +109,9 @@ export const PlaygroundConnectionFieldset: VFC<
return ( return (
<Box sx={{ pb: 2 }}> <Box sx={{ pb: 2 }}>
<Box sx={{ display: 'flex', alignItems: 'center', mb: 2 }}> <Box sx={{ display: 'flex', alignItems: 'center', mb: 2 }}>
<GuidanceIndicator type="secondary">1</GuidanceIndicator>
<Typography <Typography
variant="body2" variant="body2"
color={theme.palette.text.secondary} color={theme.palette.text.primary}
sx={{ ml: 1 }} sx={{ ml: 1 }}
> >
Access configuration Access configuration
@ -121,13 +120,17 @@ export const PlaygroundConnectionFieldset: VFC<
<Box sx={{ display: 'flex', gap: 2, flexWrap: 'wrap' }}> <Box sx={{ display: 'flex', gap: 2, flexWrap: 'wrap' }}>
<Autocomplete <Autocomplete
disablePortal disablePortal
limitTags={3}
id="environment" id="environment"
multiple={isAdvancedPlayground} multiple={isAdvancedPlayground}
options={environmentOptions} options={environmentOptions}
sx={{ width: 200, maxWidth: '100%' }} sx={{ flex: 1 }}
renderInput={params => ( renderInput={params => (
<TextField {...params} label="Environments" /> <TextField {...params} label="Environments" />
)} )}
renderOption={renderOption}
getOptionLabel={({ label }) => label}
disableCloseOnSelect={isAdvancedPlayground!}
size="small" size="small"
value={envValue} value={envValue}
onChange={onEnvironmentsChange} onChange={onEnvironmentsChange}
@ -136,12 +139,16 @@ export const PlaygroundConnectionFieldset: VFC<
<Autocomplete <Autocomplete
disablePortal disablePortal
id="projects" id="projects"
limitTags={3}
multiple={!isAllProjects} multiple={!isAllProjects}
options={projectsOptions} options={projectsOptions}
sx={{ width: 200, maxWidth: '100%' }} sx={{ flex: 1 }}
renderInput={params => ( renderInput={params => (
<TextField {...params} label="Projects" /> <TextField {...params} label="Projects" />
)} )}
renderOption={renderOption}
getOptionLabel={({ label }) => label}
disableCloseOnSelect
size="small" size="small"
value={ value={
isAllProjects isAllProjects

View File

@ -1,5 +1,4 @@
import { Box, Button, Divider, useTheme } from '@mui/material'; import { Box, Button, Divider, useTheme } from '@mui/material';
import { GuidanceIndicator } from 'component/common/GuidanceIndicator/GuidanceIndicator';
import { IEnvironment } from 'interfaces/environments'; import { IEnvironment } from 'interfaces/environments';
import { FormEvent, VFC } from 'react'; import { FormEvent, VFC } from 'react';
import { PlaygroundCodeFieldset } from './PlaygroundCodeFieldset/PlaygroundCodeFieldset'; import { PlaygroundCodeFieldset } from './PlaygroundCodeFieldset/PlaygroundCodeFieldset';
@ -48,33 +47,17 @@ export const PlaygroundForm: VFC<IPlaygroundFormProps> = ({
({ name }) => name ({ name }) => name
)} )}
/> />
<Divider
variant="fullWidth"
sx={{
mb: 2,
borderColor: theme.palette.divider,
borderStyle: 'dashed',
}}
/>
<PlaygroundCodeFieldset context={context} setContext={setContext} /> <PlaygroundCodeFieldset context={context} setContext={setContext} />
<Divider
variant="fullWidth"
sx={{
mt: 3,
mb: 2,
borderColor: theme.palette.divider,
}}
/>
<Box <Box
sx={{ sx={{
mt: 2,
display: 'flex', display: 'flex',
alignItems: 'center', alignItems: 'center',
justifyContent: 'space-between', justifyContent: 'space-between',
}} }}
> >
<GuidanceIndicator type="secondary">3</GuidanceIndicator>
<Button <Button
variant="contained" variant="contained"
size="large" size="large"

View File

@ -0,0 +1,23 @@
import CheckBoxOutlineBlankIcon from '@mui/icons-material/CheckBoxOutlineBlank';
import CheckBoxIcon from '@mui/icons-material/CheckBox';
import React from 'react';
import { Checkbox, styled } from '@mui/material';
const SelectOptionCheckbox = styled(Checkbox)(({ theme }) => ({
marginRight: theme.spacing(0.4),
}));
export const renderOption = (
props: object,
option: { label: string },
{ selected }: { selected: boolean }
) => (
<li {...props}>
<SelectOptionCheckbox
icon={<CheckBoxOutlineBlankIcon fontSize="small" />}
checkedIcon={<CheckBoxIcon fontSize="small" />}
checked={selected}
/>
{option.label}
</li>
);