-
Notifications
You must be signed in to change notification settings - Fork 29
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
Fix checkbox selection issues #1986
Changes from all commits
9e529ba
3afa2ae
7dfd915
c335c91
4aa3583
352e7fb
0605411
40c4f56
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,10 @@ const experimentMenuOption = ( | |
} as MessagesMenuOptionProps | ||
} | ||
|
||
const getMultiSelectMenuOptions = (selectedRowsList: RowProp[]) => { | ||
const getMultiSelectMenuOptions = ( | ||
selectedRowsList: RowProp[], | ||
hasRunningExperiment: boolean | ||
) => { | ||
const unstarredExperiments = selectedRowsList.filter( | ||
({ | ||
row: { | ||
|
@@ -67,7 +70,8 @@ const getMultiSelectMenuOptions = (selectedRowsList: RowProp[]) => { | |
.filter(value => value.row.depth === 1) | ||
.map(value => value.row.values.id) | ||
|
||
const hideRemoveOption = removableRowIds.length !== selectedRowsList.length | ||
const hideRemoveOption = | ||
removableRowIds.length !== selectedRowsList.length || hasRunningExperiment | ||
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. [C] IMO if one of the selected rows is removable we should offer the remove option and remove only the ones we can. |
||
|
||
const toggleStarOption = (ids: string[], label: string) => | ||
experimentMenuOption( | ||
|
@@ -92,6 +96,46 @@ const getMultiSelectMenuOptions = (selectedRowsList: RowProp[]) => { | |
MessageFromWebviewType.REMOVE_EXPERIMENT, | ||
hideRemoveOption, | ||
true | ||
), | ||
{ | ||
divider: true, | ||
id: 'clear-selection', | ||
keyboardShortcut: 'Esc', | ||
label: 'Clear row selection' | ||
} | ||
] | ||
} | ||
|
||
const getRunResumeOptions = ( | ||
withId: ( | ||
label: string, | ||
type: MessageFromWebviewType, | ||
hidden?: boolean, | ||
divider?: boolean | ||
) => MessagesMenuOptionProps, | ||
isWorkspace: boolean, | ||
projectHasCheckpoints: boolean, | ||
hideVaryAndRun: boolean, | ||
depth: number | ||
) => { | ||
const isNotCheckpoint = depth <= 1 || isWorkspace | ||
|
||
return [ | ||
withId( | ||
'Modify, Reset and Run', | ||
MessageFromWebviewType.VARY_EXPERIMENT_PARAMS_RESET_AND_RUN, | ||
!isNotCheckpoint || !projectHasCheckpoints | ||
), | ||
withId( | ||
projectHasCheckpoints ? 'Modify and Resume' : 'Modify and Run', | ||
MessageFromWebviewType.VARY_EXPERIMENT_PARAMS_AND_RUN, | ||
!isNotCheckpoint, | ||
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. [C] Might be easier to read if you change the condition to 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. try and simplify this boolean logic wherever you can, it is getting pretty difficult to understand at first glance. 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. I don't like it either, but I have a feeling this refactoring will take some time. I can tackle it in the next PR, if that's ok. |
||
!hideVaryAndRun | ||
), | ||
withId( | ||
'Modify and Queue', | ||
MessageFromWebviewType.VARY_EXPERIMENT_PARAMS_AND_QUEUE, | ||
!isNotCheckpoint | ||
) | ||
] | ||
} | ||
|
@@ -100,53 +144,51 @@ const getSingleSelectMenuOptions = ( | |
id: string, | ||
isWorkspace: boolean, | ||
projectHasCheckpoints: boolean, | ||
hasRunningExperiment: boolean, | ||
depth: number, | ||
queued?: boolean, | ||
starred?: boolean | ||
) => { | ||
const isNotCheckpoint = depth <= 1 || isWorkspace | ||
const canApplyOrCreateBranch = queued || isWorkspace || depth <= 0 | ||
const hideApplyAndCreateBranch = queued || isWorkspace || depth <= 0 | ||
|
||
const withId = ( | ||
label: string, | ||
type: MessageFromWebviewType, | ||
hidden?: boolean, | ||
divider?: boolean | ||
) => experimentMenuOption(id, label, type, hidden, divider) | ||
) => | ||
experimentMenuOption( | ||
id, | ||
label, | ||
type, | ||
hidden || hasRunningExperiment, | ||
divider | ||
) | ||
|
||
return [ | ||
withId( | ||
'Apply to Workspace', | ||
MessageFromWebviewType.APPLY_EXPERIMENT_TO_WORKSPACE, | ||
canApplyOrCreateBranch | ||
hideApplyAndCreateBranch | ||
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. [Q] The name would suggest the logic has been reversed here (but it looks like the same condition). Was the name wrong before and the logic correct or has something else happened? 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. Yes, because the property is called |
||
), | ||
withId( | ||
'Create new Branch', | ||
MessageFromWebviewType.CREATE_BRANCH_FROM_EXPERIMENT, | ||
canApplyOrCreateBranch | ||
), | ||
withId( | ||
projectHasCheckpoints ? 'Modify and Resume' : 'Modify and Run', | ||
MessageFromWebviewType.VARY_EXPERIMENT_PARAMS_AND_RUN, | ||
!isNotCheckpoint, | ||
!canApplyOrCreateBranch | ||
hideApplyAndCreateBranch | ||
), | ||
withId( | ||
'Modify, Reset and Run', | ||
MessageFromWebviewType.VARY_EXPERIMENT_PARAMS_RESET_AND_RUN, | ||
!isNotCheckpoint || !projectHasCheckpoints | ||
), | ||
withId( | ||
'Modify and Queue', | ||
MessageFromWebviewType.VARY_EXPERIMENT_PARAMS_AND_QUEUE, | ||
!isNotCheckpoint | ||
...getRunResumeOptions( | ||
withId, | ||
isWorkspace, | ||
projectHasCheckpoints, | ||
hideApplyAndCreateBranch, | ||
depth | ||
), | ||
experimentMenuOption( | ||
[id], | ||
starred ? 'Unstar Experiment' : 'Star Experiment', | ||
MessageFromWebviewType.TOGGLE_EXPERIMENT_STAR, | ||
isWorkspace, | ||
true | ||
!hasRunningExperiment | ||
), | ||
withId( | ||
'Remove', | ||
|
@@ -161,6 +203,7 @@ const getContextMenuOptions = ( | |
id: string, | ||
isWorkspace: boolean, | ||
projectHasCheckpoints: boolean, | ||
hasRunningExperiment: boolean, | ||
depth: number, | ||
selectedRows: Record<string, RowProp | undefined>, | ||
queued?: boolean, | ||
|
@@ -173,12 +216,13 @@ const getContextMenuOptions = ( | |
|
||
return cond( | ||
isFromSelection && selectedRowsList.length > 1, | ||
() => getMultiSelectMenuOptions(selectedRowsList), | ||
() => getMultiSelectMenuOptions(selectedRowsList, hasRunningExperiment), | ||
() => | ||
getSingleSelectMenuOptions( | ||
id, | ||
isWorkspace, | ||
projectHasCheckpoints, | ||
hasRunningExperiment, | ||
depth, | ||
queued, | ||
starred | ||
|
@@ -187,6 +231,7 @@ const getContextMenuOptions = ( | |
} | ||
|
||
export const RowContextMenu: React.FC<RowProp> = ({ | ||
hasRunningExperiment = false, | ||
projectHasCheckpoints = false, | ||
row: { | ||
original: { queued, starred }, | ||
|
@@ -204,6 +249,7 @@ export const RowContextMenu: React.FC<RowProp> = ({ | |
id, | ||
isWorkspace, | ||
projectHasCheckpoints, | ||
hasRunningExperiment, | ||
depth, | ||
selectedRows, | ||
queued, | ||
|
@@ -216,7 +262,8 @@ export const RowContextMenu: React.FC<RowProp> = ({ | |
depth, | ||
id, | ||
projectHasCheckpoints, | ||
selectedRows | ||
selectedRows, | ||
hasRunningExperiment | ||
]) | ||
|
||
return ( | ||
|
@@ -267,6 +314,7 @@ export const RowContent: React.FC< | |
changes, | ||
contextMenuDisabled, | ||
projectHasCheckpoints, | ||
hasRunningExperiment, | ||
batchRowSelection | ||
}): JSX.Element => { | ||
const { | ||
|
@@ -319,6 +367,7 @@ export const RowContent: React.FC< | |
<RowContextMenu | ||
row={row} | ||
projectHasCheckpoints={projectHasCheckpoints} | ||
hasRunningExperiment={hasRunningExperiment} | ||
/> | ||
} | ||
> | ||
|
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.
[N] I think you can use
toHaveLength
here.