2023-11-02 10:25:24 +00:00
|
|
|
import type {
|
|
|
|
|
ApplicationPayload,
|
|
|
|
|
Page,
|
|
|
|
|
ReduxAction,
|
|
|
|
|
} from "@appsmith/constants/ReduxActionConstants";
|
|
|
|
|
import { ReduxActionTypes } from "@appsmith/constants/ReduxActionConstants";
|
|
|
|
|
import type { UpdatePageResponse } from "api/PageApi";
|
|
|
|
|
import type {
|
|
|
|
|
ApplicationURLParams,
|
|
|
|
|
PageURLParams,
|
|
|
|
|
} from "@appsmith/entities/URLRedirect/URLAssembly";
|
|
|
|
|
import urlBuilder from "@appsmith/entities/URLRedirect/URLAssembly";
|
|
|
|
|
import type { Middleware } from "redux";
|
|
|
|
|
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2023-11-02 10:25:24 +00:00
|
|
|
export const handler = (action: ReduxAction<any>) => {
|
|
|
|
|
let appParams: ApplicationURLParams = {};
|
|
|
|
|
let pageParams: PageURLParams[] = [];
|
2024-01-26 08:46:26 +00:00
|
|
|
switch (action?.type) {
|
2023-11-02 10:25:24 +00:00
|
|
|
case ReduxActionTypes.IMPORT_APPLICATION_SUCCESS:
|
|
|
|
|
case ReduxActionTypes.IMPORT_TEMPLATE_TO_WORKSPACE_SUCCESS:
|
|
|
|
|
case ReduxActionTypes.FETCH_APPLICATION_SUCCESS: {
|
|
|
|
|
const application: ApplicationPayload = action.payload;
|
|
|
|
|
const { pages } = application;
|
|
|
|
|
appParams = {
|
2024-07-31 02:54:51 +00:00
|
|
|
baseApplicationId: application.baseId,
|
2023-11-02 10:25:24 +00:00
|
|
|
applicationSlug: application.slug,
|
|
|
|
|
applicationVersion: application.applicationVersion,
|
|
|
|
|
};
|
|
|
|
|
pageParams = pages.map((page) => ({
|
|
|
|
|
pageSlug: page.slug,
|
2024-07-31 02:54:51 +00:00
|
|
|
basePageId: page.baseId,
|
2023-11-02 10:25:24 +00:00
|
|
|
customSlug: page.customSlug,
|
|
|
|
|
}));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ReduxActionTypes.FORK_APPLICATION_SUCCESS:
|
|
|
|
|
case ReduxActionTypes.CREATE_APPLICATION_SUCCESS: {
|
|
|
|
|
const application: ApplicationPayload = action.payload.application;
|
|
|
|
|
const { pages } = application;
|
|
|
|
|
appParams = {
|
2024-07-31 02:54:51 +00:00
|
|
|
baseApplicationId: application.baseId,
|
2023-11-02 10:25:24 +00:00
|
|
|
applicationSlug: application.slug,
|
|
|
|
|
applicationVersion: application.applicationVersion,
|
|
|
|
|
};
|
|
|
|
|
pageParams = pages.map((page) => ({
|
|
|
|
|
pageSlug: page.slug,
|
2024-07-31 02:54:51 +00:00
|
|
|
basePageId: page.baseId,
|
2023-11-02 10:25:24 +00:00
|
|
|
customSlug: page.customSlug,
|
|
|
|
|
}));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ReduxActionTypes.CURRENT_APPLICATION_NAME_UPDATE: {
|
|
|
|
|
const application = action.payload;
|
|
|
|
|
appParams = {
|
2024-07-31 02:54:51 +00:00
|
|
|
baseApplicationId: application.baseId,
|
2023-11-02 10:25:24 +00:00
|
|
|
applicationSlug: application.slug,
|
|
|
|
|
applicationVersion: application.applicationVersion,
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ReduxActionTypes.FETCH_PAGE_LIST_SUCCESS: {
|
|
|
|
|
const pages: Page[] = action.payload.pages;
|
|
|
|
|
pageParams = pages.map((page) => ({
|
|
|
|
|
pageSlug: page.slug,
|
2024-07-31 02:54:51 +00:00
|
|
|
basePageId: page.basePageId,
|
2023-11-02 10:25:24 +00:00
|
|
|
customSlug: page.customSlug,
|
|
|
|
|
}));
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ReduxActionTypes.UPDATE_PAGE_SUCCESS: {
|
|
|
|
|
const page: UpdatePageResponse = action.payload;
|
|
|
|
|
pageParams = [
|
|
|
|
|
{
|
|
|
|
|
pageSlug: page.slug,
|
2024-07-31 02:54:51 +00:00
|
|
|
basePageId: page.baseId,
|
2023-11-02 10:25:24 +00:00
|
|
|
customSlug: page.customSlug,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ReduxActionTypes.CREATE_PAGE_SUCCESS: {
|
|
|
|
|
const page: Page = action.payload;
|
|
|
|
|
pageParams = [
|
|
|
|
|
{
|
|
|
|
|
pageSlug: page.slug,
|
2024-07-31 02:54:51 +00:00
|
|
|
basePageId: page.basePageId,
|
2023-11-02 10:25:24 +00:00
|
|
|
customSlug: page.customSlug,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ReduxActionTypes.GENERATE_TEMPLATE_PAGE_SUCCESS: {
|
|
|
|
|
const { page } = action.payload;
|
|
|
|
|
urlBuilder.updateURLParams(null, [
|
|
|
|
|
{
|
|
|
|
|
pageSlug: page.slug,
|
2024-07-31 02:54:51 +00:00
|
|
|
basePageId: page.baseId,
|
2023-11-02 10:25:24 +00:00
|
|
|
customSlug: page.customSlug,
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case ReduxActionTypes.UPDATE_APPLICATION_SUCCESS:
|
|
|
|
|
const application = action.payload;
|
|
|
|
|
appParams = {
|
2024-07-31 02:54:51 +00:00
|
|
|
baseApplicationId: application.baseid,
|
2023-11-02 10:25:24 +00:00
|
|
|
applicationSlug: application.slug,
|
|
|
|
|
applicationVersion: application.applicationVersion,
|
|
|
|
|
};
|
|
|
|
|
break;
|
|
|
|
|
case ReduxActionTypes.CLONE_PAGE_SUCCESS:
|
2024-07-31 02:54:51 +00:00
|
|
|
const { basePageId, pageSlug } = action.payload;
|
2023-11-02 10:25:24 +00:00
|
|
|
pageParams = [
|
|
|
|
|
{
|
2024-07-31 02:54:51 +00:00
|
|
|
basePageId,
|
2023-11-02 10:25:24 +00:00
|
|
|
pageSlug,
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
urlBuilder.updateURLParams(appParams, pageParams);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const routeParamsMiddleware: Middleware =
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2023-11-02 10:25:24 +00:00
|
|
|
() => (next: any) => (action: ReduxAction<any>) => {
|
|
|
|
|
handler(action);
|
|
|
|
|
return next(action);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default routeParamsMiddleware;
|