Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix confirmation modal on reject result #3241

Merged
merged 11 commits into from
Apr 14, 2023
2 changes: 1 addition & 1 deletion core/src/Alerts.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
},
};
handleNavigation(data);
});
}, () => {});
} else if (link.dismissKey) {
dispatch('alertDismiss', {
id: alertId,
Expand Down
113 changes: 67 additions & 46 deletions core/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -245,18 +245,26 @@
return paths.includes(removeQueryParams(routePath));
};

/**
* Clears the dirty state when dirty state promise resolves and dirty state is not needed anymore
* @param source used for drawers/modals/split view wc and iframe when source is needed to differentiate which mf is affected
*/
const clearDirtyState = (source) => {
if (unsavedChanges && unsavedChanges.dirtySet) {
if (source) {
unsavedChanges.dirtySet.delete(source);
} else {
unsavedChanges.dirtySet.clear();
}
}
};

const getUnsavedChangesModalPromise = (source) => {
return new Promise((resolve, reject) => {
if (shouldShowUnsavedChangesModal(source)) {
showUnsavedChangesModal().then(
() => {
if (unsavedChanges && unsavedChanges.dirtySet) {
if (source) {
unsavedChanges.dirtySet.delete(source);
} else {
unsavedChanges.dirtySet.clear();
}
}
clearDirtyState();
resolve();
},
() => {
Expand Down Expand Up @@ -502,23 +510,26 @@

const handleNavClick = (event) => {
const node = event.detail.node;
getUnsavedChangesModalPromise().then(() => {
closeLeftNav();
if (node.openNodeInModal) {
const route = RoutingHelpers.buildRoute(node, `/${node.pathSegment}`);
openViewInModal(
route,
node.openNodeInModal === true ? {} : node.openNodeInModal
);
} else if (node.drawer) {
const route = RoutingHelpers.buildRoute(node, `/${node.pathSegment}`);
node.drawer.isDrawer = true;
openViewInDrawer(route, node.drawer);
} else {
getComponentWrapper().set({ isNavigationSyncEnabled: true });
Routing.handleRouteClick(node, getComponentWrapper());
}
});
getUnsavedChangesModalPromise().then(
() => {
closeLeftNav();
if (node.openNodeInModal) {
const route = RoutingHelpers.buildRoute(node, `/${node.pathSegment}`);
openViewInModal(
route,
node.openNodeInModal === true ? {} : node.openNodeInModal
);
} else if (node.drawer) {
const route = RoutingHelpers.buildRoute(node, `/${node.pathSegment}`);
node.drawer.isDrawer = true;
openViewInDrawer(route, node.drawer);
} else {
getComponentWrapper().set({ isNavigationSyncEnabled: true });
Routing.handleRouteClick(node, getComponentWrapper());
}
},
() => {}
);
};

const onResizeTabNav = () => {
Expand Down Expand Up @@ -1002,7 +1013,8 @@
() => {
resetModalData(index, isClosedInternal);
rp && rp.doResolve(goBackContext);
}
},
() => {}
);
} else if (targetModal && targetModal.modalWC) {
resetModalData(index, isClosedInternal);
Expand Down Expand Up @@ -1089,13 +1101,19 @@
) {
try {
if (drawerIframe) {
getUnsavedChangesModalPromise(drawerIframe.contentWindow).then(() => {
resetMicrofrontendDrawerData();
});
getUnsavedChangesModalPromise(drawerIframe.contentWindow).then(
() => {
resetMicrofrontendDrawerData();
},
() => {}
);
} else if (drawerWC) {
getUnsavedChangesModalPromise().then(() => {
resetMicrofrontendDrawerData();
});
getUnsavedChangesModalPromise().then(
() => {
resetMicrofrontendDrawerData();
},
() => {}
);
}
IframeHelpers.getCurrentMicrofrontendIframe().removeAttribute('style');
} catch (e) {
Expand Down Expand Up @@ -1571,21 +1589,24 @@
} else {
// go back: context from the view
if (preservedViews && preservedViews.length > 0) {
getUnsavedChangesModalPromise().then(() => {
// remove current active iframe and data
Iframe.setActiveIframeToPrevious(node);
const previousActiveIframeData = preservedViews.pop();
// set new active iframe and preservedViews
config.iframe = Iframe.getActiveIframe(node);
isNavigateBack = true;
preservedViews = preservedViews;
goBackContext = _goBackContext;
// TODO: check if getNavigationPath or history pop to update hash / path
handleNavigation(
{ params: { link: previousActiveIframeData.path } },
config
);
});
getUnsavedChangesModalPromise().then(
() => {
// remove current active iframe and data
Iframe.setActiveIframeToPrevious(node);
const previousActiveIframeData = preservedViews.pop();
// set new active iframe and preservedViews
config.iframe = Iframe.getActiveIframe(node);
isNavigateBack = true;
preservedViews = preservedViews;
goBackContext = _goBackContext;
// TODO: check if getNavigationPath or history pop to update hash / path
handleNavigation(
{ params: { link: previousActiveIframeData.path } },
config
);
},
() => {}
);
} else {
if (_goBackContext) {
console.warn(
Expand Down
8 changes: 4 additions & 4 deletions core/src/Authorization.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
} else {
Routing.navigateToLink(item);
}
});
}, () => {});
dispatch('toggleDropdownState');
}

Expand All @@ -169,7 +169,7 @@
} else {
console.error('No IDP provider or profile.customLogoutFn is defined.');
}
});
}, () => {});
}

