-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into sticky-shadows
- Loading branch information
Showing
22 changed files
with
362 additions
and
133 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { | ||
FilterDefinition, | ||
filterExperiment, | ||
splitExperimentsByFilters | ||
} from '.' | ||
import { ExperimentType } from '..' | ||
import { definedAndNonEmpty } from '../../../util/array' | ||
import { Experiment } from '../../webview/contract' | ||
|
||
export type ExperimentWithType = Experiment & { type: ExperimentType } | ||
|
||
export const collectFilteredCounts = ( | ||
experiments: { type: ExperimentType }[] | ||
) => { | ||
const filtered = { checkpoints: 0, experiments: 0 } | ||
|
||
for (const { type } of experiments) { | ||
if (type === ExperimentType.CHECKPOINT) { | ||
filtered.checkpoints = filtered.checkpoints + 1 | ||
} | ||
if (type === ExperimentType.EXPERIMENT) { | ||
filtered.experiments = filtered.experiments + 1 | ||
} | ||
} | ||
|
||
return filtered | ||
} | ||
|
||
export const collectFiltered = ( | ||
acc: ExperimentWithType[], | ||
filters: FilterDefinition[], | ||
experiment: Experiment, | ||
checkpoints: ExperimentWithType[] | ||
): ExperimentWithType[] => { | ||
const { filtered, unfiltered } = splitExperimentsByFilters( | ||
filters, | ||
checkpoints | ||
) | ||
acc.push(...filtered) | ||
const hasUnfilteredCheckpoints = definedAndNonEmpty(unfiltered) | ||
if (hasUnfilteredCheckpoints) { | ||
return acc | ||
} | ||
if (!filterExperiment(filters, experiment)) { | ||
acc.push({ ...experiment, type: ExperimentType.EXPERIMENT }) | ||
} | ||
return acc | ||
} |
56 changes: 56 additions & 0 deletions
56
extension/src/experiments/model/filterBy/decorationProvider.ts
This file contains 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { | ||
Event, | ||
EventEmitter, | ||
FileDecoration, | ||
FileDecorationProvider, | ||
ThemeColor, | ||
Uri, | ||
window | ||
} from 'vscode' | ||
import { Disposable } from '../../../class/dispose' | ||
|
||
export const getDecoratableUri = (label: string): Uri => | ||
Uri.from({ path: label, scheme: 'dvc.experiments' }) | ||
|
||
export class DecorationProvider | ||
extends Disposable | ||
implements FileDecorationProvider | ||
{ | ||
private static DecorationFiltered: FileDecoration = { | ||
color: new ThemeColor('gitDecoration.ignoredResourceForeground'), | ||
tooltip: 'Filtered' | ||
} | ||
|
||
public readonly onDidChangeFileDecorations: Event<Uri[]> | ||
private readonly decorationsChanged: EventEmitter<Uri[]> | ||
|
||
private filtered = new Set<string>() | ||
|
||
constructor(decorationsChanged?: EventEmitter<Uri[]>) { | ||
super() | ||
|
||
this.decorationsChanged = this.dispose.track( | ||
decorationsChanged || new EventEmitter() | ||
) | ||
this.onDidChangeFileDecorations = this.decorationsChanged.event | ||
|
||
this.dispose.track(window.registerFileDecorationProvider(this)) | ||
} | ||
|
||
public provideFileDecoration(uri: Uri): FileDecoration | undefined { | ||
if (this.filtered.has(uri.fsPath)) { | ||
return DecorationProvider.DecorationFiltered | ||
} | ||
} | ||
|
||
public setState(labels: string[], filtered: Set<string>) { | ||
const urisToUpdate: Uri[] = [] | ||
|
||
for (const label of labels) { | ||
urisToUpdate.push(getDecoratableUri(label)) | ||
} | ||
|
||
this.filtered = filtered | ||
this.decorationsChanged.fire(urisToUpdate) | ||
} | ||
} |
Oops, something went wrong.