## Description Adds navigation and routing changes for different parts of the app sidebar. Creating a router setup for the side pane and added extra routing conditions for library and settings route for the main pain #### PR fixes following issue(s) Fixes #27958 #### Media https://github.com/appsmithorg/appsmith/assets/12022471/5458275a-d597-4755-8d37-6e20a3386a80 #### Type of change - Chore (housekeeping or task changes that don't impact user perception) ## Testing #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [ ] Manual - [ ] JUnit - [ ] Jest - [ ] Cypress > > #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
199 lines
5.5 KiB
TypeScript
199 lines
5.5 KiB
TypeScript
import { matchPath } from "react-router";
|
|
import {
|
|
API_EDITOR_ID_PATH,
|
|
BUILDER_CUSTOM_PATH,
|
|
BUILDER_PATH,
|
|
BUILDER_PATH_DEPRECATED,
|
|
DATA_SOURCES_EDITOR_ID_PATH,
|
|
INTEGRATION_EDITOR_PATH,
|
|
JS_COLLECTION_ID_PATH,
|
|
QUERIES_EDITOR_ID_PATH,
|
|
WIDGETS_EDITOR_ID_PATH,
|
|
} from "constants/routes";
|
|
import { SAAS_EDITOR_DATASOURCE_ID_PATH } from "pages/Editor/SaaSEditor/constants";
|
|
import { SAAS_EDITOR_API_ID_PATH } from "pages/Editor/SaaSEditor/constants";
|
|
import { getQueryParamsFromString } from "utils/getQueryParamsObject";
|
|
import { TEMP_DATASOURCE_ID } from "constants/Datasource";
|
|
|
|
export enum FocusEntity {
|
|
PAGE = "PAGE",
|
|
API = "API",
|
|
CANVAS = "CANVAS",
|
|
DATASOURCE_LIST = "DATASOURCE_LIST",
|
|
DATASOURCE = "DATASOURCE",
|
|
DEBUGGER = "DEBUGGER",
|
|
QUERY = "QUERY",
|
|
JS_OBJECT = "JS_OBJECT",
|
|
PROPERTY_PANE = "PROPERTY_PANE",
|
|
NONE = "NONE",
|
|
}
|
|
|
|
export const FocusStoreHierarchy: Partial<Record<FocusEntity, FocusEntity>> = {
|
|
[FocusEntity.PROPERTY_PANE]: FocusEntity.CANVAS,
|
|
[FocusEntity.DATASOURCE]: FocusEntity.DATASOURCE_LIST,
|
|
};
|
|
|
|
export interface FocusEntityInfo {
|
|
entity: FocusEntity;
|
|
id: string;
|
|
pageId?: string;
|
|
}
|
|
|
|
/**
|
|
* Method to indicate if the URL is of type API, Query etc.,
|
|
* and not anything else
|
|
* @param path
|
|
* @returns
|
|
*/
|
|
export function shouldStoreURLForFocus(path: string) {
|
|
const entityTypesToStore = [
|
|
FocusEntity.QUERY,
|
|
FocusEntity.API,
|
|
FocusEntity.JS_OBJECT,
|
|
FocusEntity.DATASOURCE,
|
|
];
|
|
|
|
const entity = identifyEntityFromPath(path)?.entity;
|
|
|
|
return entityTypesToStore.indexOf(entity) >= 0;
|
|
}
|
|
|
|
/**
|
|
* parse search string and get branch
|
|
* @param searchString
|
|
* @returns
|
|
*/
|
|
const fetchGitBranch = (searchString: string | undefined) => {
|
|
const existingParams =
|
|
getQueryParamsFromString(searchString?.substring(1)) || {};
|
|
|
|
return existingParams.branch;
|
|
};
|
|
|
|
/**
|
|
* Compare if both the params are on same branch
|
|
* @param previousParamString
|
|
* @param currentParamStaring
|
|
* @returns
|
|
*/
|
|
export function isSameBranch(
|
|
previousParamString: string,
|
|
currentParamStaring: string,
|
|
) {
|
|
const previousBranch = fetchGitBranch(previousParamString);
|
|
const currentBranch = fetchGitBranch(currentParamStaring);
|
|
|
|
return previousBranch === currentBranch;
|
|
}
|
|
|
|
export function identifyEntityFromPath(path: string): FocusEntityInfo {
|
|
const match = matchPath<{
|
|
apiId?: string;
|
|
datasourceId?: string;
|
|
pluginPackageName?: string;
|
|
queryId?: string;
|
|
appId?: string;
|
|
pageId?: string;
|
|
collectionId?: string;
|
|
widgetIds?: string;
|
|
selectedTab?: string; // Datasource creation/list screen
|
|
entity?: string;
|
|
}>(path, {
|
|
path: [
|
|
BUILDER_PATH_DEPRECATED + API_EDITOR_ID_PATH,
|
|
BUILDER_PATH + API_EDITOR_ID_PATH,
|
|
BUILDER_CUSTOM_PATH + API_EDITOR_ID_PATH,
|
|
BUILDER_PATH_DEPRECATED + QUERIES_EDITOR_ID_PATH,
|
|
BUILDER_PATH + QUERIES_EDITOR_ID_PATH,
|
|
BUILDER_CUSTOM_PATH + QUERIES_EDITOR_ID_PATH,
|
|
BUILDER_PATH_DEPRECATED + DATA_SOURCES_EDITOR_ID_PATH,
|
|
BUILDER_PATH + DATA_SOURCES_EDITOR_ID_PATH,
|
|
BUILDER_CUSTOM_PATH + DATA_SOURCES_EDITOR_ID_PATH,
|
|
BUILDER_PATH_DEPRECATED + INTEGRATION_EDITOR_PATH,
|
|
BUILDER_PATH + INTEGRATION_EDITOR_PATH,
|
|
BUILDER_CUSTOM_PATH + INTEGRATION_EDITOR_PATH,
|
|
BUILDER_PATH + SAAS_EDITOR_DATASOURCE_ID_PATH,
|
|
BUILDER_CUSTOM_PATH + SAAS_EDITOR_DATASOURCE_ID_PATH,
|
|
BUILDER_PATH_DEPRECATED + SAAS_EDITOR_API_ID_PATH,
|
|
BUILDER_PATH + SAAS_EDITOR_API_ID_PATH,
|
|
BUILDER_CUSTOM_PATH + SAAS_EDITOR_API_ID_PATH,
|
|
BUILDER_PATH_DEPRECATED + JS_COLLECTION_ID_PATH,
|
|
BUILDER_PATH + JS_COLLECTION_ID_PATH,
|
|
BUILDER_CUSTOM_PATH + JS_COLLECTION_ID_PATH,
|
|
BUILDER_PATH + WIDGETS_EDITOR_ID_PATH,
|
|
BUILDER_CUSTOM_PATH + WIDGETS_EDITOR_ID_PATH,
|
|
BUILDER_PATH_DEPRECATED + WIDGETS_EDITOR_ID_PATH,
|
|
BUILDER_PATH + "/:entity",
|
|
BUILDER_CUSTOM_PATH + "/:entity",
|
|
BUILDER_PATH_DEPRECATED + "/:entity",
|
|
BUILDER_PATH_DEPRECATED,
|
|
BUILDER_PATH,
|
|
BUILDER_CUSTOM_PATH,
|
|
],
|
|
exact: true,
|
|
});
|
|
if (!match) {
|
|
return { entity: FocusEntity.NONE, id: "", pageId: "" };
|
|
}
|
|
if (match.params.apiId) {
|
|
if (match.params.pluginPackageName) {
|
|
return {
|
|
entity: FocusEntity.QUERY,
|
|
id: match.params.apiId,
|
|
pageId: match.params.pageId,
|
|
};
|
|
}
|
|
return {
|
|
entity: FocusEntity.API,
|
|
id: match.params.apiId,
|
|
pageId: match.params.pageId,
|
|
};
|
|
}
|
|
if (
|
|
match.params.datasourceId &&
|
|
match.params.datasourceId !== TEMP_DATASOURCE_ID
|
|
) {
|
|
return {
|
|
entity: FocusEntity.DATASOURCE,
|
|
id: match.params.datasourceId,
|
|
pageId: match.params.pageId,
|
|
};
|
|
}
|
|
if (match.params.selectedTab) {
|
|
return {
|
|
entity: FocusEntity.DATASOURCE,
|
|
id: match.params.selectedTab,
|
|
pageId: match.params.pageId,
|
|
};
|
|
}
|
|
if (match.params.entity === "datasource") {
|
|
return {
|
|
entity: FocusEntity.DATASOURCE_LIST,
|
|
id: "",
|
|
pageId: match.params.pageId,
|
|
};
|
|
}
|
|
if (match.params.queryId) {
|
|
return {
|
|
entity: FocusEntity.QUERY,
|
|
id: match.params.queryId,
|
|
pageId: match.params.pageId,
|
|
};
|
|
}
|
|
if (match.params.collectionId) {
|
|
return {
|
|
entity: FocusEntity.JS_OBJECT,
|
|
id: match.params.collectionId,
|
|
pageId: match.params.pageId,
|
|
};
|
|
}
|
|
if (match.params.widgetIds) {
|
|
return {
|
|
entity: FocusEntity.PROPERTY_PANE,
|
|
id: match.params.widgetIds,
|
|
pageId: match.params.pageId,
|
|
};
|
|
}
|
|
return { entity: FocusEntity.CANVAS, id: "", pageId: match.params.pageId };
|
|
}
|