export function onUserSettingsClick() {
Expand Down Expand Up @@ -246,7 +246,7 @@
tabindex="0"
class="fd-list__link"
data-testid="luigi-topnav-profile-item"
on:click={(event) => {
on:click={event => {
NavigationHelpers.handleNavAnchorClickedWithoutMetaKey(event);
}}
href={addNavHrefForAnchor ? getRouteLink(profileItem) : undefined}
Expand Down Expand Up @@ -277,7 +277,7 @@
role="listitem"
class="fd-list__item fd-list__item--link lui-anchor-node"
on:click|preventDefault={onUserSettingsClick}
on:keyup={(event) => handleKeyUp(event)}
on:keyup={event => handleKeyUp(event)}
>
<a
tabindex="0"
Expand Down
10 changes: 5 additions & 5 deletions core/src/AuthorizationSimpleProfileMenu.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
} else {
Routing.navigateToLink(item);
}
});
}, () => {});
dispatch('toggleDropdownState');
}

Expand All @@ -168,7 +168,7 @@
} else {
console.error('No IDP provider or profile.customLogoutFn is defined.');
}
});
}, () => {});
}

export function onUserSettingsClick() {
Expand Down Expand Up @@ -214,7 +214,7 @@
class="fd-menu__link"
data-testid="luigi-topnav-profile-item"
href={addNavHrefForAnchor ? getRouteLink(profileItem) : undefined}
on:click={(event) => {
on:click={event => {
NavigationHelpers.handleNavAnchorClickedWithoutMetaKey(event);
}}
>
Expand Down Expand Up @@ -242,7 +242,7 @@
tabindex="-1"
class="fd-menu__item lui-anchor-node"
on:click|preventDefault={onUserSettingsClick}
on:keyup={(event) => handleKeyUp(event)}
on:keyup={event => handleKeyUp(event)}
data-testid={getTestId(profileNav.settings)}
>
<a
Expand Down Expand Up @@ -352,7 +352,7 @@
overflow-y: auto;
}

.lui-profile-simple-menu .lui-logout-btn{
.lui-profile-simple-menu .lui-logout-btn {
text-align: left;
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/TopNavDropDown.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
} else {
Routing.handleRouteClick(node, getComponentWrapper());
}
});
}, () => {});
closeSubNav();
}

Expand Down Expand Up @@ -121,7 +121,7 @@
>
<a
href={addNavHrefForAnchor ? getRouteLink(node) : undefined}
on:click={(event) => {
on:click={event => {
NavigationHelpers.handleNavAnchorClickedWithoutMetaKey(event);
}}
class="fd-menu__link"
Expand Down
42 changes: 24 additions & 18 deletions core/src/navigation/ContextSwitcher.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -212,29 +212,35 @@
}

export function goToPath(path) {
getUnsavedChangesModalPromise().then(() => {
Routing.navigateTo(path);
});
getUnsavedChangesModalPromise().then(
() => {
Routing.navigateTo(path);
},
() => {}
);
}

export function goToOption(event) {
let option = event.detail.option;
let selectedOption = event.detail.selectedOption;
getUnsavedChangesModalPromise().then(() => {
if (preserveSubPathOnSwitch && selectedOption) {
Routing.navigateTo(
ContextSwitcherHelpers.getNodePathFromCurrentPath(
option,
selectedOption
)
);
} else {
Routing.navigateTo(option.link);
}
if (isMobile) {
dispatch('toggleDropdownState');
}
});
getUnsavedChangesModalPromise().then(
() => {
if (preserveSubPathOnSwitch && selectedOption) {
Routing.navigateTo(
ContextSwitcherHelpers.getNodePathFromCurrentPath(
option,
selectedOption
)
);
} else {
Routing.navigateTo(option.link);
}
if (isMobile) {
dispatch('toggleDropdownState');
}
},
() => {}
);
}

export function toggleDropdownState() {
Expand Down
Loading