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

Dynamically move items in QuestionnaireBuilder #2883

Merged
merged 10 commits into from
Sep 27, 2023

Conversation

jamestouri
Copy link
Contributor

@jamestouri jamestouri commented Sep 19, 2023

Would love some UI feedback as I'm thinking of ways to move some of the actions around

Screen.Recording.2023-09-22.at.2.07.09.PM.mov

@jamestouri jamestouri self-assigned this Sep 19, 2023
@vercel
Copy link

vercel bot commented Sep 19, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
medplum-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 27, 2023 1:08am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
medplum-www ⬜️ Ignored (Inspect) Visit Preview Sep 27, 2023 1:08am

@coveralls
Copy link

Coverage Status

coverage: 93.973% (-0.1%) from 94.079% when pulling baaf1c3 on james-builder-move-item into dd6d9dc on main.

@reshmakh reshmakh added this to the September 30, 2023 milestone Sep 19, 2023
@jamestouri jamestouri marked this pull request as ready for review September 20, 2023 00:19
@jamestouri jamestouri requested a review from a team as a code owner September 20, 2023 00:19
Copy link
Member

@codyebberson codyebberson left a comment

Choose a reason for hiding this comment

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

Thanks for taking a stab at this.

See comments about moving logic into ItemBuilder

Aesthetically, I like the icon choice. It's a little on the bold side. Maybe shrink the icons down ~25%, and make them a more subtle gray?

@@ -106,6 +129,18 @@ export function QuestionnaireBuilder(props: QuestionnaireBuilderProps): JSX.Elem
};
}, [defaultValue]);

function toggleItemOrder(itemToMove: QuestionnaireItem, direction: Direction): void {
Copy link
Member

Choose a reason for hiding this comment

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

If we move this from QuestionnaireBuilder into ItemBuilder, then I think you should be able to simplify the reorderItems method.

Currently, reorderItems recursively searches for the item to move. If you do it in ItemBuilder, I believe you should be able to use the array directly, similar to how we do it with addItem and removeItem

import { QuestionnaireFormItem } from '../QuestionnaireForm/QuestionnaireFormItem/QuestionnaireFormItem';

enum Direction {
UP,
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if this is useful here, but I've found that using delta with values 1 or -1 can be more elegant than direction enums. Then it becomes less if/else, and just math.

@@ -204,6 +230,15 @@ function ItemBuilder<T extends Questionnaire | QuestionnaireItem>(props: ItemBui
});
}

