fix(popup): fix URL anomalies caused by using popups together with Link buttons (#5219)

* fix(popup): resolve URL issues caused by popups used with Link buttons

* chore: make e2e tests pass
This commit is contained in:
Zeke Zhang 2024-09-08 22:14:51 +08:00 committed by GitHub
parent b2dd68faff
commit 1e7a740f66
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 2 additions and 14 deletions

View File

@ -40,7 +40,7 @@ test.describe('sub page', () => {
page.getByLabel('block-item-Markdown.Void-').getByText('Markdown从弹窗中打开的子页面tab2。'), page.getByLabel('block-item-Markdown.Void-').getByText('Markdown从弹窗中打开的子页面tab2。'),
).toBeVisible(); ).toBeVisible();
await page.getByLabel('back-button').click(); await page.getByLabel('back-button').click();
await page.goBack(); await page.getByLabel('drawer-Action.Container-users-View record-mask').click();
// 从嵌套弹窗中打开子页面 -------------------------------------------------------------------- // 从嵌套弹窗中打开子页面 --------------------------------------------------------------------
await page.getByLabel('action-Action.Link-View-view-').nth(2).click(); await page.getByLabel('action-Action.Link-View-view-').nth(2).click();

View File

@ -48,10 +48,6 @@ export interface PopupContextStorage extends PopupContext {
/** used to refresh data for block */ /** used to refresh data for block */
service?: any; service?: any;
sourceId?: string; sourceId?: string;
/**
* if true, will not back to the previous path when closing the popup
*/
notBackToPreviousPath?: boolean;
} }
const popupsContextStorage: Record<string, PopupContextStorage> = {}; const popupsContextStorage: Record<string, PopupContextStorage> = {};
@ -279,14 +275,7 @@ export const usePopupUtils = (
return setVisibleFromAction?.(false); return setVisibleFromAction?.(false);
} }
// 1. If there is a value in the cache, it means that the current popup was opened by manual click, so we can simply return to the previous record; navigate(withSearchParams(removeLastPopupPath(location.pathname)), { replace: true });
// 2. If there is no value in the cache, it means that the current popup was opened by clicking the URL elsewhere, and since there is no history,
// we need to construct the URL of the previous record to return to;
if (getStoredPopupContext(currentPopupUid) && !getStoredPopupContext(currentPopupUid).notBackToPreviousPath) {
navigate(-1);
} else {
navigate(withSearchParams(removeLastPopupPath(location.pathname)));
}
}, },
[isPopupVisibleControlledByURL, setVisibleFromAction, navigate, location?.pathname], [isPopupVisibleControlledByURL, setVisibleFromAction, navigate, location?.pathname],
); );

View File

@ -33,7 +33,6 @@ function cacheSchema(collectionNameList: string[]) {
storePopupContext(workflowTodoViewActionSchema['x-uid'], { storePopupContext(workflowTodoViewActionSchema['x-uid'], {
schema: workflowTodoViewActionSchema, schema: workflowTodoViewActionSchema,
...workflowTodoViewActionSchema['x-action-context'], ...workflowTodoViewActionSchema['x-action-context'],
notBackToPreviousPath: true,
}); });
}); });
} }