Skip to content

Commit

Permalink
Merge branch 'main' into update-old-workspace-plots-state
Browse files Browse the repository at this point in the history
  • Loading branch information
julieg18 authored Mar 22, 2023
2 parents 441f2d7 + ab598a5 commit cf6c276
Show file tree
Hide file tree
Showing 12 changed files with 194 additions and 59 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.

## [0.6.24] - 2023-03-21

### 🐛 Bug Fixes

- Remove error for invalid dvc.yaml if no dvc.yaml file [#3514](https://github.com/iterative/vscode-dvc/pull/3514) by [@sroy3](https://github.com/sroy3)
- Add missing loading screen to Custom section [#3524](https://github.com/iterative/vscode-dvc/pull/3524) by [@julieg18](https://github.com/julieg18)

### 🔨 Maintenance

- Add etc/no-assign-mutated-array rule [#3521](https://github.com/iterative/vscode-dvc/pull/3521) by [@mattseddon](https://github.com/mattseddon)

## [0.6.23] - 2023-03-21

### 🚀 New Features and Enhancements
Expand Down
6 changes: 3 additions & 3 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"extensionDependencies": [
"vscode.git"
],
"version": "0.6.23",
"version": "0.6.24",
"license": "Apache-2.0",
"readme": "./README.md",
"repository": {
Expand Down Expand Up @@ -1616,7 +1616,7 @@
},
"dependencies": {
"@hediet/std": "0.6.0",
"@vscode/extension-telemetry": "0.7.5",
"@vscode/extension-telemetry": "0.7.7",
"appdirs": "1.1.0",
"execa": "5.1.1",
"fs-extra": "11.1.0",
Expand All @@ -1641,7 +1641,7 @@
"@types/chai-as-promised": "7.1.5",
"@types/copy-webpack-plugin": "10.1.0",
"@types/fs-extra": "11.0.1",
"@types/jest": "29.4.1",
"@types/jest": "29.4.2",
"@types/js-yaml": "4.0.5",
"@types/lodash.clonedeep": "4.5.7",
"@types/lodash.get": "4.4.7",
Expand Down
5 changes: 3 additions & 2 deletions extension/src/experiments/webview/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { ConfigKey, setConfigValue } from '../../vscode/config'
import { Toast } from '../../vscode/toast'
import { EXPERIMENT_WORKSPACE_ID } from '../../cli/dvc/contract'
import { stopWorkspaceExperiment } from '../processExecution'
import { hasDvcYamlFile } from '../../fileSystem'

export class WebviewMessages {
private readonly dvcRoot: string
Expand All @@ -40,7 +41,7 @@ export class WebviewMessages {
...ids: string[]
) => Promise<string | undefined>

private readonly hasStages: () => Promise<string>
private readonly hasStages: () => Promise<string | undefined>

private hasConfig = false
private hasValidDvcYaml = true
Expand Down Expand Up @@ -77,7 +78,7 @@ export class WebviewMessages {

public async changeHasConfig(update?: boolean) {
const stages = await this.hasStages()
this.hasValidDvcYaml = stages !== undefined
this.hasValidDvcYaml = !hasDvcYamlFile(this.dvcRoot) || stages !== undefined
this.hasConfig = !!stages
update && this.sendWebviewMessage()
}
Expand Down
33 changes: 32 additions & 1 deletion extension/src/experiments/workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ import { buildMockedEventEmitter } from '../test/util/jest'
import { OutputChannel } from '../vscode/outputChannel'
import { Title } from '../vscode/title'
import { Args } from '../cli/dvc/constants'
import { findOrCreateDvcYamlFile, getFileExtension } from '../fileSystem'
import {
findOrCreateDvcYamlFile,
getFileExtension,
hasDvcYamlFile
} from '../fileSystem'
import { Toast } from '../vscode/toast'

const mockedShowWebview = jest.fn()
Expand All @@ -30,6 +34,7 @@ const mockedExpFunc = jest.fn()
const mockedListStages = jest.fn()
const mockedFindOrCreateDvcYamlFile = jest.mocked(findOrCreateDvcYamlFile)
const mockedGetFileExtension = jest.mocked(getFileExtension)
const mockedHasDvcYamlFile = jest.mocked(hasDvcYamlFile)

jest.mock('vscode')
jest.mock('@hediet/std/disposable')
Expand Down Expand Up @@ -597,11 +602,26 @@ describe('Experiments', () => {
)
})

it('should not show a toast if there is no dvc.yaml file', async () => {
const showErrorSpy = jest.spyOn(Toast, 'showError')

mockedQuickPickOne.mockResolvedValueOnce(mockedDvcRoot)
mockedListStages.mockResolvedValueOnce(undefined)
mockedHasDvcYamlFile.mockReturnValueOnce(false)

await workspaceExperiments.getCwdThenRun(mockedCommandId)

expect(showErrorSpy).not.toHaveBeenCalledWith(
'Cannot perform task. Your dvc.yaml file is invalid.'
)
})

it('should show a toast if the dvc.yaml file is invalid', async () => {
const showErrorSpy = jest.spyOn(Toast, 'showError')

mockedQuickPickOne.mockResolvedValueOnce(mockedDvcRoot)
mockedListStages.mockResolvedValueOnce(undefined)
mockedHasDvcYamlFile.mockReturnValueOnce(true)

await workspaceExperiments.getCwdThenRun(mockedCommandId)

Expand All @@ -610,9 +630,20 @@ describe('Experiments', () => {
)
})

it('should ask to create a stage if there is no dvc.yaml file', async () => {
mockedQuickPickOne.mockResolvedValueOnce(mockedDvcRoot)
mockedListStages.mockResolvedValueOnce(undefined)
mockedHasDvcYamlFile.mockReturnValueOnce(false)

await workspaceExperiments.getCwdThenRun(mockedCommandId)

expect(mockedGetValidInput).toHaveBeenCalled()
})

it('should not ask to create a stage if the dvc.yaml file is invalid', async () => {
mockedQuickPickOne.mockResolvedValueOnce(mockedDvcRoot)
mockedListStages.mockResolvedValueOnce(undefined)
mockedHasDvcYamlFile.mockReturnValueOnce(true)

await workspaceExperiments.getCwdThenRun(mockedCommandId)

Expand Down
8 changes: 6 additions & 2 deletions extension/src/experiments/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import {
import { BaseWorkspaceWebviews } from '../webview/workspace'
import { Title } from '../vscode/title'
import { ContextKey, setContextValue } from '../vscode/context'
import { findOrCreateDvcYamlFile, getFileExtension } from '../fileSystem'
import {
findOrCreateDvcYamlFile,
getFileExtension,
hasDvcYamlFile
} from '../fileSystem'
import { quickPickOneOrInput } from '../vscode/quickPick'
import { pickFile } from '../vscode/resourcePicker'

Expand Down Expand Up @@ -444,7 +448,7 @@ export class WorkspaceExperiments extends BaseWorkspaceWebviews<
cwd
)

if (stages === undefined) {
if (hasDvcYamlFile(cwd) && stages === undefined) {
await Toast.showError(
'Cannot perform task. Your dvc.yaml file is invalid.'
)
Expand Down
2 changes: 2 additions & 0 deletions extension/src/fileSystem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ export const openImageFileInEditor = async (imagePath: string) =>
viewColumn: ViewColumn.Beside
})

export const hasDvcYamlFile = (cwd: string) => existsSync(`${cwd}/dvc.yaml`)

export const findOrCreateDvcYamlFile = (
cwd: string,
trainingScript: string,
Expand Down
50 changes: 50 additions & 0 deletions extension/src/test/suite/experiments/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,56 @@ suite('Experiments Test Suite', () => {
expect(windowSpy).not.to.have.been.called
}).timeout(WEBVIEW_TEST_TIMEOUT)

it('should set hasValidDvcYaml to false if there is an error getting stages and there is a dvc.yaml file', async () => {
stub(DvcReader.prototype, 'listStages').resolves(undefined)
stub(FileSystem, 'hasDvcYamlFile').returns(true)

const { experiments, messageSpy } = buildExperiments(
disposable,
expShowFixture
)

await experiments.showWebview()

expect(messageSpy).to.be.calledWithMatch({
hasValidDvcYaml: false
})
}).timeout(WEBVIEW_TEST_TIMEOUT)

it('should set hasValidDvcYaml to true if there is an error getting stages and there is no dvc.yaml file', async () => {
stub(DvcReader.prototype, 'listStages').resolves(undefined)
stub(FileSystem, 'hasDvcYamlFile').returns(false)

const { experiments, messageSpy } = buildExperiments(
disposable,
expShowFixture
)

await experiments.showWebview()

const expectedTableData = {
hasValidDvcYaml: true
}

expect(messageSpy).to.be.calledWithMatch(expectedTableData)
}).timeout(WEBVIEW_TEST_TIMEOUT)

it('should set hasValidDvcYaml to true if there are no errors getting stages', async () => {
stub(DvcReader.prototype, 'listStages').resolves('')
stub(FileSystem, 'hasDvcYamlFile').returns(false)

const { experiments, messageSpy } = buildExperiments(
disposable,
expShowFixture
)

await experiments.showWebview()

expect(messageSpy).to.be.calledWithMatch({
hasValidDvcYaml: true
})
}).timeout(WEBVIEW_TEST_TIMEOUT)

it('should set hasConfig to false if there are no stages', async () => {
stub(DvcReader.prototype, 'listStages').resolves('')

Expand Down
2 changes: 1 addition & 1 deletion languageServer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"devDependencies": {
"@swc/core": "1.3.40",
"@swc/jest": "0.2.24",
"@types/jest": "29.4.1",
"@types/jest": "29.4.2",
"clean-webpack-plugin": "4.0.0",
"copy-webpack-plugin": "11.0.0",
"fork-ts-checker-webpack-plugin": "8.0.0",
Expand Down
6 changes: 3 additions & 3 deletions webview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@swc/jest": "0.2.24",
"@testing-library/jest-dom": "5.16.5",
"@testing-library/react": "14.0.0",
"@types/jest": "29.4.1",
"@types/jest": "29.4.2",
"@types/jsdom": "21.1.0",
"@types/node": "16.x",
"@types/react": "18.0.28",
Expand All @@ -70,15 +70,15 @@
"jest-environment-jsdom": "29.5.0",
"lint-staged": "13.2.0",
"raw-loader": "4.0.2",
"sass": "1.59.2",
"sass": "1.59.3",
"sass-loader": "13.2.0",
"storybook-addon-designs": "6.3.1",
"storybook-addon-themes": "6.1.0",
"style-loader": "3.3.2",
"ts-loader": "9.4.2",
"webpack": "5.76.1",
"webpack-cli": "5.0.1",
"webpack-dev-server": "4.11.1"
"webpack-dev-server": "4.12.0"
},
"svgr": {
"typescript": true,
Expand Down
3 changes: 2 additions & 1 deletion webview/src/plots/components/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ describe('App', () => {
],
width: DEFAULT_NB_ITEMS_PER_ROW
},
custom: null,
hasPlots: true,
hasUnselectedPlots: false,
sectionCollapsed: DEFAULT_SECTION_COLLAPSED,
Expand All @@ -279,7 +280,7 @@ describe('App', () => {
})
const loading = await screen.findAllByText('Loading...')

expect(loading).toHaveLength(2)
expect(loading).toHaveLength(3)
})

it('should render the Add Plots and Add Experiments get started button when there are experiments which have plots that are all unselected', async () => {
Expand Down
8 changes: 8 additions & 0 deletions webview/src/plots/components/customPlots/CustomPlots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { shouldUseVirtualizedGrid } from '../util'
import { PlotsState } from '../../store'
import { sendMessage } from '../../../shared/vscode'
import { changeOrderWithDraggedInfo } from '../../../util/array'
import { LoadingSection, sectionIsLoading } from '../LoadingSection'

interface CustomPlotsProps {
plotsIds: string[]
Expand All @@ -29,6 +30,9 @@ export const CustomPlots: React.FC<CustomPlotsProps> = ({ plotsIds }) => {
const draggedRef = useSelector(
(state: PlotsState) => state.dragAndDrop.draggedRef
)
const selectedRevisions = useSelector(
(state: PlotsState) => state.webview.selectedRevisions
)

useEffect(() => {
setOrder(plotsIds)
Expand All @@ -42,6 +46,10 @@ export const CustomPlots: React.FC<CustomPlotsProps> = ({ plotsIds }) => {
})
}

if (sectionIsLoading(selectedRevisions)) {
return <LoadingSection />
}

if (!hasData) {
return <EmptyState isFullScreen={false}>No Plots to Display</EmptyState>
}
Expand Down
Loading

0 comments on commit cf6c276

Please sign in to comment.