PromucFlow_constructor/app/client/src/navigation/FocusElements.ts
Hetu Nandu 8e88676243
fix: Widget Context Switching (#29735)
## Description
Fixes context switching issues related to Widget List ensuring it also
works for current prod


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


#### 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
- Bug fix (non-breaking change which fixes an issue)

## 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


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
  - Added a search functionality to the app.
- Integrated a search bar at the top of the `Hero` component and a
`Search` component to the `App` component.
  - Included styles for the search bar in the application.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2023-12-20 12:26:16 +05:30

361 lines
10 KiB
TypeScript

import type { ReduxAction } from "@appsmith/constants/ReduxActionConstants";
import type { AppState } from "@appsmith/reducers";
import {
setApiPaneConfigSelectedTabIndex,
setApiRightPaneSelectedTab,
} from "actions/apiPaneActions";
import {
setAllEntityCollapsibleStates,
setAllSubEntityCollapsibleStates,
setCodeEditorHistory,
setExplorerSwitchIndex,
setFocusableInputField,
setPanelPropertiesState,
setWidgetSelectedPropertyTabIndex,
} from "actions/editorContextActions";
import {
getApiPaneConfigSelectedTabIndex,
getApiRightPaneSelectedTab,
} from "selectors/apiPaneSelectors";
import {
getAllEntityCollapsibleStates,
getAllPropertySectionState,
getAllSubEntityCollapsibleStates,
getCodeEditorHistory,
getExplorerSwitchIndex,
getFocusableInputField,
getPropertyPanelState,
getWidgetSelectedPropertyTabIndex,
} from "selectors/editorContextSelectors";
import {
getAllDatasourceCollapsibleState,
getDefaultSelectedWidgetIds,
getDsViewModeValues,
getSelectedWidgets,
} from "selectors/ui";
import {
setAllDatasourceCollapsible,
setDatasourceViewMode,
} from "actions/datasourceActions";
import { updateExplorerWidthAction } from "actions/explorerActions";
import { setJsPaneConfigSelectedTab } from "actions/jsPaneActions";
import {
setAllPropertySectionState,
setFocusablePropertyPaneField,
setPropertyPaneWidthAction,
setSelectedPropertyPanels,
} from "actions/propertyPaneActions";
import { setQueryPaneConfigSelectedTabIndex } from "actions/queryPaneActions";
import { selectWidgetInitAction } from "actions/widgetSelectionActions";
import {
DEFAULT_ENTITY_EXPLORER_WIDTH,
DEFAULT_PROPERTY_PANE_WIDTH,
} from "constants/AppConstants";
import { PluginPackageName } from "entities/Action";
import { FocusEntity } from "navigation/FocusEntity";
import { SelectionRequestType } from "sagas/WidgetSelectUtils";
import { getExplorerWidth } from "selectors/explorerSelector";
import {
getFirstJSObjectId,
getJSPaneConfigSelectedTab,
} from "selectors/jsPaneSelectors";
import {
getFocusablePropertyPaneField,
getPropertyPaneWidth,
getSelectedPropertyPanel,
} from "selectors/propertyPaneSelectors";
import {
getFirstQueryId,
getQueryPaneConfigSelectedTabIndex,
} from "selectors/queryPaneSelectors";
import { getDebuggerContext } from "selectors/debuggerSelectors";
import { setDebuggerContext } from "actions/debuggerActions";
import { DefaultDebuggerContext } from "reducers/uiReducers/debuggerReducer";
import { NavigationMethod } from "../utils/history";
import { JSEditorTab } from "../reducers/uiReducers/jsPaneReducer";
import {
getSelectedDatasourceId,
getSelectedJSObjectId,
getSelectedQueryId,
getSelectedSegment,
} from "./FocusSelectors";
import {
setSelectedDatasource,
setSelectedJSObject,
setSelectedQuery,
setSelectedSegment,
} from "./FocusSetters";
import { getFirstDatasourceId } from "../selectors/datasourceSelectors";
export enum FocusElement {
ApiPaneConfigTabs = "ApiPaneConfigTabs",
CodeEditorHistory = "CodeEditorHistory",
EntityCollapsibleState = "EntityCollapsibleState",
EntityExplorerWidth = "EntityExplorerWidth",
ExplorerSwitchIndex = "ExplorerSwitchIndex",
DatasourceViewMode = "DatasourceViewMode",
DatasourceAccordions = "DatasourceAccordions",
SelectedDatasource = "SelectedDatasource",
DebuggerContext = "DebuggerContext",
ApiRightPaneTabs = "ApiRightPaneTabs",
QueryPaneConfigTabs = "QueryPaneConfigTabs",
JSPaneConfigTabs = "JSPaneConfigTabs",
PropertySections = "PropertySections",
PropertyField = "PropertyField",
PropertyTabs = "PropertyTabs",
PropertyPanelContext = "PropertyPanelContext",
PropertyPaneWidth = "PropertyPaneWidth",
SelectedPropertyPanel = "SelectedPropertyPanel",
SelectedWidgets = "SelectedWidgets",
SubEntityCollapsibleState = "SubEntityCollapsibleState",
InputField = "InputField",
SelectedQuery = "SelectedQuery",
SelectedJSObject = "SelectedJSObject",
SelectedSegment = "SelectedSegment",
}
export enum ConfigType {
Redux = "Redux",
URL = "URL",
}
interface ConfigOther {
name: FocusElement;
/* If a selector is added for default value, it will be supplied the state to
derive a default value */
defaultValue?: unknown | ((state: AppState) => unknown);
subTypes?: Record<string, { defaultValue: unknown }>;
}
type ConfigRedux = {
type: ConfigType.Redux;
selector: (state: AppState) => unknown;
setter: (payload: any) => ReduxAction<any>;
} & ConfigOther;
type ConfigURL = {
type: ConfigType.URL;
selector: (url: string) => unknown;
setter: (payload: any) => void;
} & ConfigOther;
export type Config = ConfigRedux | ConfigURL;
export const FocusElementsConfig: Record<FocusEntity, Config[]> = {
[FocusEntity.NONE]: [],
[FocusEntity.APP_STATE]: [],
[FocusEntity.PAGE]: [],
[FocusEntity.CANVAS]: [],
[FocusEntity.DATASOURCE_LIST]: [
{
type: ConfigType.URL,
name: FocusElement.SelectedDatasource,
selector: getSelectedDatasourceId,
setter: setSelectedDatasource,
defaultValue: getFirstDatasourceId,
},
],
[FocusEntity.DATASOURCE]: [
{
type: ConfigType.Redux,
name: FocusElement.DatasourceViewMode,
selector: getDsViewModeValues,
setter: setDatasourceViewMode,
defaultValue: { datasourceId: "", viewMode: true },
},
{
type: ConfigType.Redux,
name: FocusElement.DatasourceAccordions,
selector: getAllDatasourceCollapsibleState,
setter: setAllDatasourceCollapsible,
},
],
[FocusEntity.JS_OBJECT]: [
{
type: ConfigType.Redux,
name: FocusElement.InputField,
selector: getFocusableInputField,
setter: setFocusableInputField,
},
{
type: ConfigType.Redux,
name: FocusElement.JSPaneConfigTabs,
selector: getJSPaneConfigSelectedTab,
setter: setJsPaneConfigSelectedTab,
defaultValue: JSEditorTab.CODE,
},
],
[FocusEntity.QUERY]: [
{
type: ConfigType.Redux,
name: FocusElement.InputField,
selector: getFocusableInputField,
setter: setFocusableInputField,
},
{
type: ConfigType.Redux,
name: FocusElement.QueryPaneConfigTabs,
selector: getQueryPaneConfigSelectedTabIndex,
setter: setQueryPaneConfigSelectedTabIndex,
defaultValue: 0,
},
{
type: ConfigType.Redux,
name: FocusElement.ApiPaneConfigTabs,
selector: getApiPaneConfigSelectedTabIndex,
setter: setApiPaneConfigSelectedTabIndex,
defaultValue: 0,
subTypes: {
[PluginPackageName.GRAPHQL]: {
defaultValue: 2,
},
},
},
{
type: ConfigType.Redux,
name: FocusElement.InputField,
selector: getFocusableInputField,
setter: setFocusableInputField,
},
{
type: ConfigType.Redux,
name: FocusElement.ApiRightPaneTabs,
selector: getApiRightPaneSelectedTab,
setter: setApiRightPaneSelectedTab,
},
],
[FocusEntity.PROPERTY_PANE]: [
{
type: ConfigType.Redux,
name: FocusElement.PropertyPanelContext,
selector: getPropertyPanelState,
setter: setPanelPropertiesState,
defaultValue: {},
},
{
type: ConfigType.Redux,
name: FocusElement.PropertySections,
selector: getAllPropertySectionState,
setter: setAllPropertySectionState,
defaultValue: {},
},
{
type: ConfigType.Redux,
name: FocusElement.SelectedPropertyPanel,
selector: getSelectedPropertyPanel,
setter: setSelectedPropertyPanels,
defaultValue: {},
},
{
type: ConfigType.Redux,
name: FocusElement.PropertyTabs,
selector: getWidgetSelectedPropertyTabIndex,
setter: setWidgetSelectedPropertyTabIndex,
defaultValue: 0,
},
{
type: ConfigType.Redux,
name: FocusElement.PropertyField,
selector: getFocusablePropertyPaneField,
setter: setFocusablePropertyPaneField,
defaultValue: "",
},
{
type: ConfigType.Redux,
name: FocusElement.PropertyPaneWidth,
selector: getPropertyPaneWidth,
setter: setPropertyPaneWidthAction,
defaultValue: DEFAULT_PROPERTY_PANE_WIDTH,
},
],
[FocusEntity.API]: [],
[FocusEntity.DEBUGGER]: [
{
type: ConfigType.Redux,
name: FocusElement.DebuggerContext,
selector: getDebuggerContext,
setter: setDebuggerContext,
defaultValue: DefaultDebuggerContext,
},
],
[FocusEntity.LIBRARY]: [],
[FocusEntity.SETTINGS]: [],
[FocusEntity.QUERY_LIST]: [
{
type: ConfigType.URL,
name: FocusElement.SelectedQuery,
selector: getSelectedQueryId,
setter: setSelectedQuery,
defaultValue: getFirstQueryId,
},
],
[FocusEntity.JS_OBJECT_LIST]: [
{
type: ConfigType.URL,
name: FocusElement.SelectedJSObject,
selector: getSelectedJSObjectId,
setter: setSelectedJSObject,
defaultValue: getFirstJSObjectId,
},
],
[FocusEntity.WIDGET_LIST]: [
{
type: ConfigType.Redux,
name: FocusElement.SelectedWidgets,
selector: getSelectedWidgets,
setter: (widgetIds: string[]) =>
selectWidgetInitAction(
SelectionRequestType.Multiple,
widgetIds,
NavigationMethod.ContextSwitching,
),
defaultValue: getDefaultSelectedWidgetIds,
},
],
[FocusEntity.QUERY_ADD]: [],
[FocusEntity.EDITOR]: [
{
type: ConfigType.URL,
name: FocusElement.SelectedSegment,
selector: getSelectedSegment,
setter: setSelectedSegment,
},
{
type: ConfigType.Redux,
name: FocusElement.EntityExplorerWidth,
selector: getExplorerWidth,
setter: updateExplorerWidthAction,
defaultValue: DEFAULT_ENTITY_EXPLORER_WIDTH,
},
{
type: ConfigType.Redux,
name: FocusElement.EntityCollapsibleState,
selector: getAllEntityCollapsibleStates,
setter: setAllEntityCollapsibleStates,
defaultValue: {},
},
{
type: ConfigType.Redux,
name: FocusElement.SubEntityCollapsibleState,
selector: getAllSubEntityCollapsibleStates,
setter: setAllSubEntityCollapsibleStates,
defaultValue: {},
},
{
type: ConfigType.Redux,
name: FocusElement.ExplorerSwitchIndex,
selector: getExplorerSwitchIndex,
setter: setExplorerSwitchIndex,
defaultValue: 0,
},
{
type: ConfigType.Redux,
name: FocusElement.CodeEditorHistory,
selector: getCodeEditorHistory,
setter: setCodeEditorHistory,
defaultValue: {},
},
],
};