Skip to content

Commit

Permalink
Merge pull request #184 from MOV-AI/bugfix/FP-2527-closing-new-doc-do…
Browse files Browse the repository at this point in the history
…es-not-dismiss-it

FP-2527: Preventing the reload of a new doc when it's closed
  • Loading branch information
diasnad authored Aug 14, 2023
2 parents 66827f0 + 2a88e02 commit 697cf67
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# 1.0.0 --installs on--> 2.4 IDE-EE / 3.1 IDE-CE

- [FP-2527 - Preventing the reload of a new doc when it's closed](https://movai.atlassian.net/browse/FP-2527)
- [FP-2216 - IDE- black screen after changing resolution](https://movai.atlassian.net/browse/FP-2216)
- [FP-2542 - Removed code that prevented flow validations from running](https://movai.atlassian.net/browse/FP-2542)
- [FP-2540 - Duplicated code on the new merge request](https://movai.atlassian.net/browse/FP-2540)
Expand Down
7 changes: 4 additions & 3 deletions src/plugins/DocManager/DocManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class DocManager extends IDEPlugin {
scope,
onSubmit: async action => {
switch (action) {
case SAVE_OUTDATED_DOC_ACTIONS.UPDATE_DOC:
case SAVE_OUTDATED_DOC_ACTIONS.UPDATE_DOC: {
this.discardDocChanges(modelKey);
const updatedDoc = await this.read(modelKey);

Expand All @@ -229,6 +229,7 @@ class DocManager extends IDEPlugin {

this.saveStack.delete(`${name}_${scope}`);
break;
}
case SAVE_OUTDATED_DOC_ACTIONS.OVERWRITE_DOC:
this.doSave(modelKey, callback, undefined, opts);
break;
Expand Down Expand Up @@ -289,7 +290,7 @@ class DocManager extends IDEPlugin {
});
}

callback && callback(returnMessage);
callback?.(returnMessage);
this.saveStack.delete(`${name}_${scope}`);
return returnMessage;
}
Expand Down Expand Up @@ -424,7 +425,7 @@ class DocManager extends IDEPlugin {
* Remove subscribers
* @param {Event} event
*/
onUnload = _event => {
onUnload = () => {
this.getStores().forEach(store => {
const dirtyDocs = store.getDirties();

Expand Down
24 changes: 17 additions & 7 deletions src/plugins/views/Tabs/hooks/useTabLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const useTabLayout = (props, dockRef) => {
const workspaceManager = useMemo(() => new Workspace(), []);
const activeTabId = useRef(null);
const firstLoad = useRef(true);
const preventReloadNewDoc = useRef(false);
const tabsById = useRef(new Map());
const [layout, setLayout] = useState({ ...DEFAULT_LAYOUT });
const { addTabToStack, removeTabFromStack, getNextTabFromStack } =
Expand Down Expand Up @@ -198,8 +199,9 @@ const useTabLayout = (props, dockRef) => {
const newLayout = { ...prevLayout };
const box = _getTabContainer(newLayout[location], prevTabId);
if (box) {
tabData.id = `${tabData.id.substring(0, tabData.id.lastIndexOf("/"))}/${tabData.name
}`;
tabData.id = `${tabData.id.substring(0, tabData.id.lastIndexOf("/"))}/${
tabData.name
}`;
const tabIndex = box.tabs.findIndex(_el => _el.id === prevTabId);
box.tabs[tabIndex] = tabData;
box.activeId = tabData.id;
Expand Down Expand Up @@ -305,6 +307,7 @@ const useTabLayout = (props, dockRef) => {
name,
scope,
onSubmit: action => {
preventReloadNewDoc.current = true;
const triggerAction = {
// Save changes and close document
save: () => _saveDoc(document),
Expand Down Expand Up @@ -460,7 +463,10 @@ const useTabLayout = (props, dockRef) => {
if (!docFactory) return docData;
return installTabPlugin(docFactory, docData)
.then(viewPlugin => {
const Decorated = withError(() => viewPlugin.render(docFactory.props ?? {}), dependencies);
const Decorated = withError(
() => viewPlugin.render(docFactory.props ?? {}),
dependencies
);

// Create and return tab data
const extension = docFactory.store.model.EXTENSION ?? "";
Expand Down Expand Up @@ -773,10 +779,14 @@ const useTabLayout = (props, dockRef) => {

updateTabId(doc.path.replace(`/${doc.version}`, ""), newTabData);

call(PLUGINS.DOC_MANAGER.NAME, PLUGINS.DOC_MANAGER.CALL.RELOAD_DOC, {
scope,
name
});
if (!preventReloadNewDoc.current) {
call(PLUGINS.DOC_MANAGER.NAME, PLUGINS.DOC_MANAGER.CALL.RELOAD_DOC, {
scope,
name
});
}

preventReloadNewDoc.current = false;
}
});
// Unsubscribe on unmount
Expand Down

0 comments on commit 697cf67

Please sign in to comment.