PromucFlow_constructor/app/client/src/ce/RouteBuilder.ts
Hetu Nandu ad54bfcd45
chore: Add Create as a Widget SelectionRequestType (#31799)
## Description

Adds a `SelectionRequestType.Create` and enhance `widgetUrl` to have add
view. When `Create` is selected, it will navigate to the `widgetUrl`
with add view

Fixes #30578

## Automation

/ok-to-test tags="@tags.Widget"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!CAUTION]  
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/8292718827>
> Commit: `231b88cc2c070f9286558b05e36bb1e0b84c7817`
> Cypress dashboard: <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=8292718827&attempt=1&selectiontype=test&testsstatus=failed&specsstatus=fail"
target="_blank"> Click here!</a>
> The following are new failures, please fix them before merging the PR:
<ol>
> <li>cypress/e2e/Regression/ServerSide/GenerateCRUD/MySQL2_Spec.ts
</ol>
> To know the list of identified flaky tests - <a
href="https://internal.appsmith.com/app/cypress-dashboard/identified-flaky-tests-65890b3c81d7400d08fa9ee3?branch=master"
target="_blank">Refer here</a>

<!-- end of auto-generated comment: Cypress test results  -->







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

## Summary by CodeRabbit

- **New Features**
- Enhanced URL building capabilities to support additional view options
in the app.
- Improved widget selection process to facilitate easier addition and
manipulation of widgets on the canvas.

- **Refactor**
- Updated selection logic to include a new `Create` selection type,
streamlining the process of adding new widgets.

- **Chores**
- Internal updates to support the new selection type across different
components and sagas.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-03-15 14:57:06 +05:30

214 lines
4.9 KiB
TypeScript

import {
ADD_PATH,
ADMIN_SETTINGS_PATH,
GEN_TEMPLATE_FORM_ROUTE,
GEN_TEMPLATE_URL,
getViewerCustomPath,
getViewerPath,
TEMPLATES_PATH,
} from "constants/routes";
import { APP_MODE } from "entities/App";
import urlBuilder from "@appsmith/entities/URLRedirect/URLAssembly";
import type { URLBuilderParams } from "@appsmith/entities/URLRedirect/URLAssembly";
import type {
ApplicationPayload,
Page,
} from "@appsmith/constants/ReduxActionConstants";
export const fillPathname = (
pathname: string,
application: ApplicationPayload,
page: Page,
) => {
const replaceValue = page.customSlug
? getViewerCustomPath(page.customSlug, page.pageId)
: getViewerPath(application.slug, page.slug, page.pageId);
return pathname.replace(
`/applications/${application.id}/pages/${page.pageId}`,
replaceValue,
);
};
export const datasourcesEditorURL = (props: URLBuilderParams): string =>
urlBuilder.build({
...props,
suffix: "datasource",
});
export const datasourcesEditorIdURL = (
props: URLBuilderParams & {
datasourceId: string;
},
): string => {
return urlBuilder.build({
...props,
suffix: `datasource/${props.datasourceId}`,
});
};
export interface WithAddView {
add?: boolean;
}
export const jsCollectionIdURL = (
props: URLBuilderParams &
WithAddView & {
collectionId: string;
// Pass a function name to set the cursor directly on the function
functionName?: string;
},
): string => {
return urlBuilder.build({
...props,
suffix: `jsObjects/${props.collectionId}${props.add ? ADD_PATH : ""}`,
hash: props.functionName,
});
};
export const integrationEditorURL = (
props: URLBuilderParams & { selectedTab: string },
): string => {
const suffixPath = props.suffix ? `/${props.suffix}` : "";
return urlBuilder.build({
...props,
suffix: `datasources/${props.selectedTab}${suffixPath}`,
});
};
export const queryEditorIdURL = (
props: URLBuilderParams &
WithAddView & {
queryId: string;
},
): string =>
urlBuilder.build({
...props,
suffix: `queries/${props.queryId}${props.add ? ADD_PATH : ""}`,
});
export const apiEditorIdURL = (
props: URLBuilderParams &
WithAddView & {
apiId: string;
},
): string =>
urlBuilder.build({
...props,
suffix: `api/${props.apiId}${props.add ? ADD_PATH : ""}`,
});
export const curlImportPageURL = (props: URLBuilderParams): string =>
urlBuilder.build({
...props,
suffix: "api/curl/curl-import",
});
export const saasEditorDatasourceIdURL = (
props: URLBuilderParams & {
pluginPackageName: string;
datasourceId: string;
},
): string =>
urlBuilder.build({
...props,
suffix: `saas/${props.pluginPackageName}/datasources/${props.datasourceId}`,
});
export const saasEditorApiIdURL = (
props: URLBuilderParams &
WithAddView & {
pluginPackageName: string;
apiId: string;
},
): string =>
urlBuilder.build({
...props,
suffix: `saas/${props.pluginPackageName}/api/${props.apiId}${
props.add ? ADD_PATH : ""
}`,
});
export const generateTemplateFormURL = (props: URLBuilderParams): string =>
urlBuilder.build({
...props,
suffix: `${GEN_TEMPLATE_URL}${GEN_TEMPLATE_FORM_ROUTE}`,
});
export const onboardingCheckListUrl = (props: URLBuilderParams): string =>
urlBuilder.build({
...props,
suffix: "checklist",
});
export const builderURL = (props: URLBuilderParams): string => {
return urlBuilder.build(props);
};
export const globalAddURL = (props: URLBuilderParams): string => {
return urlBuilder.build({
...props,
suffix: "add",
});
};
export const widgetURL = (
props: URLBuilderParams & WithAddView & { selectedWidgets: string[] },
) => {
return urlBuilder.build({
...props,
suffix: `widgets/${props.selectedWidgets.join(",")}${
props.add ? ADD_PATH : ""
}`,
});
};
export const widgetListURL = (props: URLBuilderParams) => {
return urlBuilder.build({
...props,
suffix: `widgets`,
});
};
export const viewerURL = (props: URLBuilderParams): string => {
return urlBuilder.build(props, APP_MODE.PUBLISHED);
};
export function adminSettingsCategoryUrl({
category,
selected,
}: {
category: string;
selected?: string;
}) {
return `${ADMIN_SETTINGS_PATH}/${category}${selected ? "/" + selected : ""}`;
}
export const templateIdUrl = ({ id }: { id: string }): string =>
`${TEMPLATES_PATH}/${id}`;
export const jsCollectionListURL = (props: URLBuilderParams): string => {
return urlBuilder.build({
...props,
suffix: `jsObjects`,
});
};
export const jsCollectionAddURL = (props: URLBuilderParams): string => {
return urlBuilder.build({
...props,
suffix: "jsObjects/add",
});
};
export const queryListURL = (props: URLBuilderParams): string =>
urlBuilder.build({
...props,
suffix: `queries`,
});
export const queryAddURL = (props: URLBuilderParams): string =>
urlBuilder.build({
...props,
suffix: `queries/add`,
});