-
-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add functionality for updating sections dynamically #542
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #542 +/- ##
==========================================
- Coverage 99.19% 99.18% -0.02%
==========================================
Files 115 115
Lines 1986 2076 +90
Branches 519 511 -8
==========================================
+ Hits 1970 2059 +89
- Misses 14 15 +1
Partials 2 2 ☔ View full report in Codecov by Sentry. |
src/hooks/useFormLayout.ts
Outdated
onChangeSections([...sections, ...currentSectionsToAdd]); | ||
} | ||
}, | ||
[onChangeSections, options, sections] |
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.
Please don't use state values as hook dependency which is used in custom code. It might cause infinity loops.
Options and sections should be removed from dependency list.
Use ref value or setState callback instead.
src/hooks/useFormLayout.ts
Outdated
*/ | ||
const addSections = useCallback( | ||
(newSections: LayoutSection[]) => { | ||
if (options) { |
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.
do we need to check options here?
src/utils/code-parameters.ts
Outdated
@@ -172,6 +188,22 @@ export const elementValueChangedCodeParameters = new CodeParametersBuilder({ | |||
CodeEditorSuggestionItemKind.Method | |||
), | |||
sectionsExpandedState: new CodeParameterItem<Record<string, boolean>>('Sections Expanded State'), | |||
addSections: new CodeParameterItem<(sections: LayoutSection[]) => void>( |
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.
I would change sections helpers to simplify working with them for end users.
- Add Section and already assign elements for it
const elements = []; // create and save elements;
.addSection({ name: '1', elements: [element1.id] });
.addSection({ name: '2', elements: [element2.id] });
- Get Section By Name - returns section object with elements
- Remove From section
removeFromSection(section.id, [element1.id]);
- Remove section
- Add to section
addToSection(section.id, [element1.id])
In addition, I would create an object with all helpers for sections like sectionsHelper: { add, get, getAll, update, assign, unassign, remove }
Resolves: #523