2021-08-09 15:27:13 +00:00
|
|
|
import { stringifyQs } from "@saleor/utils/urls";
|
2020-07-22 10:54:15 +00:00
|
|
|
import urlJoin from "url-join";
|
|
|
|
|
|
|
|
import { ActiveTab, Dialog, Pagination, SingleAction } from "../types";
|
|
|
|
|
|
|
|
export const MANIFEST_ATTR = "manifestUrl";
|
|
|
|
|
2022-05-31 15:18:15 +00:00
|
|
|
export type AppListUrlDialog =
|
|
|
|
| "remove"
|
|
|
|
| "remove-app"
|
|
|
|
| "remove-custom-app"
|
|
|
|
| "app-activate"
|
|
|
|
| "app-deactivate";
|
2020-07-22 10:54:15 +00:00
|
|
|
|
|
|
|
export type AppDetailsUrlDialog = "app-activate" | "app-deactivate";
|
|
|
|
|
|
|
|
export type AppListUrlQueryParams = ActiveTab &
|
|
|
|
Dialog<AppListUrlDialog> &
|
|
|
|
SingleAction &
|
|
|
|
Pagination;
|
|
|
|
|
|
|
|
export type AppDetailsUrlQueryParams = Dialog<AppDetailsUrlDialog> &
|
|
|
|
SingleAction;
|
|
|
|
|
|
|
|
export type AppInstallUrlQueryParams = Partial<{ [MANIFEST_ATTR]: string }>;
|
|
|
|
|
|
|
|
export enum AppListUrlSortField {
|
|
|
|
name = "name",
|
|
|
|
active = "active"
|
|
|
|
}
|
|
|
|
|
|
|
|
export type CustomAppUrlDialog =
|
|
|
|
| "create-token"
|
|
|
|
| "remove-webhook"
|
2021-04-26 07:49:55 +00:00
|
|
|
| "remove-token"
|
|
|
|
| "app-activate"
|
|
|
|
| "app-deactivate";
|
2020-07-22 10:54:15 +00:00
|
|
|
export type CustomAppUrlQueryParams = Dialog<CustomAppUrlDialog> & SingleAction;
|
|
|
|
|
|
|
|
export const appsSection = "/apps/";
|
|
|
|
export const appsListPath = appsSection;
|
|
|
|
|
|
|
|
export const customAppListPath = "/apps/custom/";
|
|
|
|
|
2022-02-02 15:30:34 +00:00
|
|
|
export const appDetailsPath = (id: string) => urlJoin(appsSection, id);
|
2020-07-22 10:54:15 +00:00
|
|
|
export const appSettingsPath = (id: string) =>
|
|
|
|
urlJoin(appsSection, id, "settings");
|
2022-02-02 15:30:34 +00:00
|
|
|
export const appPath = (id: string) => urlJoin(appsSection, id, "app");
|
|
|
|
export const appDeepPath = (id: string, subPath: string) =>
|
|
|
|
urlJoin(appPath(id), subPath);
|
2020-07-22 10:54:15 +00:00
|
|
|
export const customAppPath = (id: string) => urlJoin(customAppListPath, id);
|
|
|
|
export const appInstallPath = urlJoin(appsSection, "install");
|
|
|
|
export const appInstallUrl = appInstallPath;
|
|
|
|
|
2022-02-02 15:30:34 +00:00
|
|
|
export const appDetailsUrl = (id: string, params?: AppDetailsUrlQueryParams) =>
|
|
|
|
appDetailsPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
2020-07-22 10:54:15 +00:00
|
|
|
|
2022-02-02 15:30:34 +00:00
|
|
|
export const appUrl = (id: string, params?: AppDetailsUrlQueryParams) =>
|
|
|
|
appPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
|
|
|
export const appDeepUrl = (
|
|
|
|
id: string,
|
|
|
|
subPath: string,
|
|
|
|
params?: AppDetailsUrlQueryParams
|
|
|
|
) => appDeepPath(encodeURIComponent(id), subPath) + "?" + stringifyQs(params);
|
|
|
|
|
|
|
|
export const getAppCompleteUrlFromDashboardUrl = (
|
|
|
|
dashboardUrl: string,
|
|
|
|
appUrl?: string,
|
|
|
|
appId?: string
|
|
|
|
) => {
|
|
|
|
if (!appUrl || !appId) {
|
|
|
|
return appUrl;
|
|
|
|
}
|
|
|
|
const deepSubPath = dashboardUrl.replace(
|
|
|
|
appPath(encodeURIComponent(appId)),
|
|
|
|
""
|
|
|
|
);
|
|
|
|
const appCompleteUrl = urlJoin(appUrl, deepSubPath);
|
|
|
|
return appCompleteUrl;
|
|
|
|
};
|
|
|
|
export const getDashboardUrFromAppCompleteUrl = (
|
|
|
|
appCompleteUrl: string,
|
|
|
|
appUrl?: string,
|
|
|
|
appId?: string
|
|
|
|
) => {
|
|
|
|
if (!appUrl || !appId) {
|
|
|
|
return appUrl;
|
|
|
|
}
|
|
|
|
const deepSubPath = appCompleteUrl.replace(appUrl, "");
|
|
|
|
const dashboardUrl = urlJoin(appPath(encodeURIComponent(appId)), deepSubPath);
|
|
|
|
return dashboardUrl;
|
|
|
|
};
|
2020-07-22 10:54:15 +00:00
|
|
|
|
|
|
|
export const customAppUrl = (id: string, params?: CustomAppUrlQueryParams) =>
|
|
|
|
customAppPath(encodeURIComponent(id)) + "?" + stringifyQs(params);
|
|
|
|
export const customAppAddPath = urlJoin(customAppListPath, "add");
|
|
|
|
export const customAppAddUrl = customAppAddPath;
|
|
|
|
|
|
|
|
export const appsListUrl = (params?: AppListUrlQueryParams) =>
|
|
|
|
appsListPath + "?" + stringifyQs(params);
|