Skip to content

Commit

Permalink
Merge branch 'main' into move-left
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon authored Jul 18, 2023
2 parents 56fdf8b + 731f9d3 commit bbd2a9c
Show file tree
Hide file tree
Showing 18 changed files with 396 additions and 290 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

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

## [1.0.21] - 2023-07-18

### 🚀 New Features and Enhancements

- Update copy in add stage component [#4292](https://github.com/iterative/vscode-dvc/pull/4292) by [@mattseddon](https://github.com/mattseddon)
- Add "Save as TSV" option to plot modal [#4285](https://github.com/iterative/vscode-dvc/pull/4285) by [@julieg18](https://github.com/julieg18)

### 🔨 Maintenance

- Remove `dvc_data_version_info` from plot values [#4262](https://github.com/iterative/vscode-dvc/pull/4262) by [@julieg18](https://github.com/julieg18)

## [1.0.20] - 2023-07-17

### 🐛 Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion 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.20",
"version": "1.0.21",
"license": "Apache-2.0",
"readme": "./README.md",
"repository": {
Expand Down
16 changes: 16 additions & 0 deletions extension/src/fileSystem/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
findOrCreateDvcYamlFile,
writeJson,
writeCsv,
writeTsv,
isPathInProject
} from '.'
import { dvcDemoPath } from '../test/util'
Expand Down Expand Up @@ -88,6 +89,21 @@ describe('writeCsv', () => {
})
})

describe('writeTsv', () => {
it('should write tsv into given file', async () => {
await writeTsv('file-name.tsv', [
{ nested: { string: 'string1' }, value: 3 },
{ nested: { string: 'string2' }, value: 4 },
{ nested: { string: 'string3' }, value: 6 }
])

expect(mockedWriteFileSync).toHaveBeenCalledWith(
'file-name.tsv',
'nested.string\tvalue\nstring1\t3\nstring2\t4\nstring3\t6'
)
})
})

describe('findDvcRootPaths', () => {
it('should find the dvc root if it exists in the given folder', async () => {
const dvcRoots = await findDvcRootPaths(dvcDemoPath)
Expand Down
9 changes: 9 additions & 0 deletions extension/src/fileSystem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,15 @@ export const writeCsv = async (
return writeFileSync(path, csv)
}

export const writeTsv = async (
path: string,
arr: Array<Record<string, unknown>>
) => {
ensureFileSync(path)
const csv = await json2csv(arr, { delimiter: { field: '\t' } })
return writeFileSync(path, csv)
}

export const getPidFromFile = async (
path: string
): Promise<number | undefined> => {
Expand Down
7 changes: 6 additions & 1 deletion extension/src/plots/model/collect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
} from '../multiSource/collect'
import { StrokeDashEncoding } from '../multiSource/constants'
import { exists } from '../../fileSystem'
import { hasKey } from '../../util/object'

export const getCustomPlotId = (metric: string, param: string) =>
`custom-${metric}-${param}`
Expand Down Expand Up @@ -156,12 +157,16 @@ const collectDatapoints = (
) => {
for (const value of values) {
const dvc_data_version_info = getDvcDataVersionInfo(value)
const data: { rev: string } = {
const data: { rev: string; dvc_data_version_info?: unknown } = {
...value,
...dvc_data_version_info,
rev
}

if (hasKey(data, 'dvc_data_version_info')) {
delete data.dvc_data_version_info
}

;(acc[rev][path] as unknown[]).push(data)
}
}
Expand Down
11 changes: 10 additions & 1 deletion extension/src/plots/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ import {
} from '../multiSource/collect'
import { isDvcError } from '../../cli/dvc/reader'
import { ErrorsModel } from '../errors/model'
import { openFileInEditor, writeCsv, writeJson } from '../../fileSystem'
import {
openFileInEditor,
writeCsv,
writeJson,
writeTsv
} from '../../fileSystem'
import { Toast } from '../../vscode/toast'

export class PlotsModel extends ModelWithPersistence {
Expand Down Expand Up @@ -244,6 +249,10 @@ export class PlotsModel extends ModelWithPersistence {
void this.savePlotData(filePath, plotId, data => writeCsv(filePath, data))
}

public savePlotDataAsTsv(filePath: string, plotId: string) {
void this.savePlotData(filePath, plotId, data => writeTsv(filePath, data))
}

public getTemplatePlots(
order: TemplateOrder | undefined,
selectedRevisions: Revision[]
Expand Down
56 changes: 38 additions & 18 deletions extension/src/plots/webview/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ export class WebviewMessages {
)
case MessageFromWebviewType.EXPORT_PLOT_DATA_AS_CSV:
return this.exportPlotDataAsCsv(message.payload)
case MessageFromWebviewType.EXPORT_PLOT_DATA_AS_TSV:
return this.exportPlotDataAsTsv(message.payload)
case MessageFromWebviewType.EXPORT_PLOT_DATA_AS_JSON:
return this.exportPlotDataAsJson(message.payload)
case MessageFromWebviewType.RESIZE_PLOTS:
Expand Down Expand Up @@ -362,35 +364,53 @@ export class WebviewMessages {
return this.plots.getCustomPlots() || null
}

private async exportPlotDataAsJson(plotId: string) {
const file = await showSaveDialog('data.json', 'json')
private async exportPlotData(
extName: string,
plotId: string,
event:
| typeof EventName.VIEWS_PLOTS_EXPORT_PLOT_DATA_AS_CSV
| typeof EventName.VIEWS_PLOTS_EXPORT_PLOT_DATA_AS_JSON
| typeof EventName.VIEWS_PLOTS_EXPORT_PLOT_DATA_AS_TSV,
writeFile: (filePath: string, plotId: string) => void
) {
const file = await showSaveDialog(`data.${extName}`, extName)

if (!file) {
return
}

sendTelemetryEvent(
EventName.VIEWS_PLOTS_EXPORT_PLOT_DATA_AS_JSON,
undefined,
undefined
)
sendTelemetryEvent(event, undefined, undefined)

void this.plots.savePlotDataAsJson(file.path, plotId)
writeFile(file.path, plotId)
}

private async exportPlotDataAsCsv(plotId: string) {
const file = await showSaveDialog('data.csv', 'csv')

if (!file) {
return
}
private exportPlotDataAsJson(plotId: string) {
void this.exportPlotData(
'json',
plotId,
EventName.VIEWS_PLOTS_EXPORT_PLOT_DATA_AS_JSON,
(filePath: string, plotId: string) =>
this.plots.savePlotDataAsJson(filePath, plotId)
)
}

sendTelemetryEvent(
private exportPlotDataAsCsv(plotId: string) {
void this.exportPlotData(
'csv',
plotId,
EventName.VIEWS_PLOTS_EXPORT_PLOT_DATA_AS_CSV,
undefined,
undefined
(filePath: string, plotId: string) =>
this.plots.savePlotDataAsCsv(filePath, plotId)
)
}

void this.plots.savePlotDataAsCsv(file.path, plotId)
private exportPlotDataAsTsv(plotId: string) {
void this.exportPlotData(
'tsv',
plotId,
EventName.VIEWS_PLOTS_EXPORT_PLOT_DATA_AS_TSV,
(filePath: string, plotId: string) =>
this.plots.savePlotDataAsTsv(filePath, plotId)
)
}
}
2 changes: 2 additions & 0 deletions extension/src/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export const EventName = Object.assign(
VIEWS_PLOTS_EXPERIMENT_TOGGLE: 'views.plots.toggleExperimentStatus',
VIEWS_PLOTS_EXPORT_PLOT_DATA_AS_CSV: 'views.plots.exportPlotDataAsCsv',
VIEWS_PLOTS_EXPORT_PLOT_DATA_AS_JSON: 'views.plots.exportPlotDataAsJson',
VIEWS_PLOTS_EXPORT_PLOT_DATA_AS_TSV: 'views.plots.exportPlotDataAsTsv',
VIEWS_PLOTS_FOCUS_CHANGED: 'views.plots.focusChanged',
VIEWS_PLOTS_REVISIONS_REORDERED: 'views.plots.revisionsReordered',
VIEWS_PLOTS_SECTION_RESIZED: 'views.plots.sectionResized',
Expand Down Expand Up @@ -272,6 +273,7 @@ export interface IEventNamePropertyMapping {
[EventName.VIEWS_PLOTS_EXPERIMENT_TOGGLE]: undefined
[EventName.VIEWS_PLOTS_EXPORT_PLOT_DATA_AS_CSV]: undefined
[EventName.VIEWS_PLOTS_EXPORT_PLOT_DATA_AS_JSON]: undefined
[EventName.VIEWS_PLOTS_EXPORT_PLOT_DATA_AS_TSV]: undefined

[EventName.VIEWS_PLOTS_ZOOM_PLOT]: { isImage: boolean }
[EventName.VIEWS_REORDER_PLOTS_CUSTOM]: undefined
Expand Down
Loading

0 comments on commit bbd2a9c

Please sign in to comment.