function toggleItemOrder(itemToMove: QuestionnaireItem, delta: number): void {
Copy link
Member

@codyebberson codyebberson Sep 26, 2023

Choose a reason for hiding this comment

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

It's not really a "toggle"... Maybe moveItem?

In this case, I think your code will end up cleaner if you accept the itemIndex rather than itemToMove. When passing in the QuestionnaireItem, you have to do an Array.find() which is O(n) lookup. You already have the item index on lines 295-296, so might as well use it directly.

items: QuestionnaireItem[] | undefined,
itemToMove: QuestionnaireItem,
delta: number
): QuestionnaireItem[] | null {
Copy link
Member

@codyebberson codyebberson Sep 26, 2023

Choose a reason for hiding this comment

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

We almost never return null from any of our methods, except in very rare circumstances. Usually we'd return undefined for a "nothing" result.

However, in this case, I think we should always return the QuestionnaireItem[] array. If the delta is invalid, then we can just return the original array. Fewer edges cases to worry about (you're already preventing this case by not including the buttons, and we're not checking for null return values at the call site).

As mentioned above, I think we should change itemToMove to itemIndex and pass in the numeric array index. That should avoid the findIndex call.

Then you can remove the index === -1 check.

const newIndex = itemIndex + delta;
if (newIndex < 0 || newIndex >= items.length) {
  return items;
}
...

@github-actions
Copy link

github-actions bot commented Sep 27, 2023

prettier errors have been resolved. Thank you.

#9be56607bb8c3a5ad76d25be14a6dda07fd0ba7d

@sonarcloud
Copy link

sonarcloud bot commented Sep 27, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

85.4% 85.4% Coverage
0.0% 0.0% Duplication

@reshmakh reshmakh added the questionnaires FHIR questionnaires related features and fixes label Sep 27, 2023
@codyebberson codyebberson added this pull request to the merge queue Sep 27, 2023
Merged via the queue into main with commit f983e71 Sep 27, 2023
12 checks passed
@codyebberson codyebberson deleted the james-builder-move-item branch September 27, 2023 21:55
codyebberson added a commit that referenced this pull request Sep 27, 2023
Fixes #2901 - cli command to update s3 bucket policies (#2924)
Bot cli fixes (#2935)
Dynamically move items in QuestionnaireBuilder (#2883)
publish changes (#2927)
Update contributing docs (#2897)
Fixes #2898 - export CDK types (#2905)
Update sweep.yaml (#2920)
Split tsquery handling by language config (#2885)
Add stack traces back to error logs (#2918)
Fixes #2899 - agent push (#2900)
Add request IDs to error responses (#2907)
Create documentation for the Apps Tab (#2873)
Clarify that paginated search requires a _sort for consistency (#2913)
Added docs on the "Communication Lifecycle" (#2912)
Bump graphql from 16.8.0 to 16.8.1 (#2903)
Fixes #2891k - ID capitalization (#2902)
Add Value Set Autocomplete to Kitchen Sink (#2896)
Added reference resolution to  PATCH batch entries (#2884)
Fixes #2876 - CDK creates awsRegion parameter (#2879)
Bind async callbacks to context local storage (#2875)
Clarification on per-server vs. per-project users (#2881)
Fixes #2847 - Create new resources from JSON input (#2870)
Fixes ElementDefinition.contentReference in deep nested backbone element (#2868)
Bind AsyncLocalStorage to cursor callbacks (#2874)
Use getElementDefinitionTypeName (#2869)
Fix bug on page sequence input changes  (#2865)
Updating SOC2 report link to 2023 version (#2872)
Update Patient Dedupe Docs (#2760)
Fix CLI docs headings (#2867)
Monitoring bots documentation (#2782)
Updating bots based on feedback and correcting for use of deprecated fields (#2866)
Remove unnecessary generics (#2864)
Create docs for promoting a user to admin (#2757)
Fixes #2792 - multiple patient compartments in resource (#2862)
Fix 'sign-in' vs 'sign in' in invite email (#2861)
Fixes #2796 - copy binary content in project clone (#2858)
Dependency upgrades (#2857)
codyebberson added a commit that referenced this pull request Sep 28, 2023
Fixes #2901 - cli command to update s3 bucket policies (#2924)
Bot cli fixes (#2935)
Dynamically move items in QuestionnaireBuilder (#2883)
publish changes (#2927)
Update contributing docs (#2897)
Fixes #2898 - export CDK types (#2905)
Update sweep.yaml (#2920)
Split tsquery handling by language config (#2885)
Add stack traces back to error logs (#2918)
Fixes #2899 - agent push (#2900)
Add request IDs to error responses (#2907)
Create documentation for the Apps Tab (#2873)
Clarify that paginated search requires a _sort for consistency (#2913)
Added docs on the "Communication Lifecycle" (#2912)
Bump graphql from 16.8.0 to 16.8.1 (#2903)
Fixes #2891k - ID capitalization (#2902)
Add Value Set Autocomplete to Kitchen Sink (#2896)
Added reference resolution to  PATCH batch entries (#2884)
Fixes #2876 - CDK creates awsRegion parameter (#2879)
Bind async callbacks to context local storage (#2875)
Clarification on per-server vs. per-project users (#2881)
Fixes #2847 - Create new resources from JSON input (#2870)
Fixes ElementDefinition.contentReference in deep nested backbone element (#2868)
Bind AsyncLocalStorage to cursor callbacks (#2874)
Use getElementDefinitionTypeName (#2869)
Fix bug on page sequence input changes  (#2865)
Updating SOC2 report link to 2023 version (#2872)
Update Patient Dedupe Docs (#2760)
Fix CLI docs headings (#2867)
Monitoring bots documentation (#2782)
Updating bots based on feedback and correcting for use of deprecated fields (#2866)
Remove unnecessary generics (#2864)
Create docs for promoting a user to admin (#2757)
Fixes #2792 - multiple patient compartments in resource (#2862)
Fix 'sign-in' vs 'sign in' in invite email (#2861)
Fixes #2796 - copy binary content in project clone (#2858)
Dependency upgrades (#2857)
github-merge-queue bot pushed a commit that referenced this pull request Sep 28, 2023
Fixes #2901 - cli command to update s3 bucket policies (#2924)
Bot cli fixes (#2935)
Dynamically move items in QuestionnaireBuilder (#2883)
publish changes (#2927)
Update contributing docs (#2897)
Fixes #2898 - export CDK types (#2905)
Update sweep.yaml (#2920)
Split tsquery handling by language config (#2885)
Add stack traces back to error logs (#2918)
Fixes #2899 - agent push (#2900)
Add request IDs to error responses (#2907)
Create documentation for the Apps Tab (#2873)
Clarify that paginated search requires a _sort for consistency (#2913)
Added docs on the "Communication Lifecycle" (#2912)
Bump graphql from 16.8.0 to 16.8.1 (#2903)
Fixes #2891k - ID capitalization (#2902)
Add Value Set Autocomplete to Kitchen Sink (#2896)
Added reference resolution to  PATCH batch entries (#2884)
Fixes #2876 - CDK creates awsRegion parameter (#2879)
Bind async callbacks to context local storage (#2875)
Clarification on per-server vs. per-project users (#2881)
Fixes #2847 - Create new resources from JSON input (#2870)
Fixes ElementDefinition.contentReference in deep nested backbone element (#2868)
Bind AsyncLocalStorage to cursor callbacks (#2874)
Use getElementDefinitionTypeName (#2869)
Fix bug on page sequence input changes  (#2865)
Updating SOC2 report link to 2023 version (#2872)
Update Patient Dedupe Docs (#2760)
Fix CLI docs headings (#2867)
Monitoring bots documentation (#2782)
Updating bots based on feedback and correcting for use of deprecated fields (#2866)
Remove unnecessary generics (#2864)
Create docs for promoting a user to admin (#2757)
Fixes #2792 - multiple patient compartments in resource (#2862)
Fix 'sign-in' vs 'sign in' in invite email (#2861)
Fixes #2796 - copy binary content in project clone (#2858)
Dependency upgrades (#2857)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
questionnaires FHIR questionnaires related features and fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants