Skip to content
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

Form Builder - Move backend to HCMS #3645

Open
wants to merge 47 commits into
base: next
Choose a base branch
from

Conversation

neatbyte-vnobis
Copy link
Collaborator

@neatbyte-vnobis neatbyte-vnobis commented Oct 27, 2023

Changes

Form Methods moved to HCMS:

  • createForm
  • getForm
  • listFormRevisions
  • listForms
  • createFormFrom
  • deleteForm
  • deleteFormRevision
  • publishForm
  • unpublishForm
  • updateForm

Submission Methods moved to HCMS:

  • listSubmissions
  • createSubmission
  • updateSubmission

Skipped Submission Methods: deleteSubmission, getSubmission. They were skipped because they are not used anywhere.

How Has This Been Tested?

Manually.

Documentation

Form Builder - Move backend to HCMS

@neatbyte-vnobis neatbyte-vnobis changed the title Form Builder - Move backend to HCMS [WIP] Form Builder - Move backend to HCMS Nov 8, 2023
@neatbyte-ivelychko
Copy link

@adrians5j, @SvenAlHamad what should we do about these bugs?

While working on this feature we have found bug that exists for a long time.

  1. When we have a form that has ONLY one revision and after deleting that revision we would see that the form that should have been deleted still being displayed in UI in the list of the forms. But after reloading the page it would not be rendered in the list of forms. I think that happens becuase of caching. Furthemore this bug doesn not appear if we delete a form instead of revision.
2023-11-08.16.36.41.mov
  1. When have created a form submission, opened Submissions tab in Form Builder and clicked on reload submissions we would see that the list of submissions has been updated.
    But Overview stats on the Submissions tab are still the same, so they has not been updated. To see a most recent data for Overview we would need to reload the page.
Знімок екрана 2023-11-08 о 17 17 50
  1. When we choose a form revision that we had chosen previously then that revision won't be re-rendered in the Page Builder Editor Form and it would render the latest chosen revision.
2023-11-08.17.19.49.mov

Copy link
Contributor

@leopuleo leopuleo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @neatbyte-vnobis and @neatbyte-ivelychko for this Pull Request.

You will find many comments below; most are repetitive, and many others address tiny issues.

There are a couple of issues we need to address before merging:

  • we want to keep the original imported method createFormBuilder. TLDR: we don't want to upgrade some part of user projects.
  • we want to keep the GraphQL schema unchanged: some field types have been changed, some of them are not required anymore and vice-versa. Use the API playground in the admin app to confront the newly generated schema with the previous one.

apps/api/graphql/src/index.ts Outdated Show resolved Hide resolved
packages/api-form-builder/src/types.ts Outdated Show resolved Hide resolved
packages/api-form-builder/src/types.ts Show resolved Hide resolved
packages/api-headless-cms/src/crud/contentEntry.crud.ts Outdated Show resolved Hide resolved
@neatbyte-vnobis neatbyte-vnobis force-pushed the neatbyte/form-builder-hcms branch 4 times, most recently from 824dfdf to eb371aa Compare November 23, 2023 09:58
@neatbyte-vnobis
Copy link
Collaborator Author

@adrians5j @leopuleo As we're removing the revision selection for forms in the Page Builder, I assume we should now only display forms with a published revision in the form select. Should we create a new listPublishedForms API endpoint for this, or modify the existing listForms with an additional parameter? I think a separate endpoint would be preferable, as it would utilize listPublishedEntries instead of listLatestEntries.

Additionally, considering we now have only one published revision, should we rename getLatestPublishedFormRevision to getPublishedFormRevision?

@adrians5j @leopuleo Any thoughts on this?

@neatbyte-vnobis
Copy link
Collaborator Author

@adrians5j While updating tests following the recent status updates, I noticed that this test fails. The test involves publishing a form revision and then incrementing its views. However, with our current use of published HCMS entries, we cannot update them. This is because the current implementation of HCMS includes a check to see if an entry is locked before updating, and it is set to true when an entry is published. So we cannot update already published form - which is a breaking change compared to old API and FB logic.

What should our approach be in this case? Could we consider making some changes to HCMS to address this issue? (option to override the locked status or something like this)

@neatbyte-vnobis
Copy link
Collaborator Author

@adrians5j While updating tests following the recent status updates, I noticed that this test fails. The test involves publishing a form revision and then incrementing its views. However, with our current use of published HCMS entries, we cannot update them. This is because the current implementation of HCMS includes a check to see if an entry is locked before updating, and it is set to true when an entry is published. So we cannot update already published form - which is a breaking change compared to old API and FB logic.

What should our approach be in this case? Could we consider making some changes to HCMS to address this issue? (option to override the locked status or something like this)

@adrians5j @Pavel910 Any thoughts on this?

@adrians5j
Copy link
Member

We're still discussing this internally. We'll get back to you re this soon.

Copy link
Contributor

@leopuleo leopuleo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neatbyte-vnobis, we are almost there 💪.

I highlighted some minor changes, plus while testing the admin app, I noticed a couple of bugs:

  1. App Form Builder: While trying to create a new version from a previous one, it always keeps the configuration from the latest version instead of the selected one.
  2. App Page Builder: The application crashes while trying to insert a form on a page. It looks like an error on the getPublishedForm query. See the video here below:
CleanShot.2023-12-14.at.07.44.54.mp4

@@ -341,7 +336,7 @@ export const createFormsCrud = (params: CreateFormsCrudParams): FormsCRUD => {

if (!original) {
throw new NotFoundError(`Form "${id}" was not found!`);
} else if (original.locked) {
} else if (original.status === "unpublished") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's create a FORM_STATUS enum: you can import this enum from api-headless-cms package and re-export it.

i.e.

if (original.status === CONTENT_ENTRY_STATUS.UNPUBLISHED) {
  ...
}

@@ -69,7 +69,7 @@ export const createSubmissionsSchema = (params: CreateSubmissionsTypeDefsParams)
* Get all revisions of the form.
*/
const revisions = await formBuilder.getFormRevisions(form);
const publishedRevisions = revisions.filter(r => r.published);
const publishedRevisions = revisions.filter(r => r.status === "published");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's create a FORM_STATUS enum: you can import this enum from api-headless-cms package and re-export it.

@@ -92,7 +92,7 @@ export const Name = () => {
<NameWrapper>
<FormMeta>
<Typography use={"overline"}>{`status: ${
state.data.published ? t`published` : t`draft`
state.data.status === "published" ? t`published` : t`draft`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's create an enum with the possible status.

@@ -37,7 +37,7 @@ const revisionsMenu = css({

const getIcon = (revision: Pick<FbFormModel, "status">) => {
switch (revision.status) {
case "locked":
case "unpublished":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, let's use an enum with the possible status.

@@ -138,7 +138,7 @@ const FormsDataList = (props: FormsDataListProps) => {
const handlerKey = form.id + form.status;
if (!editHandlers.current[handlerKey]) {
editHandlers.current[handlerKey] = async () => {
if (!form.published) {
if (form.status !== "published") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, let's use an enum with the possible status.

@m0nikaza m0nikaza added this to the 5.39.0 milestone Jan 9, 2024
@adrians5j adrians5j modified the milestones: 5.39.0, 5.40.0 Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants