Skip to content

Commit

Permalink
Merge branch 'main' into add-pipeline-model
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Jul 16, 2023
2 parents 207a11f + 46d8fd0 commit e321dc5
Show file tree
Hide file tree
Showing 37 changed files with 719 additions and 204 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

All notable changes to this project will be documented in this file.

## [1.0.18] - 2023-07-14

### 🚀 New Features and Enhancements

- Add CSV export option to zoomed in plots [#4252](https://github.com/iterative/vscode-dvc/pull/4252) by [@julieg18](https://github.com/julieg18)
- Save smooth plot values across sessions [#4220](https://github.com/iterative/vscode-dvc/pull/4220) by [@julieg18](https://github.com/julieg18)

## [1.0.17] - 2023-07-11

### 🚀 New Features and Enhancements
Expand Down
10 changes: 5 additions & 5 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"extensionDependencies": [
"vscode.git"
],
"version": "1.0.17",
"version": "1.0.18",
"license": "Apache-2.0",
"readme": "./README.md",
"repository": {
Expand Down Expand Up @@ -1708,8 +1708,8 @@
"@types/vscode": "1.64.0",
"@vscode/test-electron": "2.3.3",
"@vscode/vsce": "2.19.0",
"@wdio/cli": "8.11.2",
"@wdio/local-runner": "8.11.2",
"@wdio/cli": "8.11.4",
"@wdio/local-runner": "8.11.3",
"@wdio/mocha-framework": "8.11.0",
"@wdio/spec-reporter": "8.11.2",
"chai": "4.3.7",
Expand All @@ -1727,8 +1727,8 @@
"sinon-chai": "3.7.0",
"ts-loader": "9.4.4",
"vscode-uri": "3.0.7",
"wdio-vscode-service": "5.1.0",
"webdriverio": "8.11.2",
"wdio-vscode-service": "5.2.0",
"webdriverio": "8.11.3",
"webpack": "5.88.1",
"webpack-cli": "5.1.4"
},
Expand Down
25 changes: 12 additions & 13 deletions extension/src/experiments/model/tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -533,20 +533,19 @@ describe('ExperimentsTree', () => {

it('should return a tree item for the workspace', () => {
let mockedItem = {}
mockedTreeItem.mockImplementationOnce(function (
resourceUri,
collapsibleState
) {
expect(collapsibleState).toStrictEqual(0)
expect(resourceUri).toStrictEqual(
getDecoratableUri(
EXPERIMENT_WORKSPACE_ID,
DecoratableTreeItemScheme.EXPERIMENTS
mockedTreeItem.mockImplementationOnce(
function (resourceUri, collapsibleState) {
expect(collapsibleState).toStrictEqual(0)
expect(resourceUri).toStrictEqual(
getDecoratableUri(
EXPERIMENT_WORKSPACE_ID,
DecoratableTreeItemScheme.EXPERIMENTS
)
)
)
mockedItem = { collapsibleState, resourceUri }
return mockedItem
})
mockedItem = { collapsibleState, resourceUri }
return mockedItem
}
)
mockedThemeIcon.mockImplementationOnce(function (id) {
return { id }
})
Expand Down
1 change: 1 addition & 0 deletions extension/src/persistence/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export enum PersistenceKey {
PLOTS_CUSTOM_ORDER = 'plotCustomOrder:',
PLOT_SECTION_COLLAPSED = 'plotSectionCollapsed:',
PLOT_SELECTED_METRICS = 'plotSelectedMetrics:',
PLOTS_SMOOTH_PLOT_VALUES = 'plotSmoothPlotValues:',
PLOT_TEMPLATE_ORDER = 'plotTemplateOrder:'
}

Expand Down
2 changes: 1 addition & 1 deletion extension/src/plots/model/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,4 @@ export const createSpec = (title: string, metric: string, param: string) =>
}
],
width: 'container'
} as VisualizationSpec)
}) as VisualizationSpec
17 changes: 16 additions & 1 deletion extension/src/plots/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import {
CustomPlotsData,
DEFAULT_HEIGHT,
DEFAULT_NB_ITEMS_PER_ROW,
PlotHeight
PlotHeight,
SmoothPlotValues
} from '../webview/contract'
import {
EXPERIMENT_WORKSPACE_ID,
Expand Down Expand Up @@ -74,6 +75,7 @@ export class PlotsModel extends ModelWithPersistence {

private comparisonData: ComparisonData = {}
private comparisonOrder: string[]
private smoothPlotValues: SmoothPlotValues = {}

private revisionData: RevisionData = {}
private templates: TemplateAccumulator = {}
Expand Down Expand Up @@ -102,6 +104,10 @@ export class PlotsModel extends ModelWithPersistence {
)
this.comparisonOrder = this.revive(PersistenceKey.PLOT_COMPARISON_ORDER, [])
this.customPlotsOrder = this.revive(PersistenceKey.PLOTS_CUSTOM_ORDER, [])
this.smoothPlotValues = this.revive(
PersistenceKey.PLOTS_SMOOTH_PLOT_VALUES,
{}
)

this.cleanupOutdatedCustomPlotsState()
this.cleanupOutdatedTrendsState()
Expand Down Expand Up @@ -312,6 +318,15 @@ export class PlotsModel extends ModelWithPersistence {
)
}

public setSmoothPlotValues(id: string, value: number) {
this.smoothPlotValues[id] = value
this.persist(PersistenceKey.PLOTS_SMOOTH_PLOT_VALUES, this.smoothPlotValues)
}

public getSmoothPlotValues() {
return this.smoothPlotValues
}

public getNbItemsPerRowOrWidth(section: PlotsSection) {
if (this.nbItemsPerRowOrWidth[section]) {
return this.nbItemsPerRowOrWidth[section]
Expand Down
2 changes: 1 addition & 1 deletion extension/src/plots/paths/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ describe('PathsModel', () => {
getCliError: () => undefined,
getPathErrors: () => undefined,
hasCliError: () => undefined
} as unknown as ErrorsModel)
}) as unknown as ErrorsModel

it('should return the expected paths when given the default output fixture', () => {
const comparisonType = new Set([PathType.COMPARISON])
Expand Down
2 changes: 1 addition & 1 deletion extension/src/plots/paths/tree.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('PlotsPathsTree', () => {
it('should return the correct children for multi source plots (encoding elements)', () => {
const mockedWorkspacePlots = {
getRepository: () =>
({ getChildPaths: mockedGetChildPaths } as unknown as Plots),
({ getChildPaths: mockedGetChildPaths }) as unknown as Plots,
pathsChanged: buildMockedEventEmitter()
} as unknown as WorkspacePlots
const mockedInternalCommands = {
Expand Down
2 changes: 1 addition & 1 deletion extension/src/plots/vega/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ describe('extendVegaSpec', () => {
...layers.slice(1)
],
title
} as TopLevelSpec)
}) as TopLevelSpec

it('should truncate all titles from the left to 50 characters for large plots', () => {
const spec = withLongTemplatePlotTitle()
Expand Down
3 changes: 3 additions & 0 deletions extension/src/plots/webview/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,13 @@ export type TemplatePlotSection = {
entries: TemplatePlotEntry[]
}

export type SmoothPlotValues = { [id: string]: number }

export interface TemplatePlotsData {
plots: TemplatePlotSection[]
nbItemsPerRow: number
height: PlotHeight
smoothPlotValues: SmoothPlotValues
}

export type ComparisonPlot = {
Expand Down
18 changes: 17 additions & 1 deletion extension/src/plots/webview/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ export class WebviewMessages {
)
case MessageFromWebviewType.TOGGLE_EXPERIMENT:
return this.setExperimentStatus(message.payload)
case MessageFromWebviewType.SET_SMOOTH_PLOT_VALUE:
return this.setSmoothPlotValues(
message.payload.id,
message.payload.value
)
case MessageFromWebviewType.ZOOM_PLOT:
if (message.payload) {
const imagePath = this.revertCorrectUrl(message.payload)
Expand Down Expand Up @@ -200,6 +205,16 @@ export class WebviewMessages {
)
}

private setSmoothPlotValues(id: string, value: number) {
this.plots.setSmoothPlotValues(id, value)
this.sendTemplatePlots()
sendTelemetryEvent(
EventName.VIEWS_PLOTS_SET_SMOOTH_PLOT_VALUE,
undefined,
undefined
)
}

private setCustomPlotsOrder(plotIds: string[]) {
const customPlotsOrderWithId = this.plots
.getCustomPlotsOrder()
Expand Down Expand Up @@ -287,7 +302,8 @@ export class WebviewMessages {
nbItemsPerRow: this.plots.getNbItemsPerRowOrWidth(
PlotsSection.TEMPLATE_PLOTS
),
plots
plots,
smoothPlotValues: this.plots.getSmoothPlotValues()
}
}

Expand Down
2 changes: 2 additions & 0 deletions extension/src/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const EventName = Object.assign(
VIEWS_PLOTS_SECTION_TOGGLE: 'views.plots.toggleSection',
VIEWS_PLOTS_SELECT_EXPERIMENTS: 'view.plots.selectExperiments',
VIEWS_PLOTS_SELECT_PLOTS: 'view.plots.selectPlots',
VIEWS_PLOTS_SET_SMOOTH_PLOT_VALUE: 'view.plots.setSmoothPlotValues',
VIEWS_PLOTS_ZOOM_PLOT: 'views.plots.zoomPlot',
VIEWS_REORDER_PLOTS_CUSTOM: 'views.plots.customReordered',
VIEWS_REORDER_PLOTS_TEMPLATES: 'views.plots.templatesReordered',
Expand Down Expand Up @@ -274,6 +275,7 @@ export interface IEventNamePropertyMapping {
[EventName.VIEWS_PLOTS_ZOOM_PLOT]: { isImage: boolean }
[EventName.VIEWS_REORDER_PLOTS_CUSTOM]: undefined
[EventName.VIEWS_REORDER_PLOTS_TEMPLATES]: undefined
[EventName.VIEWS_PLOTS_SET_SMOOTH_PLOT_VALUE]: undefined

[EventName.VIEWS_PLOTS_PATH_TREE_OPENED]: DvcRootCount

Expand Down
20 changes: 12 additions & 8 deletions extension/src/test/fixtures/plotsDiff/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,11 +488,12 @@ const extendedSpecs = (plotsOutput: TemplatePlots): TemplatePlotSection[] => {
...originalPlot.content,
data: {
values:
REVISIONS.flatMap(revision =>
originalPlot.datapoints?.[revision].map(values => ({
...values,
rev: revision
}))
REVISIONS.flatMap(
revision =>
originalPlot.datapoints?.[revision].map(values => ({
...values,
rev: revision
}))
) || []
}
} as TopLevelSpec,
Expand Down Expand Up @@ -732,13 +733,15 @@ export const getMinimalWebviewMessage = () => ({
plots: extendedSpecs(basicVega),
nbItemsPerRow: DEFAULT_NB_ITEMS_PER_ROW,
height: DEFAULT_PLOT_HEIGHT,
revisions: getRevisions()
revisions: getRevisions(),
smoothPlotValues: {}
})

export const getTemplateWebviewMessage = (): TemplatePlotsData => ({
plots: extendedSpecs({ ...basicVega, ...require('./vega').default }),
nbItemsPerRow: DEFAULT_NB_ITEMS_PER_ROW,
height: DEFAULT_PLOT_HEIGHT
height: DEFAULT_PLOT_HEIGHT,
smoothPlotValues: {}
})

export const getManyTemplatePlotsWebviewMessage = (
Expand All @@ -748,7 +751,8 @@ export const getManyTemplatePlotsWebviewMessage = (
...multipleVega(length)
}),
nbItemsPerRow: DEFAULT_NB_ITEMS_PER_ROW,
height: DEFAULT_PLOT_HEIGHT
height: DEFAULT_PLOT_HEIGHT,
smoothPlotValues: {}
})

export const MOCK_IMAGE_MTIME = 946684800000
Expand Down
5 changes: 3 additions & 2 deletions extension/src/test/suite/cli/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ suite('CLI Suite', () => {
const options = getOptions('child')
const child = createProcess(options)

const stdout = await new Promise<string>(resolve =>
child.all?.on('data', chunk => resolve(chunk.toString().trim()))
const stdout = await new Promise<string>(
resolve =>
child.all?.on('data', chunk => resolve(chunk.toString().trim()))
)

const childPid = createValidInteger(child.pid) as number
Expand Down
33 changes: 33 additions & 0 deletions extension/src/test/suite/plots/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,39 @@ suite('Plots Test Suite', () => {
)
})

it('should handle an update smooth plot values message from the webview', async () => {
const { plots, plotsModel } = await buildPlots({
disposer: disposable,
plotsDiff: plotsDiffFixture
})
const templatePlot = templatePlotsFixture.plots[0].entries[0]

const webview = await plots.showWebview()
const mockMessageReceived = getMessageReceivedEmitter(webview)
const mockSendTelemetryEvent = stub(Telemetry, 'sendTelemetryEvent')
const mockSetSmoothPlotValues = stub(plotsModel, 'setSmoothPlotValues')

mockMessageReceived.fire({
payload: {
id: templatePlot.id,
value: 0.5
},
type: MessageFromWebviewType.SET_SMOOTH_PLOT_VALUE
})

expect(mockSendTelemetryEvent).to.be.called
expect(mockSendTelemetryEvent).to.be.calledWithExactly(
EventName.VIEWS_PLOTS_SET_SMOOTH_PLOT_VALUE,
undefined,
undefined
)
expect(mockSetSmoothPlotValues).to.be.called
expect(mockSetSmoothPlotValues).to.be.calledWithExactly(
templatePlot.id,
0.5
)
})

it('should handle the CLI throwing an error', async () => {
const { data, errorsModel, mockPlotsDiff, plots, plotsModel } =
await buildPlots({ disposer: disposable, plotsDiff: plotsDiffFixture })
Expand Down
2 changes: 1 addition & 1 deletion extension/src/test/suite/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export const buildMockExperimentsData = (update = stub()) =>
onDidUpdate: stub(),
setBranches: stub(),
update
} as unknown as ExperimentsData)
}) as unknown as ExperimentsData

const buildResourceLocator = (disposer: Disposer): ResourceLocator =>
disposer.track(new ResourceLocator(extensionUri))
Expand Down
2 changes: 1 addition & 1 deletion extension/src/test/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ export const buildMockMemento = (
values[key] = value
void Promise.resolve()
}
} as unknown as Memento)
}) as unknown as Memento
6 changes: 3 additions & 3 deletions extension/src/test/util/jest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ export const getMockedProcess = (stdout: string): Process =>
all: { on: jest.fn() },
on: jest.fn(),
stdout: new Promise(resolve => resolve(stdout))
} as unknown as Process)
}) as unknown as Process

export const getFailingMockedProcess = (stderr: string): Process =>
({
on: jest.fn(),
// eslint-disable-next-line promise/param-names
stdout: new Promise((_, reject) => reject(new Error(stderr)))
} as unknown as Process)
}) as unknown as Process

