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

feat: Refactor onDrop for Multi Step Form #3574

Merged
merged 26 commits into from
Dec 21, 2023

Conversation

neatbyte-vnobis
Copy link
Collaborator

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

Changes

Refactored the onDrop function for Fields, Rows and Condition Groups.

How Has This Been Tested?

Manually

Documentation

https://www.notion.so/Proposal-to-refactor-the-onDrop-function-for-Fields-Rows-and-Condition-Groups-a3c3604f42d4495eb4bc9f5f4774dfdf

@neatbyte-ivelychko
Copy link

@adrians5j
The refactor of onDrop for Multi Step Form is done.
Could you please review it?

@neatbyte-ivelychko
Copy link

@adrians5j I don't know whether it is okay that property _id of form field can be undefined.
Because if we want to pass that prop in some functions we would need to add extra check whether that id exists, and it is kinda strange. Or it a desired behaviour of _id property?

Знімок екрана 2023-10-05 о 13 27 47

https://github.com/webiny/webiny-js/blob/next/packages/app-form-builder/src/types.ts#L195

@neatbyte-vnobis neatbyte-vnobis changed the base branch from next to neatbyte/multi-step-form-rules-condition-group October 10, 2023 14:41
@neatbyte-vnobis neatbyte-vnobis changed the base branch from neatbyte/multi-step-form-rules-condition-group to next October 10, 2023 14:44
@neatbyte-vnobis neatbyte-vnobis changed the base branch from next to neatbyte/multi-step-form-rules-condition-group October 12, 2023 08:29
@neatbyte-vnobis neatbyte-vnobis changed the base branch from neatbyte/multi-step-form-rules-condition-group to next October 12, 2023 08:30
@neatbyte-vnobis neatbyte-vnobis force-pushed the neatbyte/multi-step-form-drag-n-drop branch from a5d10c7 to 1b8aaf6 Compare October 12, 2023 08:30
@adrians5j adrians5j self-assigned this Oct 18, 2023
@adrians5j
Copy link
Member

Re ?_id, I think it makes sense to have it as a required field. Especially because on the GQL level, I can see it's non-nullable:
image

If you want, we can try updating this and see if anything breaks.

@neatbyte-ivelychko
Copy link

neatbyte-ivelychko commented Oct 18, 2023

If you want, we can try updating this and see if anything breaks.

I think I would try to update it.

@neatbyte-vnobis neatbyte-vnobis force-pushed the neatbyte/multi-step-form-drag-n-drop branch from eb55a5c to ef7b3b7 Compare October 19, 2023 08:31
@neatbyte-ivelychko
Copy link

@adrians5j could you please review this pr?

Copy link
Member

@adrians5j adrians5j left a comment

Choose a reason for hiding this comment

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

Initial review done. Didn't go over the whole PR, but it's a good start I'd say.

BTW I applaud the comments 👏🏻 . I just added a couple of directions.

P.S. I added two commits.

@neatbyte-ivelychko
Copy link

@adrians5j Hi, I have made all of the requested changes. Could you please take a look?

Copy link
Member

@adrians5j adrians5j left a comment

Choose a reason for hiding this comment

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

Did some changes, left some comments.

Please check it out when you get a chance.

@adrians5j
Copy link
Member

adrians5j commented Dec 13, 2023 via email

@neatbyte-vnobis neatbyte-vnobis force-pushed the neatbyte/multi-step-form-drag-n-drop branch 2 times, most recently from 1454c85 to cd4b300 Compare December 13, 2023 14:07
@neatbyte-ivelychko
Copy link

@adrians5j

I've refactored EditTab, and fixed issues with useCallback.
Could you please review it again?

Copy link
Member

@adrians5j adrians5j left a comment

Choose a reason for hiding this comment

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

Almost there!

export interface MoveStepParams {
target: {
containerId: string;
position: {
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to use DropTarget here?

@@ -112,6 +145,19 @@ export interface FbFormStep {
layout: FbFormModelFieldsLayout;
}

export interface MoveStepParams {
target: {
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to rename this to source, the same way we have it above?


export interface DropSource {
// Contains info about the Container from which we are dragging an element or elements.
// containerId and containerType could be null in case we are creating a custom field.
Copy link
Member

Choose a reason for hiding this comment

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

Says here containerId and containerType can be null, but type doesn't reflect that. Maybe you meant undefined?

Comment on lines 40 to 41
// Contains info about the Container,
// in which we are dropping an element or elements.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Contains info about the Container,
// in which we are dropping an element or elements.
// Contains info about the Container into which we are dropping one or more elements.

Comment on lines 17 to 18
// Property "id" is optional,
// because when we move row it does not have an id.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Property "id" is optional,
// because when we move row it does not have an id.
// Property "id" is optional because when we move row it does not have an `id`.

}, []);

const onFormStepDrop = useCallback(
(params: HandleDropParams) => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
(params: HandleDropParams) => {
(params: OnFormStepDropParams) => {

Also, does it make sense to to maybe just undo the name change here to handleDrop since we don't have the original one anymore?

@@ -20,29 +20,34 @@ export interface DroppableCollectedProps {
isOver: boolean;
}

export type DroppableUIElements = "row" | "field" | "conditionGroup" | "step";
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
export type DroppableUIElements = "row" | "field" | "conditionGroup" | "step";
export type DraggableUIElement = "row" | "field" | "conditionGroup" | "step";

Notice the singular instead of plural.

P.S. At this point, ui name of the prop does sound ambiguous, but let's leave it as is for now (I'm aware if was like this before you started working on this).

id?: string;
pos: FieldLayoutPositionType;
container?: {
type: "step" | "conditionGroup";
Copy link
Member

Choose a reason for hiding this comment

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

Let's also have a type for this, e.g. ContainerType.

id?: string;
// "container" contains info about source element.
container?: {
type: "step" | "conditionGroup";
Copy link
Member

Choose a reason for hiding this comment

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

Again a use case where we could use a type that could live in types.ts file. Let's do that and also make sure to use the type in packages/app-form-builder/src/admin/components/FormEditor/Droppable.tsx.

[data]
);

// This function will render drop zones on the top of the step,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// This function will render drop zones on the top of the step,
// This function will render drop zones on the bottom of the step,

@neatbyte-ivelychko
Copy link

@adrians5j fixed latest comments

Copy link
Member

@adrians5j adrians5j left a comment

Choose a reason for hiding this comment

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

One question.

@@ -11,6 +11,44 @@ import {
import { ApolloClient } from "apollo-client";
import { SecurityPermission } from "@webiny/app-security/types";

export type DropTargetType = "field" | "row" | "conditionGroup" | "step";
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to use this instead of DroppableUIElement in packages/app-form-builder/src/admin/components/FormEditor/Droppable.tsx:23 ?

@adrians5j
Copy link
Member

/cypress

Copy link

Cypress E2E tests have been initiated (for more information, click here). ✨

@adrians5j adrians5j merged commit 7f8da60 into next Dec 21, 2023
78 checks passed
@adrians5j adrians5j deleted the neatbyte/multi-step-form-drag-n-drop branch April 5, 2024 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants