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

Eliminate the need to provide index in DragAndDrop #11252

Merged
merged 2 commits into from
Oct 2, 2023

Conversation

TomasEng
Copy link
Contributor

@TomasEng TomasEng commented Sep 28, 2023

Description

Now, consumers have to provide an index to the DragAndDrop items, like this:

<DragAndDrop.List>
    <DragAndDrop.ListItem index={0}/>
    <DragAndDrop.ListItem index={1}/>
    <DragAndDrop.ListItem index={2}/>
    ...
</DragAndDrop.List>

Providing the wrong index will lead to buggy behaviour, so this is not ideal. This pull request introduces a findPositionInList function that is used to find the correct index from within the component using the DOM model. It is only called when the user drags something, so there should not be any risk of it being called before the DOM is fully rendered.

In order to avoid selector collisions, I have also added a useDomSelectors hook that generates unique ids and class names that are used by findPositionInList.

Verification

@github-actions github-actions bot added area/ui-editor Area: Related to the designer tool for assembling app UI in Altinn Studio. solution/studio/designer Issues related to the Altinn Studio Designer solution. labels Sep 28, 2023
@codecov
Copy link

codecov bot commented Sep 28, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (0a2cc67) 80.85% compared to head (85be382) 80.92%.
Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11252      +/-   ##
==========================================
+ Coverage   80.85%   80.92%   +0.06%     
==========================================
  Files         751      753       +2     
  Lines       11940    11982      +42     
  Branches     1597     1598       +1     
==========================================
+ Hits         9654     9696      +42     
  Misses       2038     2038              
  Partials      248      248              
Files Coverage Δ
...ts/dragAndDrop/DragAndDropList/DragAndDropList.tsx 81.81% <100.00%> (+1.81%) ⬆️
.../DragAndDropListItem/DragAndDropListItemContext.ts 100.00% <100.00%> (ø)
...ndDrop/DragAndDropProvider/DragAndDropProvider.tsx 100.00% <100.00%> (ø)
...Drop/DragAndDropProvider/DragAndDropRootContext.ts 100.00% <ø> (ø)
...rc/components/dragAndDrop/hooks/useDomSelectors.ts 100.00% <100.00%> (ø)
...hared/src/components/dragAndDrop/utils/domUtils.ts 100.00% <100.00%> (ø)
...d/packages/ux-editor/src/containers/DesignView.tsx 88.23% <ø> (ø)
...ndDrop/DragAndDropListItem/DragAndDropListItem.tsx 78.94% <85.71%> (+1.80%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@framitdavid framitdavid left a comment

Choose a reason for hiding this comment

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

LGTM!👏 🎖️

@TomasEng TomasEng marked this pull request as ready for review September 29, 2023 13:09
@TomasEng TomasEng merged commit 9d35dbf into master Oct 2, 2023
@TomasEng TomasEng deleted the fix/draganddrop/eliminate-index branch October 2, 2023 06:15
nkylstad added a commit that referenced this pull request Oct 12, 2023
* Add titles and helpTexts to components (#11263)

* remove unused import & update test

* Apply suggestions from code review

Co-authored-by: andreastanderen <71079896+standeren@users.noreply.github.com>

* Make varaiblename- and variable-usage in cypress tests consistent (#11243)

* Make varaiblename- and variable-usage in cypress tests consistent

* Removed unused value in local cypress config file

* Use same usernames for dev and prod test users as before

* Use same usernames for staging test users as before

* remove invalid properties (#11257)

* remove invalid properties

* use correct property name in test

* Base successfully added expression on the expression property (#11250)

* Base successfully added expression on the property

* Eliminate the need to provide index in DragAndDrop (#11252)

* 11177 move sidegrupper to dropdownselect (#11245)

* Added dropdown list in left menu

* Replace LegacyCheckbox with Switch (#11244)

* Replace LegacyCheckbox with Switch

* Fix Switch errors

* Remove duplicate labels

* Replace LegacyCheckbox with Switch

* refactor: use context class (#11264)

* Context classes added

* Used context class in AppDevelopmentController

* Rename context generator method

* use context class in datamodelign controller

* use new context class in process modelling

* Add cancellation tokens

* format

* Delete unused methods from RepositorySI

* remove unused methods

* More unused methods

* repositorySi more unused

* Some repositorySi mehods migrated to use context

* CodeQl fix

* Add preview column (#11240)

* Update nb.json (#11268)

Fix typo

* Drag and drop tree view (#11270)

* updated tests

* added text resource binding

* merge issues

* sorting keys

* fix test

---------

Co-authored-by: andreastanderen <71079896+standeren@users.noreply.github.com>
Co-authored-by: Tomas Engebretsen <tomas.engebretsen@digdir.no>
Co-authored-by: JamalAlabdullah <90609090+JamalAlabdullah@users.noreply.github.com>
Co-authored-by: Michael Queyrichon <michael.queyrichon@digdir.no>
Co-authored-by: Mirko Sekulic <misha.sekulic@gmail.com>
Co-authored-by: andreas-didriksen <75472603+andreas-didriksen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/ui-editor Area: Related to the designer tool for assembling app UI in Altinn Studio. solution/studio/designer Issues related to the Altinn Studio Designer solution.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants