Merge pull request #1811 from automatisch/AUT-920
fix: make inputs look and behave disabled when flow is in published state
This commit is contained in:
@@ -61,31 +61,38 @@ function ControlledCustomAutocomplete(props) {
|
|||||||
const [isSingleChoice, setSingleChoice] = React.useState(undefined);
|
const [isSingleChoice, setSingleChoice] = React.useState(undefined);
|
||||||
const priorStepsWithExecutions = React.useContext(StepExecutionsContext);
|
const priorStepsWithExecutions = React.useContext(StepExecutionsContext);
|
||||||
const editorRef = React.useRef(null);
|
const editorRef = React.useRef(null);
|
||||||
|
|
||||||
const renderElement = React.useCallback(
|
const renderElement = React.useCallback(
|
||||||
(props) => <Element {...props} disabled={disabled} />,
|
(props) => <Element {...props} disabled={disabled} />,
|
||||||
[disabled],
|
[disabled],
|
||||||
);
|
);
|
||||||
|
|
||||||
const [editor] = React.useState(() => customizeEditor(createEditor()));
|
const [editor] = React.useState(() => customizeEditor(createEditor()));
|
||||||
|
|
||||||
const [showVariableSuggestions, setShowVariableSuggestions] =
|
const [showVariableSuggestions, setShowVariableSuggestions] =
|
||||||
React.useState(false);
|
React.useState(false);
|
||||||
let dependsOnValues = [];
|
let dependsOnValues = [];
|
||||||
if (dependsOn?.length) {
|
if (dependsOn?.length) {
|
||||||
dependsOnValues = watch(dependsOn);
|
dependsOnValues = watch(dependsOn);
|
||||||
}
|
}
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const ref = ReactEditor.toDOMNode(editor, editor);
|
const ref = ReactEditor.toDOMNode(editor, editor);
|
||||||
resizeObserver.observe(ref);
|
resizeObserver.observe(ref);
|
||||||
return () => resizeObserver.unobserve(ref);
|
return () => resizeObserver.unobserve(ref);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const promoteValue = () => {
|
const promoteValue = () => {
|
||||||
const serializedValue = serialize(editor.children);
|
const serializedValue = serialize(editor.children);
|
||||||
controllerOnChange(serializedValue);
|
controllerOnChange(serializedValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
const resizeObserver = React.useMemo(function syncCustomOptionsPosition() {
|
const resizeObserver = React.useMemo(function syncCustomOptionsPosition() {
|
||||||
return new ResizeObserver(() => {
|
return new ResizeObserver(() => {
|
||||||
forceUpdate();
|
forceUpdate();
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
const hasDependencies = dependsOnValues.length;
|
const hasDependencies = dependsOnValues.length;
|
||||||
if (hasDependencies) {
|
if (hasDependencies) {
|
||||||
@@ -93,6 +100,7 @@ function ControlledCustomAutocomplete(props) {
|
|||||||
resetEditor(editor);
|
resetEditor(editor);
|
||||||
}
|
}
|
||||||
}, dependsOnValues);
|
}, dependsOnValues);
|
||||||
|
|
||||||
React.useEffect(
|
React.useEffect(
|
||||||
function updateInitialValue() {
|
function updateInitialValue() {
|
||||||
const hasOptions = options.length;
|
const hasOptions = options.length;
|
||||||
@@ -110,16 +118,19 @@ function ControlledCustomAutocomplete(props) {
|
|||||||
},
|
},
|
||||||
[isInitialValueSet, options, loading],
|
[isInitialValueSet, options, loading],
|
||||||
);
|
);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!showVariableSuggestions && value !== serialize(editor.children)) {
|
if (!showVariableSuggestions && value !== serialize(editor.children)) {
|
||||||
promoteValue();
|
promoteValue();
|
||||||
}
|
}
|
||||||
}, [showVariableSuggestions]);
|
}, [showVariableSuggestions]);
|
||||||
|
|
||||||
const hideSuggestionsOnShift = (event) => {
|
const hideSuggestionsOnShift = (event) => {
|
||||||
if (event.code === 'Tab') {
|
if (event.code === 'Tab') {
|
||||||
setShowVariableSuggestions(false);
|
setShowVariableSuggestions(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleKeyDown = (event) => {
|
const handleKeyDown = (event) => {
|
||||||
hideSuggestionsOnShift(event);
|
hideSuggestionsOnShift(event);
|
||||||
if (event.code === 'Tab') {
|
if (event.code === 'Tab') {
|
||||||
@@ -129,15 +140,18 @@ function ControlledCustomAutocomplete(props) {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const stepsWithVariables = React.useMemo(() => {
|
const stepsWithVariables = React.useMemo(() => {
|
||||||
return processStepWithExecutions(priorStepsWithExecutions);
|
return processStepWithExecutions(priorStepsWithExecutions);
|
||||||
}, [priorStepsWithExecutions]);
|
}, [priorStepsWithExecutions]);
|
||||||
|
|
||||||
const handleVariableSuggestionClick = React.useCallback(
|
const handleVariableSuggestionClick = React.useCallback(
|
||||||
(variable) => {
|
(variable) => {
|
||||||
insertVariable(editor, variable, stepsWithVariables);
|
insertVariable(editor, variable, stepsWithVariables);
|
||||||
},
|
},
|
||||||
[stepsWithVariables],
|
[stepsWithVariables],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleOptionClick = React.useCallback(
|
const handleOptionClick = React.useCallback(
|
||||||
(event, option) => {
|
(event, option) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
@@ -147,17 +161,20 @@ function ControlledCustomAutocomplete(props) {
|
|||||||
},
|
},
|
||||||
[stepsWithVariables],
|
[stepsWithVariables],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleClearButtonClick = (event) => {
|
const handleClearButtonClick = (event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
resetEditor(editor);
|
resetEditor(editor);
|
||||||
promoteValue();
|
promoteValue();
|
||||||
setSingleChoice(undefined);
|
setSingleChoice(undefined);
|
||||||
};
|
};
|
||||||
|
|
||||||
const reset = (tabIndex) => {
|
const reset = (tabIndex) => {
|
||||||
const isOptions = tabIndex === 0;
|
const isOptions = tabIndex === 0;
|
||||||
setSingleChoice(isOptions);
|
setSingleChoice(isOptions);
|
||||||
resetEditor(editor, { focus: true });
|
resetEditor(editor, { focus: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Slate
|
<Slate
|
||||||
editor={editor}
|
editor={editor}
|
||||||
|
@@ -178,6 +178,7 @@ export default function InputCreator(props) {
|
|||||||
helperText={description}
|
helperText={description}
|
||||||
clickToCopy={schema.clickToCopy}
|
clickToCopy={schema.clickToCopy}
|
||||||
shouldUnregister={shouldUnregister}
|
shouldUnregister={shouldUnregister}
|
||||||
|
disabled={disabled}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{isDynamicFieldsLoading && !additionalFields?.length && (
|
{isDynamicFieldsLoading && !additionalFields?.length && (
|
||||||
|
@@ -1,17 +1,20 @@
|
|||||||
import MuiTabs from '@mui/material/Tabs';
|
import MuiTabs from '@mui/material/Tabs';
|
||||||
import { styled } from '@mui/material/styles';
|
import { styled } from '@mui/material/styles';
|
||||||
|
|
||||||
export const ChildrenWrapper = styled('div')`
|
export const ChildrenWrapper = styled('div')`
|
||||||
overflow-wrap: break-word;
|
overflow-wrap: break-word;
|
||||||
word-wrap: break-word;
|
word-wrap: break-word;
|
||||||
word-break: break-word;
|
word-break: break-word;
|
||||||
hyphens: auto;
|
hyphens: auto;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const InputLabelWrapper = styled('div')`
|
export const InputLabelWrapper = styled('div')`
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: ${({ theme }) => theme.spacing(1.75)};
|
left: ${({ theme }) => theme.spacing(1.75)};
|
||||||
inset: 0;
|
inset: 0;
|
||||||
left: -6px;
|
left: -6px;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const FakeInput = styled('div', {
|
export const FakeInput = styled('div', {
|
||||||
shouldForwardProp: (prop) => prop !== 'disabled',
|
shouldForwardProp: (prop) => prop !== 'disabled',
|
||||||
})`
|
})`
|
||||||
@@ -31,15 +34,17 @@ export const FakeInput = styled('div', {
|
|||||||
border-color: ${theme.palette.action.disabled};
|
border-color: ${theme.palette.action.disabled};
|
||||||
`}
|
`}
|
||||||
|
|
||||||
|
${({ disabled, theme }) =>
|
||||||
|
!disabled &&
|
||||||
|
`
|
||||||
&:hover {
|
&:hover {
|
||||||
border-color: ${({ theme }) => theme.palette.text.primary};
|
border-color: ${theme.palette.text.primary};
|
||||||
}
|
}
|
||||||
|
|
||||||
&:focus-within,
|
&:focus-within,
|
||||||
&:focus {
|
&:focus {
|
||||||
&:before {
|
&:before {
|
||||||
border-color: ${({ theme }) => theme.palette.primary.main};
|
border-color: ${theme.palette.primary.main};
|
||||||
border-radius: ${({ theme }) => theme.spacing(0.5)};
|
border-radius: ${theme.spacing(0.5)};
|
||||||
border-style: solid;
|
border-style: solid;
|
||||||
border-width: 2px;
|
border-width: 2px;
|
||||||
bottom: -2px;
|
bottom: -2px;
|
||||||
@@ -51,7 +56,9 @@ export const FakeInput = styled('div', {
|
|||||||
top: -2px;
|
top: -2px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
`}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const Tabs = styled(MuiTabs)`
|
export const Tabs = styled(MuiTabs)`
|
||||||
border-bottom: 1px solid ${({ theme }) => theme.palette.divider};
|
border-bottom: 1px solid ${({ theme }) => theme.palette.divider};
|
||||||
`;
|
`;
|
||||||
|
Reference in New Issue
Block a user