-
Notifications
You must be signed in to change notification settings - Fork 186
feat(protocol-designer): Update Shift-click step selection to work with concurrent Thermocycler profiles #20193
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7fc2b9d
Delete unused SELECT_MULTIPLE_STEPS_FOR_GROUP action.
SyntaxColoring 7a96626
Minor formatting cleanup in actions.ts.
SyntaxColoring f15e24f
Clarify parameter names.
SyntaxColoring 6dc6db5
Exclude hidden steps from Shift-selection.
SyntaxColoring bc684e9
Add test for getShiftSelectedSteps().
SyntaxColoring File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,8 +2,12 @@ import round from 'lodash/round' | |
| import uniq from 'lodash/uniq' | ||
| import { UAParser } from 'ua-parser-js' | ||
|
|
||
| import { getStepVisibilities } from '/protocol-designer/steplist/utils/getStepVisibilities' | ||
| import { convertStepHierarchyToArray } from '/protocol-designer/steplist/utils/stepHierarchy' | ||
|
|
||
| import type { MouseEvent } from 'react' | ||
| import type { StepIdType } from '/protocol-designer/form-types' | ||
| import type { StepHierarchy } from '/protocol-designer/steplist/utils/stepHierarchy' | ||
|
|
||
| export const capitalizeFirstLetterAfterNumber = (title: string): string => | ||
| title.replace( | ||
|
|
@@ -36,84 +40,98 @@ export const formatPercentage = (part: number, total: number): string => { | |
| } | ||
|
|
||
| export const getMetaSelectedSteps = ( | ||
| multiSelectItemIds: StepIdType[] | null, | ||
| stepId: StepIdType, | ||
| selectedStepId: StepIdType | null | ||
| priorMultiSelectedItemIds: StepIdType[] | null, | ||
| newlySelectedStepId: StepIdType, | ||
| priorSingleSelectedStepId: StepIdType | null | ||
| ): StepIdType[] => { | ||
| let stepsToSelect: StepIdType[] | ||
| if (multiSelectItemIds?.length) { | ||
| if (priorMultiSelectedItemIds?.length) { | ||
| // already have a selection, add/remove the meta-clicked item | ||
| stepsToSelect = multiSelectItemIds.includes(stepId) | ||
| ? multiSelectItemIds.filter(id => id !== stepId) | ||
| : [...multiSelectItemIds, stepId] | ||
| } else if (selectedStepId && selectedStepId === stepId) { | ||
| stepsToSelect = priorMultiSelectedItemIds.includes(newlySelectedStepId) | ||
| ? priorMultiSelectedItemIds.filter(id => id !== newlySelectedStepId) | ||
| : [...priorMultiSelectedItemIds, newlySelectedStepId] | ||
| } else if ( | ||
| priorSingleSelectedStepId && | ||
| priorSingleSelectedStepId === newlySelectedStepId | ||
| ) { | ||
| // meta-clicked on the selected single step | ||
| stepsToSelect = [selectedStepId] | ||
| } else if (selectedStepId) { | ||
| stepsToSelect = [priorSingleSelectedStepId] | ||
| } else if (priorSingleSelectedStepId) { | ||
| // meta-clicked on a different step, multi-select both | ||
| stepsToSelect = [selectedStepId, stepId] | ||
| stepsToSelect = [priorSingleSelectedStepId, newlySelectedStepId] | ||
| } else { | ||
| // meta-clicked on a step when a terminal item was selected | ||
| stepsToSelect = [stepId] | ||
| stepsToSelect = [newlySelectedStepId] | ||
| } | ||
| return stepsToSelect | ||
| } | ||
|
|
||
| export const getShiftSelectedSteps = ( | ||
| selectedStepId: StepIdType | null, | ||
| orderedStepIds: StepIdType[], | ||
| stepId: StepIdType, | ||
| multiSelectItemIds: StepIdType[] | null, | ||
| priorSingleSelectedStepId: StepIdType | null, | ||
| stepHierarchy: StepHierarchy, | ||
| newlySelectedStepId: StepIdType, | ||
| priorMultiSelectedItemIds: StepIdType[] | null, | ||
| lastMultiSelectedStepId: StepIdType | null | ||
| ): StepIdType[] => { | ||
| let stepsToSelect: StepIdType[] | ||
| if (selectedStepId) { | ||
| stepsToSelect = getOrderedStepsInRange( | ||
| selectedStepId, | ||
| stepId, | ||
| orderedStepIds | ||
| if (priorSingleSelectedStepId) { | ||
| stepsToSelect = getOrderedVisibleStepsInRange( | ||
| priorSingleSelectedStepId, | ||
| newlySelectedStepId, | ||
| stepHierarchy | ||
| ) | ||
| } else if (multiSelectItemIds?.length && lastMultiSelectedStepId) { | ||
| const potentialStepsToSelect = getOrderedStepsInRange( | ||
| } else if (priorMultiSelectedItemIds?.length && lastMultiSelectedStepId) { | ||
| const potentialStepsToSelect = getOrderedVisibleStepsInRange( | ||
| lastMultiSelectedStepId, | ||
| stepId, | ||
| orderedStepIds | ||
| newlySelectedStepId, | ||
| stepHierarchy | ||
| ) | ||
|
|
||
| const allSelected: boolean = potentialStepsToSelect | ||
| .slice(1) | ||
| .every(stepId => multiSelectItemIds.includes(stepId)) | ||
| .every(stepId => priorMultiSelectedItemIds.includes(stepId)) | ||
|
|
||
| if (allSelected) { | ||
| // if they're all selected, deselect them all | ||
| if (multiSelectItemIds.length - potentialStepsToSelect.length > 0) { | ||
| stepsToSelect = multiSelectItemIds.filter( | ||
| if ( | ||
| priorMultiSelectedItemIds.length - potentialStepsToSelect.length > | ||
| 0 | ||
| ) { | ||
| stepsToSelect = priorMultiSelectedItemIds.filter( | ||
| (id: StepIdType) => !potentialStepsToSelect.includes(id) | ||
| ) | ||
| } else { | ||
| // unless deselecting them all results in none being selected | ||
| stepsToSelect = [potentialStepsToSelect[0]] | ||
| } | ||
| } else { | ||
| stepsToSelect = uniq([...multiSelectItemIds, ...potentialStepsToSelect]) | ||
| stepsToSelect = uniq([ | ||
| ...priorMultiSelectedItemIds, | ||
| ...potentialStepsToSelect, | ||
| ]) | ||
| } | ||
| } else { | ||
| stepsToSelect = [stepId] | ||
| stepsToSelect = [newlySelectedStepId] | ||
| } | ||
| return stepsToSelect | ||
| } | ||
|
|
||
| const getOrderedStepsInRange = ( | ||
| const getOrderedVisibleStepsInRange = ( | ||
| lastSelectedStepId: StepIdType, | ||
| stepId: StepIdType, | ||
| orderedStepIds: StepIdType[] | ||
| stepHierarchy: StepHierarchy | ||
| ): StepIdType[] => { | ||
| const orderedStepIds = convertStepHierarchyToArray(stepHierarchy) | ||
| const stepVisibilities = getStepVisibilities(stepHierarchy) | ||
|
|
||
| const prevIndex: number = orderedStepIds.indexOf(lastSelectedStepId) | ||
| const currentIndex: number = orderedStepIds.indexOf(stepId) | ||
|
|
||
| const [startIndex, endIndex] = [prevIndex, currentIndex].sort((a, b) => a - b) | ||
| const orderedSteps = orderedStepIds.slice(startIndex, endIndex + 1) | ||
| return orderedSteps | ||
|
|
||
| const orderedVisibleSteps = orderedStepIds | ||
| .slice(startIndex, endIndex + 1) | ||
| .filter(stepId => stepVisibilities[stepId].isVisibleToUser) | ||
| return orderedVisibleSteps | ||
|
Comment on lines
+131
to
+134
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This new |
||
| } | ||
|
|
||
| export const nonePressed = (keysPressed: boolean[]): boolean => | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
No behavioral changes in
getMetaSelectedSteps(), just renaming parameters for clarity.