export const buildMockedEventEmitter = <T = void>() => {
const mockedEmitter = jest.mocked(new EventEmitter<T>())
Expand Down Expand Up @@ -55,7 +55,7 @@ export const buildMockedExperiments = () => {
getSorts: mockedGetSorts,
getSummaryColumnOrder: mockedGetSummaryColumnOrder,
getWorkspaceAndCommits: mockedGetWorkspaceAndCommits
} as unknown as Experiments),
}) as unknown as Experiments,
isReady: () => true
} as unknown as WorkspaceExperiments

Expand Down
5 changes: 5 additions & 0 deletions extension/src/webview/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export enum MessageFromWebviewType {
RESIZE_COLUMN = 'resize-column',
RESIZE_PLOTS = 'resize-plots',
SAVE_STUDIO_TOKEN = 'save-studio-token',
SET_SMOOTH_PLOT_VALUE = 'update-smooth-plot-value',
SHOW_EXPERIMENT_LOGS = 'show-experiment-logs',
SHOW_WALKTHROUGH = 'show-walkthrough',
STOP_EXPERIMENTS = 'stop-experiments',
Expand Down Expand Up @@ -232,6 +233,10 @@ export type MessageFromWebview =
| { type: MessageFromWebviewType.SHOW_WALKTHROUGH }
| { type: MessageFromWebviewType.SHOW_SCM_PANEL }
| { type: MessageFromWebviewType.INSTALL_DVC }
| {
type: MessageFromWebviewType.SET_SMOOTH_PLOT_VALUE
payload: { id: string; value: number }
}
| { type: MessageFromWebviewType.UPGRADE_DVC }
| { type: MessageFromWebviewType.SETUP_WORKSPACE }
| { type: MessageFromWebviewType.OPEN_STUDIO }
Expand Down
Loading

0 comments on commit e321dc5

Please sign in to comment.