Skip to content

Form Builder - Move backend to HCMS #3645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 47 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
c08f095
feat: moved createForm, listForms into HCMS
neatbyte-vnobis Oct 27, 2023
02af88f
feat: moved submission methods, revision methods, deleteForm into HCMS
neatbyte-vnobis Nov 1, 2023
be28245
fix: fixed build errors
neatbyte-vnobis Nov 1, 2023
8144935
feat: added locked form model field
neatbyte-vnobis Nov 1, 2023
44f7f10
feat: moved deleteFormRevision into HCMS
neatbyte-vnobis Nov 1, 2023
9eba393
fix: removed unused form builder context methods
neatbyte-vnobis Nov 1, 2023
63714c9
feat: add updateForm, dynamic schema for submissions
neatbyte-vnobis Nov 3, 2023
cb042fb
feat: moved publishRevision, unpublishRevision into HCMS, dynamic sch…
neatbyte-vnobis Nov 3, 2023
9c04f9b
fix: imports/exports, refactor cms storages
neatbyte-vnobis Nov 7, 2023
1d4a590
fix: fix ddb packages types
neatbyte-vnobis Nov 7, 2023
96f0783
fix: fix dependencies
neatbyte-vnobis Nov 7, 2023
59d07f6
fix: fixed api-form-builder tests
neatbyte-vnobis Nov 7, 2023
37603f3
fix: fixed api-audit-logs tests
neatbyte-vnobis Nov 8, 2023
6e6360c
fix: add interface implementation to CmsSubmissionsStorage class
neatbyte-vnobis Nov 8, 2023
eb371aa
feat: moved deleteSubmission and getSubmission into HCMS
neatbyte-vnobis Nov 8, 2023
9b203f2
Merge branch 'next' into neatbyte/form-builder-hcms
neatbyte-vnobis Nov 23, 2023
f8747c1
fix: implemented requested changes
neatbyte-vnobis Nov 23, 2023
dd4e2b2
fix: fixed issue with packages
neatbyte-vnobis Nov 23, 2023
725f673
fix: merged with next, resolved conflicts and type issues
neatbyte-vnobis Nov 27, 2023
600d9a2
Merge branch 'next' into neatbyte/form-builder-hcms
neatbyte-vnobis Nov 28, 2023
989f4e5
fix: fixed issue with settings model validation
neatbyte-vnobis Nov 28, 2023
d1549c9
Merge branch 'next' into neatbyte/form-builder-hcms
neatbyte-vnobis Nov 30, 2023
a987ff7
fix: fix tests
neatbyte-vnobis Nov 30, 2023
bc629bc
fix: revert back cwp-template-aws changes
neatbyte-vnobis Dec 1, 2023
b4de07c
fix: revert back api-headless-cms publishedOn changes
neatbyte-vnobis Dec 6, 2023
0192677
Merge branch 'next' into neatbyte/form-builder-hcms
leopuleo Dec 7, 2023
bd01907
Merge branch 'next' into neatbyte/form-builder-hcms
neatbyte-vnobis Dec 11, 2023
0033d87
fix: use entry publish status
neatbyte-vnobis Dec 11, 2023
f3da9b1
fix: requested changes and add test
neatbyte-vnobis Dec 14, 2023
6c5da6f
fix: remove reCaptcha settings fields from form entry
leopuleo Jan 9, 2024
cca3b82
fix: change Recaptcha error message field type
leopuleo Jan 10, 2024
03ad21f
Merge branch 'next' into neatbyte/form-builder-hcms
leopuleo Jan 24, 2024
2d51809
chore: merge next
leopuleo Jan 24, 2024
5f45544
test: fix ownedBy
leopuleo Jan 24, 2024
ce03eef
Merge branch 'next' into neatbyte/form-builder-hcms
leopuleo Jan 25, 2024
be376e2
chore: merge next
leopuleo Feb 5, 2024
32f071f
chore: update deps
leopuleo Feb 5, 2024
91e745c
fix: re-introduce getPublishedFormRevisionById crud operation
leopuleo Feb 13, 2024
1c24102
fix: re-introduce form parent and revision in form renderer
leopuleo Feb 13, 2024
cd35575
fix: fetch id instead of formId
leopuleo Feb 13, 2024
0064543
fix: remove version from getPublishedFormRevisionById
leopuleo Feb 13, 2024
929b9fe
refactor(api-form-builder): form statistics (#3780)
neatbyte-vnobis Feb 14, 2024
6c92b20
fix: remove ownedBy where param
leopuleo Feb 14, 2024
2ea2052
fix: revisions tests
leopuleo Feb 14, 2024
3c3ef69
Merge branch 'next' into neatbyte/form-builder-hcms
leopuleo Feb 14, 2024
01bccb0
chore: merge next
leopuleo Feb 14, 2024
e5e2160
Merge branch 'next' into neatbyte/form-builder-hcms
leopuleo Feb 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ describe("Forms Submission Security Test", () => {
createdOn: expect.stringMatching(/^20/),
savedOn: expect.stringMatching(/^20/),
fields: [],
locked: false,
published: false,
publishedOn: null,
name: "A1-name",
overallStats: {
Expand Down Expand Up @@ -194,9 +192,7 @@ describe("Forms Submission Security Test", () => {
}
],
status: "published",
published: true,
publishedOn: expect.stringMatching(/^20/),
locked: true
publishedOn: expect.stringMatching(/^20/)
},
error: null
}
Expand Down
14 changes: 4 additions & 10 deletions packages/api-form-builder/__tests__/forms.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,15 @@ describe('Form Builder "Form" Test', () => {
await publishRevision({ revision: id });

// Get the published form
const [{ data: get }] = await getPublishedForm({ revision: id });
const [{ data: get }] = await getPublishedForm({ formId: id });
expect(get.formBuilder.getPublishedForm.data.id).toEqual(id);

// Create a new revision
const [create2] = await createRevisionFrom({ revision: id });
const { id: id2 } = create2.data.formBuilder.createRevisionFrom.data;

// Latest published form should still be #1
const [latestPublished] = await getPublishedForm({ parent: id.split("#")[0] });
const [latestPublished] = await getPublishedForm({ formId: id.split("#")[0] });
expect(latestPublished.data.formBuilder.getPublishedForm.data.id).toEqual(id);

// Latest revision should be #2
Expand All @@ -284,7 +284,7 @@ describe('Form Builder "Form" Test', () => {
await publishRevision({ revision: id2 });

// Latest published form should now be #2
const [latestPublished2] = await getPublishedForm({ parent: id.split("#")[0] });
const [latestPublished2] = await getPublishedForm({ formId: id.split("#")[0] });
expect(latestPublished2.data.formBuilder.getPublishedForm.data.id).toEqual(id2);

// Increment views for #2
Expand All @@ -302,7 +302,7 @@ describe('Form Builder "Form" Test', () => {
await unpublishRevision({ revision: id2 });

// Latest published form should now again be #1
const [latestPublished3] = await getPublishedForm({ parent: id.split("#")[0] });
const [latestPublished3] = await getPublishedForm({ formId: id.split("#")[0] });
expect(latestPublished3.data.formBuilder.getPublishedForm.data.id).toEqual(id);
});

Expand Down Expand Up @@ -470,7 +470,6 @@ describe('Form Builder "Form" Test', () => {
publishRevision: {
data: {
name: "form 2",
published: true,
stats: {
submissions: 0,
views: 0
Expand All @@ -496,7 +495,6 @@ describe('Form Builder "Form" Test', () => {
data: {
id: `${form2.formId}#0002`,
version: 2,
published: false,
status: "draft"
},
error: null
Expand Down Expand Up @@ -530,7 +528,6 @@ describe('Form Builder "Form" Test', () => {
publishRevision: {
data: {
name: "form 1",
published: true,
stats: {
submissions: 0,
views: 0
Expand All @@ -556,7 +553,6 @@ describe('Form Builder "Form" Test', () => {
data: {
id: `${form1.formId}#0002`,
version: 2,
published: false,
status: "draft"
},
error: null
Expand All @@ -576,7 +572,6 @@ describe('Form Builder "Form" Test', () => {
publishRevision: {
data: {
name: "form 1",
published: true,
stats: {
submissions: 0,
views: 0
Expand All @@ -599,7 +594,6 @@ describe('Form Builder "Form" Test', () => {
data: {
id: `${form1.formId}#0003`,
version: 3,
published: false,
status: "draft"
},
error: null
Expand Down
14 changes: 2 additions & 12 deletions packages/api-form-builder/__tests__/formsSecurity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class MockResponse {
public readonly createdOn: RegExp;
public readonly savedOn: RegExp;
public readonly publishedOn: RegExp | null;
public readonly locked: boolean;
public readonly published: boolean;
public readonly status: "published" | "draft";
public readonly version: number;

Expand All @@ -26,8 +24,6 @@ class MockResponse {
this.createdOn = /^20/;
this.savedOn = /^20/;
this.publishedOn = null;
this.locked = false;
this.published = false;
this.status = "draft";
this.version = 1;
}
Expand Down Expand Up @@ -438,9 +434,7 @@ describe("Forms Security Test", () => {
id: formId
}),
publishedOn: /^20/,
published: true,
status: "published",
locked: true
status: "published"
},
error: null
}
Expand Down Expand Up @@ -470,9 +464,7 @@ describe("Forms Security Test", () => {
id: formId
}),
publishedOn: /^20/,
published: true,
status: "published",
locked: true
status: "published"
},
error: null
}
Expand Down Expand Up @@ -540,9 +532,7 @@ describe("Forms Security Test", () => {
id
}),
publishedOn: /^20/,
published: true,
status: "published",
locked: true,
version: i + 2
},
error: null
Expand Down
8 changes: 2 additions & 6 deletions packages/api-form-builder/__tests__/graphql/forms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ export const FORM_DATA_FIELD = /* GraphQL */ `
}
}
triggers
published
locked
status
stats {
views
Expand Down Expand Up @@ -58,10 +56,8 @@ export const FORMS_DATA_FIELD = /* GraphQL */ `
savedOn
name
slug
published
publishedOn
version
locked
status
createdBy {
id
Expand Down Expand Up @@ -190,9 +186,9 @@ export const GET_FORM_REVISIONS = /* GraphQL */ `
`;

export const GET_PUBLISHED_FORM = /* GraphQL */ `
query GetPublishedForm($revision: ID, $parent: ID) {
query GetPublishedForm($formId: ID) {
formBuilder {
getPublishedForm(revision: $revision, parent: $parent) {
getPublishedForm(formId: $formId) {
data ${FORM_DATA_FIELD}
error ${ERROR_FIELD}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CmsEntry, CmsEntryValues, CmsModel, HeadlessCms } from "@webiny/api-headless-cms/types";
import { CmsEntry, CmsModel, HeadlessCms } from "@webiny/api-headless-cms/types";
import WebinyError from "@webiny/error";
import { Security } from "@webiny/api-security/types";
import { createIdentifier, parseIdentifier } from "@webiny/utils";
Expand Down Expand Up @@ -43,17 +43,6 @@ export class CmsFormsStorage implements FormBuilderFormStorageOperations {
return { ...this.model, tenant, locale };
}

private async getSortedFormRevisions(
model: CmsModel,
formId: string
): Promise<CmsEntry<CmsEntryValues>> {
const entries = (await this.cms.getEntryRevisions(model, formId))
.filter(entryItem => entryItem.values.published)
.sort((a, b) => b.version - a.version);

return entries[0];
}

async getForm(params: FormBuilderStorageOperationsGetFormParams): Promise<FbForm | null> {
const {
id,
Expand All @@ -75,7 +64,7 @@ export class CmsFormsStorage implements FormBuilderFormStorageOperations {

return entry;
} else if (published && !version) {
const entry = await this.getSortedFormRevisions(model, formId);
const [entry] = await this.cms.getPublishedEntriesByIds(model, [formId]);

return entry;
} else if (id || version) {
Expand Down Expand Up @@ -116,9 +105,6 @@ export class CmsFormsStorage implements FormBuilderFormStorageOperations {

const entry = await this.security.withoutAuthorization(async () => {
return await this.cms.createEntryRevisionFrom(model, form.id, {
status: "draft",
published: false,
locked: false,
stats: {
submissions: 0,
views: 0
Expand Down Expand Up @@ -198,7 +184,7 @@ export class CmsFormsStorage implements FormBuilderFormStorageOperations {
const model = this.modelWithContext(form);

const entry = await this.security.withoutAuthorization(async () => {
return await this.cms.updateEntry(model, form.id, form);
return await this.cms.publishEntry(model, form.id);
});

return this.getFormFieldValues(entry);
Expand All @@ -209,7 +195,7 @@ export class CmsFormsStorage implements FormBuilderFormStorageOperations {
const model = this.modelWithContext(form);

const entry = await this.security.withoutAuthorization(async () => {
return await this.cms.updateEntry(model, form.id, form);
return await this.cms.unpublishEntry(model, form.id);
});

return this.getFormFieldValues(entry);
Expand All @@ -222,6 +208,7 @@ export class CmsFormsStorage implements FormBuilderFormStorageOperations {
createdOn: entry.createdOn,
savedOn: entry.savedOn,
publishedOn: entry.publishedOn,
status: entry.status,
locale: entry.locale,
tenant: entry.tenant,
webinyVersion: entry.webinyVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,6 @@ const nameField = () => {
});
};

const publishedField = () => {
return createModelField({
label: "Published",
type: "boolean",
validation: [required()]
});
};

const statusField = () => {
return createModelField({
label: "Status",
type: "text",
validation: [required()]
});
};

const statsViewsField = () => {
return createModelField({
label: "Views",
Expand Down Expand Up @@ -86,15 +70,6 @@ const overallStatsField = (fields: CmsModelField[]) => {
});
};

const lockedField = () => {
return createModelField({
label: "Locked",
fieldId: "locked",
type: "boolean",
validation: [required()]
});
};

const field_IdField = () => {
return createModelField({
label: "ID",
Expand Down Expand Up @@ -413,16 +388,12 @@ const slugField = () => {
const DEFAULT_FIELDS = [
"formId",
"name",
"published",
"status",
"stats",
"overallStats",
"locked",
"fields",
"steps",
"settings",
"triggers",
"publishedOn",
"slug"
];

Expand Down Expand Up @@ -475,8 +446,6 @@ export const createFormDataModelDefinition = (group: CmsModelGroup): CmsPrivateM
fields: [
formIdField(),
nameField(),
publishedField(),
statusField(),
statsField([
statsViewsField(),
statsSubmissionsField(),
Expand All @@ -487,7 +456,6 @@ export const createFormDataModelDefinition = (group: CmsModelGroup): CmsPrivateM
statsSubmissionsField(),
conversionRateStatsSubmissionsField()
]),
lockedField(),
fieldsField(FIELD_FIELDS),
stepsField(STEP_FIELDS),
settingsField(SETTINGS_FIELDS),
Expand Down
Loading