PromucFlow_constructor/app/client/src/navigation/FocusEntity.ts
Hetu Nandu ca1713c73e
fix: Improvements to Sidebar for navigation (#29205)
## Description

- Rename to Pages to Editor in the Sidebar
- Move Editor to top
- Update "Home" to "All apps"

#### PR fixes following issue(s)
Fixes #29206

#### Media
> A video or a GIF is preferred. when using Loom, don’t embed because it
looks like it’s a GIF. instead, just link to the video
>
>
#### Type of change
> Please delete options that are not relevant.
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- Chore (housekeeping or task changes that don't impact user perception)
- This change requires a documentation update
>
>
>
## 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
2023-11-30 06:11:59 +05:30

220 lines
5.9 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_API_ID_PATH,
SAAS_EDITOR_DATASOURCE_ID_PATH,
} from "pages/Editor/SaaSEditor/constants";
import { TEMP_DATASOURCE_ID } from "constants/Datasource";
import { AppState } from "../entities/IDE/constants";
export enum FocusEntity {
PAGE = "PAGE",
API = "API",
CANVAS = "CANVAS",
DATASOURCE_LIST = "DATASOURCE_LIST",
DATASOURCE = "DATASOURCE",
DEBUGGER = "DEBUGGER",
QUERY = "QUERY",
QUERY_LIST = "QUERY_LIST",
JS_OBJECT = "JS_OBJECT",
JS_OBJECT_LIST = "JS_OBJECT_LIST",
PROPERTY_PANE = "PROPERTY_PANE",
NONE = "NONE",
APP_STATE = "APP_STATE",
LIBRARY = "LIBRARY",
SETTINGS = "SETTINGS",
}
export const FocusStoreHierarchy: Partial<Record<FocusEntity, FocusEntity>> = {
[FocusEntity.PROPERTY_PANE]: FocusEntity.CANVAS,
[FocusEntity.DATASOURCE]: FocusEntity.DATASOURCE_LIST,
[FocusEntity.JS_OBJECT]: FocusEntity.JS_OBJECT_LIST,
[FocusEntity.QUERY]: FocusEntity.QUERY_LIST,
};
export interface FocusEntityInfo {
entity: FocusEntity;
id: string;
appState: AppState;
pageId?: string;
}
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: "",
appState: AppState.EDITOR,
};
}
if (match.params.apiId) {
if (match.params.pluginPackageName) {
return {
entity: FocusEntity.QUERY,
id: match.params.apiId,
pageId: match.params.pageId,
appState: AppState.EDITOR,
};
}
return {
entity: FocusEntity.QUERY,
id: match.params.apiId,
pageId: match.params.pageId,
appState: AppState.EDITOR,
};
}
if (match.params.datasourceId) {
if (match.params.datasourceId == TEMP_DATASOURCE_ID) {
return {
entity: FocusEntity.NONE,
id: match.params.datasourceId,
pageId: match.params.pageId,
appState: AppState.DATA,
};
} else {
return {
entity: FocusEntity.DATASOURCE,
id: match.params.datasourceId,
pageId: match.params.pageId,
appState: AppState.DATA,
};
}
}
if (match.params.selectedTab) {
return {
entity: FocusEntity.DATASOURCE,
id: match.params.selectedTab,
pageId: match.params.pageId,
appState: AppState.DATA,
};
}
if (match.params.entity === "datasource") {
return {
entity: FocusEntity.DATASOURCE_LIST,
id: "",
pageId: match.params.pageId,
appState: AppState.DATA,
};
}
if (match.params.queryId) {
return {
entity: FocusEntity.QUERY,
id: match.params.queryId,
pageId: match.params.pageId,
appState: AppState.EDITOR,
};
}
if (match.params.collectionId) {
return {
entity: FocusEntity.JS_OBJECT,
id: match.params.collectionId,
pageId: match.params.pageId,
appState: AppState.EDITOR,
};
}
if (match.params.widgetIds) {
return {
entity: FocusEntity.PROPERTY_PANE,
id: match.params.widgetIds,
pageId: match.params.pageId,
appState: AppState.EDITOR,
};
}
if (match.params.entity === "queries") {
return {
entity: FocusEntity.QUERY_LIST,
id: "",
pageId: match.params.pageId,
appState: AppState.EDITOR,
};
}
if (match.params.entity === "jsObjects") {
return {
entity: FocusEntity.JS_OBJECT_LIST,
id: "",
pageId: match.params.pageId,
appState: AppState.EDITOR,
};
}
if (match.params.entity) {
if (match.params.entity === "libraries") {
return {
entity: FocusEntity.LIBRARY,
id: "",
appState: AppState.LIBRARIES,
pageId: match.params.pageId,
};
}
if (match.params.entity === "settings") {
return {
entity: FocusEntity.SETTINGS,
id: "",
appState: AppState.SETTINGS,
pageId: match.params.pageId,
};
}
}
return {
entity: FocusEntity.CANVAS,
id: "",
pageId: match.params.pageId,
appState: AppState.EDITOR,
};
}