-
Notifications
You must be signed in to change notification settings - Fork 620
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
Conversation
@adrians5j |
@adrians5j I don't know whether it is okay that property https://github.com/webiny/webiny-js/blob/next/packages/app-form-builder/src/types.ts#L195 |
packages/app-form-builder/src/admin/components/FormEditor/Tabs/EditTab/FormStep/FormStep.tsx
Outdated
Show resolved
Hide resolved
a5d10c7
to
1b8aaf6
Compare
I think I would try to update it. |
packages/app-form-builder/src/admin/components/FormEditor/Tabs/EditTab/FormStep/FormStep.tsx
Outdated
Show resolved
Hide resolved
eb55a5c
to
ef7b3b7
Compare
packages/app-form-builder/src/admin/components/FormEditor/Context/useFormEditorFactory.tsx
Outdated
Show resolved
Hide resolved
@adrians5j could you please review this pr? |
There was a problem hiding this 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.
packages/app-form-builder/src/admin/components/FormEditor/Tabs/EditTab/FormStep/FormStep.tsx
Outdated
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Tabs/EditTab/EditTab.tsx
Outdated
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Droppable.tsx
Outdated
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Draggable.tsx
Outdated
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Context/functions/moveStep.ts
Outdated
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Context/functions/moveStep.ts
Outdated
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Context/functions/moveStep.ts
Outdated
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Context/functions/moveRowBetween.ts
Outdated
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Context/functions/moveRow.ts
Outdated
Show resolved
Hide resolved
@adrians5j Hi, I have made all of the requested changes. Could you please take a look? |
packages/app-form-builder/src/admin/components/FormEditor/Tabs/EditTab/FormStep/FormStep.tsx
Outdated
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Tabs/EditTab/FormStep/FormStep.tsx
Outdated
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Tabs/EditTab/EditTab.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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.
packages/app-form-builder/src/admin/components/FormEditor/Context/useFormEditorFactory.tsx
Outdated
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Tabs/EditTab/FormStep/FormStep.tsx
Outdated
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Tabs/EditTab/FormStep/useFormStep.ts
Outdated
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Tabs/EditTab/Styled.ts
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Context/useFormEditorFactory.tsx
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Tabs/EditTab/FormStep.tsx
Outdated
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Tabs/EditTab/EditTab.tsx
Outdated
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Tabs/EditTab/EditTab.tsx
Outdated
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Tabs/EditTab/EditTab.tsx
Outdated
Show resolved
Hide resolved
Hm, okay, just so you're unblocked.
But, I'd still see why this is happening. It's probably just a missing
dependency in the array. Can you double check?
If no luck, then yeah, feel free to proceed.
…On Wed, 13 Dec 2023 at 12:31, Illya Velychko ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In
packages/app-form-builder/src/admin/components/FormEditor/Tabs/EditTab/EditTab.tsx
<#3574 (comment)>:
> };
// This function will render drop zones on the top of the step,
// if steps are locatted above "source" ("source" step is the step that we move).
- const renderTopDropZone = (sourceStepId: string | undefined, targetStepId: string) => {
- if (!sourceStepId) {
+ const renderTopDropZone = (item: IsVisibleCallableParams, targetStepId: string) => {
@adrians5j <https://github.com/adrians5j>
Also I have noticed that if we add a useCallback or useMemo methods from
useFormStep stops working properly.
For instance moveRow does not work properly, it would only move one field
and delete another field instead of moving an entire row into another step.
And it is only one of many bugs that occurs after using useCallback.
And I just want to know whether it is okay that we would not use
useCallback and useMemo?
—
Reply to this email directly, view it on GitHub
<#3574 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABHCI7FVGSFZN7CYOWVYES3YJGGZTAVCNFSM6AAAAAA5SJ3ER2VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMYTONZZGQZTIMZVGY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
--
Adrian S.
|
1454c85
to
cd4b300
Compare
I've refactored EditTab, and fixed issues with useCallback. |
...er/src/admin/components/FormEditor/Tabs/EditTab/FormStep/FormStepContext/FormStepContext.tsx
Outdated
Show resolved
Hide resolved
...der/src/admin/components/FormEditor/Tabs/EditTab/FormStep/FormStepWithFields/FormStepRow.tsx
Outdated
Show resolved
Hide resolved
.../app-form-builder/src/admin/components/FormEditor/Tabs/EditTab/EditFieldDialog/useEditTab.ts
Outdated
Show resolved
Hide resolved
.../app-form-builder/src/admin/components/FormEditor/Tabs/EditTab/EditFieldDialog/useEditTab.ts
Outdated
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Droppable.tsx
Outdated
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Droppable.tsx
Outdated
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Draggable.tsx
Outdated
Show resolved
Hide resolved
packages/app-form-builder/src/admin/components/FormEditor/Context/useFormEditorFactory.tsx
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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: { |
There was a problem hiding this comment.
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: { |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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
?
// Contains info about the Container, | ||
// in which we are dropping an element or elements. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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. |
// Property "id" is optional, | ||
// because when we move row it does not have an id. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(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"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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"; |
There was a problem hiding this comment.
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"; |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// This function will render drop zones on the top of the step, | |
// This function will render drop zones on the bottom of the step, |
@adrians5j fixed latest comments |
There was a problem hiding this 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"; |
There was a problem hiding this comment.
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
?
/cypress |
Cypress E2E tests have been initiated (for more information, click here). ✨ |
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