Create PageLayoutTab resolver and controller (#14284)

Closes https://github.com/twentyhq/core-team-issues/issues/1394
This commit is contained in:
Raphaël Bosi
2025-09-04 18:07:33 +02:00
committed by GitHub
parent 0f806126ac
commit 9746c3a787
38 changed files with 2241 additions and 32 deletions
@@ -5,13 +5,13 @@ import { type CreatePageLayoutInput } from 'src/engine/core-modules/page-layout/
type CreatePageLayoutOperationFactoryParams = {
gqlFields?: string;
data?: CreatePageLayoutInput;
data: CreatePageLayoutInput;
};
export const createPageLayoutOperationFactory = ({
gqlFields = PAGE_LAYOUT_GQL_FIELDS,
data = {} as CreatePageLayoutInput,
}: CreatePageLayoutOperationFactoryParams = {}) => ({
data,
}: CreatePageLayoutOperationFactoryParams) => ({
query: gql`
mutation CreatePageLayout($input: CreatePageLayoutInput!) {
createPageLayout(input: $input) {
@@ -0,0 +1,25 @@
import gql from 'graphql-tag';
import { PAGE_LAYOUT_TAB_GQL_FIELDS } from 'test/integration/constants/page-layout-gql-fields.constants';
import { type CreatePageLayoutTabInput } from 'src/engine/core-modules/page-layout/dtos/inputs/create-page-layout-tab.input';
type CreatePageLayoutTabOperationFactoryParams = {
gqlFields?: string;
data: CreatePageLayoutTabInput;
};
export const createPageLayoutTabOperationFactory = ({
gqlFields = PAGE_LAYOUT_TAB_GQL_FIELDS,
data,
}: CreatePageLayoutTabOperationFactoryParams) => ({
query: gql`
mutation CreatePageLayoutTab($input: CreatePageLayoutTabInput!) {
createPageLayoutTab(input: $input) {
${gqlFields}
}
}
`,
variables: {
input: data,
},
});
@@ -0,0 +1,18 @@
import gql from 'graphql-tag';
type DeletePageLayoutTabOperationFactoryParams = {
pageLayoutTabId: string;
};
export const deletePageLayoutTabOperationFactory = ({
pageLayoutTabId,
}: DeletePageLayoutTabOperationFactoryParams) => ({
query: gql`
mutation DeletePageLayoutTab($id: String!) {
deletePageLayoutTab(id: $id)
}
`,
variables: {
id: pageLayoutTabId,
},
});
@@ -0,0 +1,18 @@
import gql from 'graphql-tag';
type DestroyPageLayoutTabOperationFactoryParams = {
pageLayoutTabId: string;
};
export const destroyPageLayoutTabOperationFactory = ({
pageLayoutTabId,
}: DestroyPageLayoutTabOperationFactoryParams) => ({
query: gql`
mutation DestroyPageLayoutTab($id: String!) {
destroyPageLayoutTab(id: $id)
}
`,
variables: {
id: pageLayoutTabId,
},
});
@@ -0,0 +1,23 @@
import gql from 'graphql-tag';
import { PAGE_LAYOUT_TAB_GQL_FIELDS } from 'test/integration/constants/page-layout-gql-fields.constants';
type FindPageLayoutTabOperationFactoryParams = {
gqlFields?: string;
pageLayoutTabId: string;
};
export const findPageLayoutTabOperationFactory = ({
gqlFields = PAGE_LAYOUT_TAB_GQL_FIELDS,
pageLayoutTabId,
}: FindPageLayoutTabOperationFactoryParams) => ({
query: gql`
query GetPageLayoutTab($id: String!) {
getPageLayoutTab(id: $id) {
${gqlFields}
}
}
`,
variables: {
id: pageLayoutTabId,
},
});
@@ -0,0 +1,23 @@
import gql from 'graphql-tag';
import { PAGE_LAYOUT_TAB_GQL_FIELDS } from 'test/integration/constants/page-layout-gql-fields.constants';
type FindPageLayoutTabsOperationFactoryParams = {
gqlFields?: string;
pageLayoutId: string;
};
export const findPageLayoutTabsOperationFactory = ({
gqlFields = PAGE_LAYOUT_TAB_GQL_FIELDS,
pageLayoutId,
}: FindPageLayoutTabsOperationFactoryParams) => ({
query: gql`
query GetPageLayoutTabs($pageLayoutId: String!) {
getPageLayoutTabs(pageLayoutId: $pageLayoutId) {
${gqlFields}
}
}
`,
variables: {
pageLayoutId,
},
});
@@ -0,0 +1,59 @@
import { type GraphQLResponse } from 'test/integration/graphql/utils/graphql-test-assertions.util';
import { makeGraphqlAPIRequest } from 'test/integration/graphql/utils/make-graphql-api-request.util';
import { type PageLayoutTabEntity } from 'src/engine/core-modules/page-layout/entities/page-layout-tab.entity';
import { createPageLayoutTabOperationFactory } from './create-page-layout-tab-operation-factory.util';
import { destroyPageLayoutTabOperationFactory } from './destroy-page-layout-tab-operation-factory.util';
import { findPageLayoutTabsOperationFactory } from './find-page-layout-tabs-operation-factory.util';
interface CreatePageLayoutTabResponse extends Record<string, unknown> {
createPageLayoutTab: PageLayoutTabEntity;
}
export const createTestPageLayoutTabWithGraphQL = async (data: {
title: string;
position?: number;
pageLayoutId: string;
}): Promise<PageLayoutTabEntity> => {
const operation = createPageLayoutTabOperationFactory({
data: {
title: data.title,
position: data.position || 0,
pageLayoutId: data.pageLayoutId,
},
});
const response = (await makeGraphqlAPIRequest(
operation,
)) as GraphQLResponse<CreatePageLayoutTabResponse>;
if (response.body.errors) {
throw new Error(
`Failed to create test page layout tab: ${JSON.stringify(response.body.errors)}`,
);
}
if (!response.body.data) {
throw new Error('No data returned from createTestPageLayoutTabWithGraphQL');
}
return response.body.data.createPageLayoutTab;
};
export const cleanupPageLayoutTabRecordsWithGraphQL = async (
pageLayoutId: string,
): Promise<void> => {
const operation = findPageLayoutTabsOperationFactory({ pageLayoutId });
const response = await makeGraphqlAPIRequest(operation);
if (response.body.data?.getPageLayoutTabs) {
for (const pageLayoutTab of response.body.data.getPageLayoutTabs) {
const destroyOperation = destroyPageLayoutTabOperationFactory({
pageLayoutTabId: pageLayoutTab.id,
});
await makeGraphqlAPIRequest(destroyOperation);
}
}
};
@@ -0,0 +1,23 @@
import gql from 'graphql-tag';
import { PAGE_LAYOUT_TAB_GQL_FIELDS } from 'test/integration/constants/page-layout-gql-fields.constants';
type RestorePageLayoutTabOperationFactoryParams = {
gqlFields?: string;
pageLayoutTabId: string;
};
export const restorePageLayoutTabOperationFactory = ({
gqlFields = PAGE_LAYOUT_TAB_GQL_FIELDS,
pageLayoutTabId,
}: RestorePageLayoutTabOperationFactoryParams) => ({
query: gql`
mutation RestorePageLayoutTab($id: String!) {
restorePageLayoutTab(id: $id) {
${gqlFields}
}
}
`,
variables: {
id: pageLayoutTabId,
},
});
@@ -6,13 +6,13 @@ import { type UpdatePageLayoutInput } from 'src/engine/core-modules/page-layout/
type UpdatePageLayoutOperationFactoryParams = {
gqlFields?: string;
pageLayoutId: string;
data?: UpdatePageLayoutInput;
data: UpdatePageLayoutInput;
};
export const updatePageLayoutOperationFactory = ({
gqlFields = PAGE_LAYOUT_GQL_FIELDS,
pageLayoutId,
data = {} as UpdatePageLayoutInput,
data,
}: UpdatePageLayoutOperationFactoryParams) => ({
query: gql`
mutation UpdatePageLayout($id: String!, $input: UpdatePageLayoutInput!) {
@@ -0,0 +1,28 @@
import gql from 'graphql-tag';
import { PAGE_LAYOUT_TAB_GQL_FIELDS } from 'test/integration/constants/page-layout-gql-fields.constants';
import { type UpdatePageLayoutTabInput } from 'src/engine/core-modules/page-layout/dtos/inputs/update-page-layout-tab.input';
type UpdatePageLayoutTabOperationFactoryParams = {
gqlFields?: string;
pageLayoutTabId: string;
data: UpdatePageLayoutTabInput;
};
export const updatePageLayoutTabOperationFactory = ({
gqlFields = PAGE_LAYOUT_TAB_GQL_FIELDS,
pageLayoutTabId,
data,
}: UpdatePageLayoutTabOperationFactoryParams) => ({
query: gql`
mutation UpdatePageLayoutTab($id: String!, $input: UpdatePageLayoutTabInput!) {
updatePageLayoutTab(id: $id, input: $input) {
${gqlFields}
}
}
`,
variables: {
id: pageLayoutTabId,
input: data,
},
});