-
Notifications
You must be signed in to change notification settings - Fork 348
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
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
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.
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 { |
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.
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, |
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'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 { |
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.
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 { |
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.
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;
}
...
✅ |
Kudos, SonarCloud Quality Gate passed! |
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)
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)
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)
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