chore: Refactoring focus strategy to get the correct key name on history removal for all IDEs (#39689)
## Description Refactoring focus strategy to get the correct key name on history removal for all IDEs Fixes [#39597](https://github.com/appsmithorg/appsmith/issues/39597) ## Automation /ok-to-test tags="@tag.All" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/13811684497> > Commit: ee66ead13719fbb882567cb2697af4cab10a5294 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=13811684497&attempt=2" target="_blank">Cypress dashboard</a>. > Tags: `@tag.All` > Spec: > <hr>Wed, 12 Mar 2025 14:19:55 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [ ] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added an enhanced mechanism for generating unique navigation keys that include branch details, improving focus state management. - **Refactor** - Restructured module organization to streamline focus history handling and overall navigation state operations. - **Chores** - Simplified URL assignment for improved clarity and maintainability. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Hetu Nandu <hetu@appsmith.com>
This commit is contained in:
parent
ce06e7edf7
commit
091c146309
|
|
@ -55,10 +55,10 @@ import {
|
|||
setSelectedEntityUrl,
|
||||
setSelectedJSObject,
|
||||
setSelectedQuery,
|
||||
} from "ee/navigation/FocusSetters";
|
||||
} from "ee/navigation/AppIDEFocusSetters";
|
||||
import { getFirstDatasourceId } from "selectors/datasourceSelectors";
|
||||
import { FocusElement, FocusElementConfigType } from "navigation/FocusElements";
|
||||
import type { FocusElementsConfigList } from "sagas/FocusRetentionSaga";
|
||||
import type { FocusElementsConfigList } from "ee/navigation/FocusStrategy/types";
|
||||
import { ActionExecutionResizerHeight } from "PluginActionEditor/components/PluginActionResponse/constants";
|
||||
import {
|
||||
getPluginActionConfigSelectedTab,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
import { all, select, take } from "redux-saga/effects";
|
||||
import type { FocusPath, FocusStrategy } from "sagas/FocusRetentionSaga";
|
||||
import type {
|
||||
FocusPath,
|
||||
FocusStrategy,
|
||||
} from "ee/navigation/FocusStrategy/types";
|
||||
import type { AppsmithLocationState } from "utils/history";
|
||||
import { NavigationMethod } from "utils/history";
|
||||
import type { FocusEntityInfo } from "navigation/FocusEntity";
|
||||
|
|
@ -288,6 +291,13 @@ export const AppIDEFocusStrategy: FocusStrategy = {
|
|||
// We do not have to add any query params because this url is used as the key
|
||||
return parentUrl.split("?")[0];
|
||||
},
|
||||
getUrlKey: function* (url: string) {
|
||||
const branch: string | undefined = yield select(
|
||||
selectGitApplicationCurrentBranch,
|
||||
);
|
||||
|
||||
return `${url}#${branch}`;
|
||||
},
|
||||
*waitForPathLoad(currentPath: string, previousPath?: string) {
|
||||
if (previousPath) {
|
||||
// When page is changing, there may be some items still not loaded,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { FocusStrategy } from "sagas/FocusRetentionSaga";
|
||||
import type { FocusStrategy } from "ee/navigation/FocusStrategy/types";
|
||||
import NoIDEFocusElements from "../FocusElements/NoIDE";
|
||||
export const NoIDEFocusStrategy: FocusStrategy = {
|
||||
focusElements: NoIDEFocusElements,
|
||||
|
|
@ -8,8 +8,11 @@ export const NoIDEFocusStrategy: FocusStrategy = {
|
|||
*getEntitiesForStore() {
|
||||
return [];
|
||||
},
|
||||
getEntityParentUrl(): string {
|
||||
getEntityParentUrl: (): string => {
|
||||
return "";
|
||||
},
|
||||
getUrlKey: function* (url: string) {
|
||||
return url;
|
||||
},
|
||||
*waitForPathLoad() {},
|
||||
};
|
||||
|
|
|
|||
50
app/client/src/ce/navigation/FocusStrategy/types.ts
Normal file
50
app/client/src/ce/navigation/FocusStrategy/types.ts
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
import type { FocusEntityInfo } from "navigation/FocusEntity";
|
||||
import type { FocusEntity } from "navigation/FocusEntity";
|
||||
import type { FocusElementConfig } from "navigation/FocusElements";
|
||||
import type { AppsmithLocationState } from "utils/history";
|
||||
|
||||
export interface FocusPath {
|
||||
key: string;
|
||||
entityInfo: FocusEntityInfo;
|
||||
}
|
||||
|
||||
export type FocusElementsConfigList = {
|
||||
[key in FocusEntity]?: FocusElementConfig[];
|
||||
};
|
||||
|
||||
export interface FocusStrategy {
|
||||
focusElements: FocusElementsConfigList;
|
||||
/** based on the route change, what states need to be set in the upcoming route **/
|
||||
getEntitiesForSet: (
|
||||
previousPath: string,
|
||||
currentPath: string,
|
||||
state: AppsmithLocationState,
|
||||
// TODO: Fix this the next time the file is edited
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
) => Generator<any, Array<FocusPath>, any>;
|
||||
/** based on the route change, what states need to be stored for the previous route **/
|
||||
getEntitiesForStore: (
|
||||
path: string,
|
||||
currentPath: string,
|
||||
// TODO: Fix this the next time the file is edited
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
) => Generator<any, Array<FocusPath>, any>;
|
||||
/** For entities with hierarchy, return the parent entity path for storing its state **/
|
||||
getEntityParentUrl: (
|
||||
entityInfo: FocusEntityInfo,
|
||||
parentEntity: FocusEntity,
|
||||
) => string;
|
||||
/** Get focus history key for the URL */
|
||||
getUrlKey: (
|
||||
url: string,
|
||||
// TODO: Fix this the next time the file is edited
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
) => Generator<any, string, any>;
|
||||
/** Define a wait (saga) before we start setting states **/
|
||||
waitForPathLoad: (
|
||||
currentPath: string,
|
||||
previousPath: string,
|
||||
// TODO: Fix this the next time the file is edited
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
) => Generator<any, void, any>;
|
||||
}
|
||||
|
|
@ -447,7 +447,7 @@ export function* deleteDatasourceSaga(
|
|||
const isValidResponse: boolean = yield validateResponse(response);
|
||||
|
||||
if (isValidResponse) {
|
||||
const currentUrl = `${window.location.pathname}`;
|
||||
const currentUrl = window.location.pathname;
|
||||
|
||||
yield call(handleDatasourceDeleteRedirect, id);
|
||||
yield call(FocusRetention.handleRemoveFocusHistory, currentUrl);
|
||||
|
|
|
|||
1
app/client/src/ee/navigation/AppIDEFocusSetters.ts
Normal file
1
app/client/src/ee/navigation/AppIDEFocusSetters.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from "ce/navigation/AppIDEFocusSetters";
|
||||
|
|
@ -1 +0,0 @@
|
|||
export * from "ce/navigation/FocusSetters";
|
||||
1
app/client/src/ee/navigation/FocusStrategy/types.ts
Normal file
1
app/client/src/ee/navigation/FocusStrategy/types.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * from "ce/navigation/FocusStrategy/types";
|
||||
|
|
@ -21,47 +21,10 @@ import type { Plugin } from "entities/Plugin";
|
|||
import { getIDETypeByUrl } from "ee/entities/IDE/utils";
|
||||
import { getIDEFocusStrategy } from "ee/navigation/FocusStrategy";
|
||||
import { IDE_TYPE } from "ee/IDE/Interfaces/IDETypes";
|
||||
import { selectGitApplicationCurrentBranch } from "selectors/gitModSelectors";
|
||||
|
||||
export interface FocusPath {
|
||||
key: string;
|
||||
entityInfo: FocusEntityInfo;
|
||||
}
|
||||
|
||||
export type FocusElementsConfigList = {
|
||||
[key in FocusEntity]?: FocusElementConfig[];
|
||||
};
|
||||
|
||||
export interface FocusStrategy {
|
||||
focusElements: FocusElementsConfigList;
|
||||
/** based on the route change, what states need to be set in the upcoming route **/
|
||||
getEntitiesForSet: (
|
||||
previousPath: string,
|
||||
currentPath: string,
|
||||
state: AppsmithLocationState,
|
||||
// TODO: Fix this the next time the file is edited
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
) => Generator<any, Array<FocusPath>, any>;
|
||||
/** based on the route change, what states need to be stored for the previous route **/
|
||||
getEntitiesForStore: (
|
||||
path: string,
|
||||
currentPath: string,
|
||||
// TODO: Fix this the next time the file is edited
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
) => Generator<any, Array<FocusPath>, any>;
|
||||
/** For entities with hierarchy, return the parent entity path for storing its state **/
|
||||
getEntityParentUrl: (
|
||||
entityInfo: FocusEntityInfo,
|
||||
parentEntity: FocusEntity,
|
||||
) => string;
|
||||
/** Define a wait (saga) before we start setting states **/
|
||||
waitForPathLoad: (
|
||||
currentPath: string,
|
||||
previousPath: string,
|
||||
// TODO: Fix this the next time the file is edited
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
) => Generator<any, void, any>;
|
||||
}
|
||||
import type {
|
||||
FocusPath,
|
||||
FocusStrategy,
|
||||
} from "ee/navigation/FocusStrategy/types";
|
||||
|
||||
/**
|
||||
* Context switching works by restoring the states of ui elements to as they were
|
||||
|
|
@ -123,23 +86,27 @@ class FocusRetention {
|
|||
}
|
||||
|
||||
public *handleRemoveFocusHistory(url: string) {
|
||||
const branch: string | undefined = yield select(
|
||||
selectGitApplicationCurrentBranch,
|
||||
);
|
||||
const removeKeys: string[] = [];
|
||||
const entityKey: string = yield call(this.focusStrategy.getUrlKey, url);
|
||||
const focusEntityInfo = identifyEntityFromPath(url);
|
||||
|
||||
removeKeys.push(`${url}#${branch}`);
|
||||
removeKeys.push(entityKey);
|
||||
|
||||
const parentElement = FocusStoreHierarchy[focusEntityInfo.entity];
|
||||
|
||||
if (parentElement) {
|
||||
const parentPath = this.focusStrategy.getEntityParentUrl(
|
||||
const parentUrl: string = yield call(
|
||||
this.focusStrategy.getEntityParentUrl,
|
||||
focusEntityInfo,
|
||||
parentElement,
|
||||
);
|
||||
|
||||
removeKeys.push(`${parentPath}#${branch}`);
|
||||
const parentEntityKey: string = yield call(
|
||||
this.focusStrategy.getUrlKey,
|
||||
parentUrl,
|
||||
);
|
||||
|
||||
removeKeys.push(parentEntityKey);
|
||||
}
|
||||
|
||||
for (const key of removeKeys) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user