feat: introduce FlowSubstepTitle in FlowStep
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
85c3442196
commit
5aae9a60f4
@@ -38,6 +38,7 @@ function ChooseAccountSubstep(props: ChooseAccountSubstepProps): React.ReactElem
|
|||||||
<Autocomplete
|
<Autocomplete
|
||||||
fullWidth
|
fullWidth
|
||||||
disablePortal
|
disablePortal
|
||||||
|
disableClearable
|
||||||
options={connectionOptions}
|
options={connectionOptions}
|
||||||
renderInput={(params) => <TextField {...params} label="Choose account" />}
|
renderInput={(params) => <TextField {...params} label="Choose account" />}
|
||||||
value={getOption(connectionOptions, connectionId)}
|
value={getOption(connectionOptions, connectionId)}
|
||||||
|
@@ -15,6 +15,7 @@ import ExpandLessIcon from '@mui/icons-material/ExpandLess';
|
|||||||
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
||||||
import IconButton from '@mui/material/IconButton';
|
import IconButton from '@mui/material/IconButton';
|
||||||
|
|
||||||
|
import FlowSubstepTitle from 'components/FlowSubstepTitle';
|
||||||
import ChooseAccountSubstep from 'components/ChooseAccountSubstep';
|
import ChooseAccountSubstep from 'components/ChooseAccountSubstep';
|
||||||
import Form from 'components/Form';
|
import Form from 'components/Form';
|
||||||
import InputCreator from 'components/InputCreator';
|
import InputCreator from 'components/InputCreator';
|
||||||
@@ -56,6 +57,28 @@ const parseStep = (step: any) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const validateSubstep = (substep: any, step: Step, substepIndex: number, substepCount: number) => {
|
||||||
|
if (!substep) return true;
|
||||||
|
|
||||||
|
if (substepCount < substepIndex + 1) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (substep.name === 'Choose account') {
|
||||||
|
return Boolean(step.connection?.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const args: AppFields[] = substep.arguments || [];
|
||||||
|
|
||||||
|
return args.every(arg => {
|
||||||
|
if (arg.required === false) { return true; }
|
||||||
|
|
||||||
|
const argValue = step.parameters[arg.key];
|
||||||
|
|
||||||
|
return argValue !== null && argValue !== undefined;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
export default function FlowStep(props: FlowStepProps): React.ReactElement | null {
|
export default function FlowStep(props: FlowStepProps): React.ReactElement | null {
|
||||||
const { collapsed, index, onChange } = props;
|
const { collapsed, index, onChange } = props;
|
||||||
const contextButtonRef = React.useRef<HTMLButtonElement | null>(null);
|
const contextButtonRef = React.useRef<HTMLButtonElement | null>(null);
|
||||||
@@ -82,7 +105,8 @@ export default function FlowStep(props: FlowStepProps): React.ReactElement | nul
|
|||||||
const appOptions = React.useMemo(() => apps?.map((app) => optionGenerator(app)), [apps]);
|
const appOptions = React.useMemo(() => apps?.map((app) => optionGenerator(app)), [apps]);
|
||||||
const actionsOrTriggers = isTrigger ? app?.triggers : app?.actions;
|
const actionsOrTriggers = isTrigger ? app?.triggers : app?.actions;
|
||||||
const actionOptions = React.useMemo(() => actionsOrTriggers?.map((trigger) => optionGenerator(trigger)) ?? [], [app?.key]);
|
const actionOptions = React.useMemo(() => actionsOrTriggers?.map((trigger) => optionGenerator(trigger)) ?? [], [app?.key]);
|
||||||
const substeps = React.useMemo(() => actionsOrTriggers?.find(({ key }) => key === step.key)?.subSteps, [actionsOrTriggers, step?.key]);
|
const substeps = React.useMemo(() => actionsOrTriggers?.find(({ key }) => key === step.key)?.subSteps || [], [actionsOrTriggers, step?.key]);
|
||||||
|
const substepCount = substeps.length + 1;
|
||||||
|
|
||||||
const expandNextStep = React.useCallback(() => { setCurrentSubstep((currentSubstep) => (currentSubstep ?? 0) + 1); }, []);
|
const expandNextStep = React.useCallback(() => { setCurrentSubstep((currentSubstep) => (currentSubstep ?? 0) + 1); }, []);
|
||||||
|
|
||||||
@@ -180,12 +204,12 @@ export default function FlowStep(props: FlowStepProps): React.ReactElement | nul
|
|||||||
<Collapse in={!collapsed}>
|
<Collapse in={!collapsed}>
|
||||||
<Content>
|
<Content>
|
||||||
<List>
|
<List>
|
||||||
<ListItemButton onClick={() => toggleSubstep(0)} selected={currentSubstep === 0} divider>
|
<FlowSubstepTitle
|
||||||
<Typography variant="body2" sx={{ display: 'flex', alignItems: 'center' }}>
|
expanded={currentSubstep === 0}
|
||||||
{currentSubstep === 0 ? <ExpandLessIcon /> : <ExpandMoreIcon />}
|
onClick={() => toggleSubstep(0)}
|
||||||
Choose app & event
|
title="Choose app & event"
|
||||||
</Typography>
|
valid={substepCount === 1 ? null : !!step.appKey && !!step.key}
|
||||||
</ListItemButton>
|
/>
|
||||||
<Collapse in={currentSubstep === 0} timeout="auto" unmountOnExit>
|
<Collapse in={currentSubstep === 0} timeout="auto" unmountOnExit>
|
||||||
<ListItem sx={{ pt: 2, pb: 3, flexDirection: 'column', alignItems: 'flex-start' }}>
|
<ListItem sx={{ pt: 2, pb: 3, flexDirection: 'column', alignItems: 'flex-start' }}>
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
@@ -221,12 +245,14 @@ export default function FlowStep(props: FlowStepProps): React.ReactElement | nul
|
|||||||
<Form defaultValues={step.parameters}>
|
<Form defaultValues={step.parameters}>
|
||||||
{substeps?.length > 0 && substeps.map((substep: { name: string, arguments: AppFields[] }, index: number) => (
|
{substeps?.length > 0 && substeps.map((substep: { name: string, arguments: AppFields[] }, index: number) => (
|
||||||
<React.Fragment key={`${substep?.name}-${index}`}>
|
<React.Fragment key={`${substep?.name}-${index}`}>
|
||||||
<ListItemButton onClick={() => toggleSubstep(index + 1)} selected={currentSubstep === (index + 1)} divider>
|
{validateSubstep(substeps[index - 1], step, index, substepCount) && (
|
||||||
<Typography variant="body2" sx={{ display: 'flex', alignItems: 'center' }}>
|
<React.Fragment>
|
||||||
{currentSubstep === (index + 1) ? <ExpandLessIcon /> : <ExpandMoreIcon />}
|
<FlowSubstepTitle
|
||||||
{substep.name as string}
|
expanded={currentSubstep === (index + 1)}
|
||||||
</Typography>
|
onClick={() => toggleSubstep(index + 1)}
|
||||||
</ListItemButton>
|
title={substep.name}
|
||||||
|
valid={validateSubstep(substep, step, index + 1, substepCount)}
|
||||||
|
/>
|
||||||
<Collapse in={currentSubstep === (index + 1)} timeout="auto" unmountOnExit>
|
<Collapse in={currentSubstep === (index + 1)} timeout="auto" unmountOnExit>
|
||||||
<ListItem sx={{ pt: 2, pb: 3 }}>
|
<ListItem sx={{ pt: 2, pb: 3 }}>
|
||||||
{substep.name === 'Choose account' && (
|
{substep.name === 'Choose account' && (
|
||||||
@@ -247,6 +273,8 @@ export default function FlowStep(props: FlowStepProps): React.ReactElement | nul
|
|||||||
</ListItem>
|
</ListItem>
|
||||||
</Collapse>
|
</Collapse>
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
|
)}
|
||||||
|
</React.Fragment>
|
||||||
))}
|
))}
|
||||||
</Form>
|
</Form>
|
||||||
</List>
|
</List>
|
||||||
|
42
packages/web/src/components/FlowSubstepTitle/index.tsx
Normal file
42
packages/web/src/components/FlowSubstepTitle/index.tsx
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
import * as React from 'react';
|
||||||
|
import ExpandLessIcon from '@mui/icons-material/ExpandLess';
|
||||||
|
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
||||||
|
import ErrorIcon from '@mui/icons-material/Error';
|
||||||
|
import CheckCircleIcon from '@mui/icons-material/CheckCircle';
|
||||||
|
|
||||||
|
import { ListItemButton, Typography} from './style';
|
||||||
|
|
||||||
|
type FlowSubstepTitleProps = {
|
||||||
|
expanded?: boolean;
|
||||||
|
onClick: () => void;
|
||||||
|
title: string;
|
||||||
|
valid?: boolean | null;
|
||||||
|
};
|
||||||
|
|
||||||
|
function FlowSubstepTitle(props: FlowSubstepTitleProps): React.ReactElement {
|
||||||
|
const {
|
||||||
|
expanded = false,
|
||||||
|
onClick = () => null,
|
||||||
|
valid = null,
|
||||||
|
title,
|
||||||
|
} = props;
|
||||||
|
|
||||||
|
const hasValidation = valid !== null;
|
||||||
|
|
||||||
|
const validIcon = <CheckCircleIcon color="success" />;
|
||||||
|
const errorIcon = <ErrorIcon color="error" />;
|
||||||
|
const validationStatusIcon = valid ? validIcon : errorIcon;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ListItemButton onClick={onClick} selected={expanded} divider>
|
||||||
|
<Typography variant="body2">
|
||||||
|
{expanded ? <ExpandLessIcon /> : <ExpandMoreIcon />}
|
||||||
|
{title}
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
{hasValidation && validationStatusIcon}
|
||||||
|
</ListItemButton>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default FlowSubstepTitle;
|
13
packages/web/src/components/FlowSubstepTitle/style.tsx
Normal file
13
packages/web/src/components/FlowSubstepTitle/style.tsx
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { styled } from '@mui/material/styles';
|
||||||
|
import MuiListItemButton from '@mui/material/ListItemButton';
|
||||||
|
import MuiTypography from '@mui/material/Typography';
|
||||||
|
|
||||||
|
export const ListItemButton = styled(MuiListItemButton)`
|
||||||
|
justify-content: space-between;
|
||||||
|
`;
|
||||||
|
|
||||||
|
export const Typography = styled(MuiTypography)`
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: ${({ theme }) => theme.spacing(1)};
|
||||||
|
`;
|
Reference in New Issue
Block a user