fixes: switching app version from version creation modal results in editor loading state

This commit is contained in:
arpitnath 2023-09-29 15:06:18 +05:30
parent 6f2522f5c3
commit 18bbb46814
2 changed files with 13 additions and 9 deletions

View file

@ -17,6 +17,7 @@ export const CreateVersion = ({
}) => {
const [isCreatingVersion, setIsCreatingVersion] = useState(false);
const [versionName, setVersionName] = useState('');
const { t } = useTranslation();
const { editingVersion } = useAppVersionStore(
(state) => ({
@ -25,6 +26,14 @@ export const CreateVersion = ({
shallow
);
const options = appVersions.map((version) => {
return { label: version.name, value: version };
});
const [selectedVersion, setSelectedVersion] = useState(() =>
options.find((option) => option?.value?.id === editingVersion?.id)
);
const createVersion = () => {
if (versionName.trim().length > 25) {
toast.error('Version name should not be longer than 25 characters');
@ -36,8 +45,9 @@ export const CreateVersion = ({
}
setIsCreatingVersion(true);
appVersionService
.create(appId, versionName, editingVersion.id)
.create(appId, versionName, selectedVersion.id)
.then((data) => {
toast.success('Version Created');
appVersionService.getAll(appId).then((data) => {
@ -62,10 +72,6 @@ export const CreateVersion = ({
});
};
const options = appVersions.map((version) => {
return { label: version.name, value: version };
});
return (
<AlertDialog
show={showCreateAppVersion}
@ -108,9 +114,9 @@ export const CreateVersion = ({
<div className="ts-control" data-cy="create-version-from-input-field">
<Select
options={options}
defaultValue={options.find((option) => option?.value?.id === editingVersion?.id)}
defaultValue={selectedVersion}
onChange={(version) => {
setAppDefinitionFromVersion(version, false);
setSelectedVersion(version);
}}
useMenuPortal={false}
width="100%"

View file

@ -811,8 +811,6 @@ const EditorComponent = (props) => {
const paramDiff = computeComponentPropertyDiff(appDefinitionDiff, appDefinition, appDiffOptions);
const updateDiff = computeAppDiff(paramDiff, currentPageId, appDiffOptions);
console.log('----arpit::', { paramDiff, updateDiff });
updateAppVersion(appId, editingVersion?.id, currentPageId, updateDiff, isUserSwitchedVersion)
.then(() => {
const _editingVersion = {