-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add option to filter experiments to starred #2164
Changes from all commits
c0d27dd
8713b41
a0a21df
dd5bafd
5830a5c
3c6fbc7
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { Column } from '../webview/contract' | ||
|
||
export type ColumnLike = { label: string; path: string; types?: string[] } | ||
|
||
const starredColumnLike: ColumnLike = { | ||
label: '$(star-full)', | ||
path: 'starred', | ||
types: ['boolean'] | ||
} | ||
|
||
export const addStarredToColumns = ( | ||
columns: Column[] | undefined | ||
): ColumnLike[] | undefined => { | ||
if (!columns?.length) { | ||
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. Didn't we have a lint rule where it said we have to compare length to 0? 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 think the optional chain will be messing with it. You would need to write |
||
return | ||
} | ||
|
||
return [ | ||
...columns.map(({ label, path, types }) => ({ label, path, types })), | ||
starredColumnLike | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,7 +128,7 @@ export class ExperimentsModel extends ModelWithPersistence { | |
|
||
public toggleStatus(id: string) { | ||
if ( | ||
this.flattenExperiments().find(({ id: queuedId }) => queuedId === id) | ||
this.getFlattenedExperiments().find(({ id: queuedId }) => queuedId === id) | ||
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. [F] The main change in this file was to encapsulate access to experiments and checkpoints so that details (selected and starred) are always added. |
||
?.queued | ||
) { | ||
return | ||
|
@@ -236,7 +236,7 @@ export class ExperimentsModel extends ModelWithPersistence { | |
} | ||
|
||
public getSelectedExperiments() { | ||
return this.getSelectedFromList(() => this.flattenExperiments()) | ||
return this.getSelectedFromList(() => this.getFlattenedExperiments()) | ||
} | ||
|
||
public setSelected(selectedExperiments: Experiment[]) { | ||
|
@@ -288,6 +288,7 @@ export class ExperimentsModel extends ModelWithPersistence { | |
public getExperiments(): (ExperimentWithType & { | ||
hasChildren: boolean | ||
selected?: boolean | ||
starred: boolean | ||
})[] { | ||
return [ | ||
{ | ||
|
@@ -302,8 +303,8 @@ export class ExperimentsModel extends ModelWithPersistence { | |
type: ExperimentType.BRANCH | ||
} | ||
}), | ||
...this.flattenExperiments().map(experiment => ({ | ||
...this.addDetails(experiment), | ||
...this.getFlattenedExperiments().map(experiment => ({ | ||
...experiment, | ||
hasChildren: definedAndNonEmpty( | ||
this.checkpointsByTip.get(experiment.id) | ||
), | ||
|
@@ -324,9 +325,7 @@ export class ExperimentsModel extends ModelWithPersistence { | |
|
||
public getExperimentsWithCheckpoints(): ExperimentWithCheckpoints[] { | ||
return this.getExperiments().map(experiment => { | ||
const checkpoints = this.checkpointsByTip | ||
.get(experiment.id) | ||
?.map(checkpoint => this.addDetails(checkpoint)) | ||
const checkpoints = this.getCheckpointsWithType(experiment.id) | ||
if (!definedAndNonEmpty(checkpoints)) { | ||
return experiment | ||
} | ||
|
@@ -350,7 +349,7 @@ export class ExperimentsModel extends ModelWithPersistence { | |
return this.splitExperimentsByQueued(true) | ||
} | ||
|
||
public getCheckpoints( | ||
public getCheckpointsWithType( | ||
id: string | ||
): (Experiment & { type: ExperimentType })[] | undefined { | ||
return this.checkpointsByTip.get(id)?.map(checkpoint => ({ | ||
|
@@ -388,8 +387,8 @@ export class ExperimentsModel extends ModelWithPersistence { | |
|
||
public getExperimentCount() { | ||
return sum([ | ||
this.flattenCheckpoints().length, | ||
this.flattenExperiments().length, | ||
this.getFlattenedCheckpoints().length, | ||
this.getFlattenedExperiments().length, | ||
this.branches.length, | ||
1 | ||
]) | ||
|
@@ -404,8 +403,8 @@ export class ExperimentsModel extends ModelWithPersistence { | |
return [ | ||
this.workspace, | ||
...this.branches, | ||
...this.flattenExperiments(), | ||
...this.flattenCheckpoints() | ||
...this.getFlattenedExperiments(), | ||
...this.getFlattenedCheckpoints() | ||
] | ||
} | ||
|
||
|
@@ -417,13 +416,11 @@ export class ExperimentsModel extends ModelWithPersistence { | |
filters | ||
) | ||
if (!checkpoints) { | ||
return this.addDetails(experiment) | ||
return experiment | ||
} | ||
return { | ||
...this.addDetails(experiment), | ||
subRows: checkpoints.map(checkpoint => ({ | ||
...this.addDetails(checkpoint) | ||
})) | ||
...experiment, | ||
subRows: checkpoints | ||
} | ||
}) | ||
.filter((row: Row) => this.filterTableRow(row, filters)) | ||
|
@@ -445,7 +442,7 @@ export class ExperimentsModel extends ModelWithPersistence { | |
const acc: ExperimentWithType[] = [] | ||
|
||
for (const experiment of this.getCurrentExperiments()) { | ||
const checkpoints = this.getCheckpoints(experiment.id) || [] | ||
const checkpoints = this.getCheckpointsWithType(experiment.id) || [] | ||
collectFiltered(acc, this.getFilters(), experiment, checkpoints) | ||
} | ||
|
||
|
@@ -456,37 +453,49 @@ export class ExperimentsModel extends ModelWithPersistence { | |
sha: string, | ||
filters: FilterDefinition[] | ||
) { | ||
const checkpoints = this.checkpointsByTip.get(sha) | ||
const checkpoints = this.getCheckpoints(sha) | ||
if (!checkpoints) { | ||
return | ||
} | ||
const { unfiltered } = splitExperimentsByFilters(filters, checkpoints) | ||
return unfiltered | ||
} | ||
|
||
private getCheckpoints(id: string) { | ||
return this.checkpointsByTip | ||
.get(id) | ||
?.map(checkpoint => this.addDetails(checkpoint)) | ||
} | ||
|
||
private getExperimentsByBranch(branch: Experiment) { | ||
const experiments = this.experimentsByBranch.get(branch.label) | ||
const experiments = this.experimentsByBranch | ||
.get(branch.label) | ||
?.map(experiment => this.addDetails(experiment)) | ||
if (!experiments) { | ||
return | ||
} | ||
return sortExperiments(this.getSorts(), experiments) | ||
} | ||
|
||
private flattenExperiments() { | ||
return flattenMapValues(this.experimentsByBranch) | ||
private getFlattenedExperiments() { | ||
return flattenMapValues(this.experimentsByBranch).map(experiment => | ||
this.addDetails(experiment) | ||
) | ||
} | ||
|
||
private splitExperimentsByQueued(getQueued = false) { | ||
return this.flattenExperiments().filter(({ queued }) => { | ||
return this.getFlattenedExperiments().filter(({ queued }) => { | ||
if (getQueued) { | ||
return queued | ||
} | ||
return !queued | ||
}) | ||
} | ||
|
||
private flattenCheckpoints() { | ||
return flattenMapValues(this.checkpointsByTip) | ||
private getFlattenedCheckpoints() { | ||
return flattenMapValues(this.checkpointsByTip).map(checkpoint => | ||
this.addDetails(checkpoint) | ||
) | ||
} | ||
|
||
private setColoredStatus() { | ||
|
@@ -546,38 +555,28 @@ export class ExperimentsModel extends ModelWithPersistence { | |
return this.persist(PersistenceKey.EXPERIMENTS_STATUS, this.coloredStatus) | ||
} | ||
|
||
private addStarred(experiment: Experiment) { | ||
private addDetails(experiment: Experiment) { | ||
const { id } = experiment | ||
|
||
if (!this.isStarred(id)) { | ||
return experiment | ||
} | ||
|
||
return { | ||
...experiment, | ||
starred: true | ||
} | ||
} | ||
const starred = !!this.isStarred(id) | ||
|
||
private addSelected(experiment: Experiment) { | ||
const { id } = experiment | ||
if (!hasKey(this.coloredStatus, id)) { | ||
return experiment | ||
return { | ||
...experiment, | ||
starred | ||
} | ||
} | ||
|
||
const selected = this.isSelected(id) | ||
|
||
return { | ||
...experiment, | ||
displayColor: this.getDisplayColor(id), | ||
selected | ||
selected, | ||
starred | ||
} | ||
} | ||
|
||
private addDetails(experiment: Experiment) { | ||
return this.addStarred(this.addSelected(experiment)) | ||
} | ||
|
||
private getDisplayColor(id: string) { | ||
const color = this.coloredStatus[id] | ||
if (!color) { | ||
|
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.
[F] This definition is used in the quick pick. It means that we don't have to create a full mocked
Column
for "starred".