This is an automated email from the ASF dual-hosted git repository.
tiagobento pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-tools.git
The following commit(s) were added to refs/heads/main by this push:
new 4c33d802408 NO-ISSUE: On KIE Sandbox, close navigation blocker modal
after deleting the last editable file in a workspace (#2998)
4c33d802408 is described below
commit 4c33d802408f9b3ffeae3dba7dc1c30b68c74cb1
Author: Thiago Lugli <[email protected]>
AuthorDate: Fri Mar 14 12:48:18 2025 -0300
NO-ISSUE: On KIE Sandbox, close navigation blocker modal after deleting the
last editable file in a workspace (#2998)
---
.../src/editor/Toolbar/EditorToolbar.tsx | 26 ++++++++++++++++++----
.../src/editor/Toolbar/Workspace/Hooks.tsx | 4 ++++
2 files changed, 26 insertions(+), 4 deletions(-)
diff --git a/packages/online-editor/src/editor/Toolbar/EditorToolbar.tsx
b/packages/online-editor/src/editor/Toolbar/EditorToolbar.tsx
index 954d7ef04e7..59015ae4bf9 100644
--- a/packages/online-editor/src/editor/Toolbar/EditorToolbar.tsx
+++ b/packages/online-editor/src/editor/Toolbar/EditorToolbar.tsx
@@ -34,7 +34,7 @@ import {
import { SaveIcon } from "@patternfly/react-icons/dist/js/icons/save-icon";
import { useOnlineI18n } from "../../i18n";
import { ExtendedServicesButtons } from
"../ExtendedServices/ExtendedServicesButtons";
-import { useRoutes } from "../../navigation/Hooks";
+import { useNavigationBlockersBypass, useRoutes } from
"../../navigation/Hooks";
import { EmbeddedEditorRef } from "@kie-tools-core/editor/dist/embedded";
import { useHistory } from "react-router";
import { useWorkspaces, WorkspaceFile } from
"@kie-tools-core/workspaces-git-fs/dist/context/WorkspacesContext";
@@ -137,6 +137,7 @@ export function EditorToolbarWithWorkspace(
useEditorToolbarDispatchContext();
useWorkspaceNavigationBlocker(props.workspace);
+ const navigationBlockersBypass = useNavigationBlockersBypass();
const { gitConfig } =
useAuthSession(props.workspace.descriptor.gitAuthSessionId);
@@ -163,7 +164,12 @@ export function EditorToolbarWithWorkspace(
})
.pop();
if (!nextFile) {
- history.push({ pathname: routes.home.path({}) });
+ // TODO: This will forcefully return home.
+ // There's no way to undo this deletion because the workspace won't be
accesible
+ // anymore without an editable file.
+ navigationBlockersBypass.execute(() => {
+ history.push({ pathname: routes.home.path({}) });
+ });
return;
}
@@ -177,6 +183,7 @@ export function EditorToolbarWithWorkspace(
}, [
editorEnvelopeLocator,
history,
+ navigationBlockersBypass,
props.workspace.files,
props.workspaceFile.relativePath,
routes.home,
@@ -185,8 +192,11 @@ export function EditorToolbarWithWorkspace(
const deleteWorkspaceFile = useCallback(async () => {
if (props.workspace.files.length === 1) {
+ // This was the last file, delete the workspace and return home
await workspaces.deleteWorkspace({ workspaceId:
props.workspaceFile.workspaceId });
- history.push({ pathname: routes.home.path({}) });
+ navigationBlockersBypass.execute(() => {
+ history.push({ pathname: routes.home.path({}) });
+ });
return;
}
@@ -195,7 +205,15 @@ export function EditorToolbarWithWorkspace(
});
handleDeletedWorkspaceFile();
- }, [props.workspace.files.length, props.workspaceFile, workspaces,
handleDeletedWorkspaceFile, history, routes.home]);
+ }, [
+ props.workspace.files.length,
+ props.workspaceFile,
+ workspaces,
+ handleDeletedWorkspaceFile,
+ navigationBlockersBypass,
+ history,
+ routes.home,
+ ]);
const deleteFileDropdownItem = useMemo(() => {
return (
diff --git a/packages/online-editor/src/editor/Toolbar/Workspace/Hooks.tsx
b/packages/online-editor/src/editor/Toolbar/Workspace/Hooks.tsx
index 97ebf3404fc..e8a13dbcdf5 100644
--- a/packages/online-editor/src/editor/Toolbar/Workspace/Hooks.tsx
+++ b/packages/online-editor/src/editor/Toolbar/Workspace/Hooks.tsx
@@ -151,6 +151,10 @@ export function useWorkspaceNavigationBlocker(workspace:
ActiveWorkspace) {
} else {
confirmNavigationAlert.close();
}
+
+ return () => {
+ confirmNavigationAlert.close();
+ };
}, [confirmNavigationAlert, navigationStatus]);
return;
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]