Skip to content

Commit ba4482b

Browse files
sroy3mattseddon
andauthored
Watch for dvc.yaml changes for manually added stages (#3365)
* Trigger a new webview message on dvc yaml change * Correctly update the webview if there is a stage or not and if the yaml is valid * Add test * Remove useless test id --------- Co-authored-by: Matt Seddon <[email protected]>
1 parent 4fbbe9e commit ba4482b

File tree

17 files changed

+67
-8
lines changed

17 files changed

+67
-8
lines changed

extension/src/experiments/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ export class Experiments extends BaseRepository<TableData> {
156156
if (hadCheckpoints !== this.hasCheckpoints()) {
157157
this.checkpointsChanged.fire()
158158
}
159+
void this.webviewMessages.changeHasConfig(true)
159160
})
160161
)
161162

extension/src/experiments/webview/contract.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ export type TableData = {
100100
hasColumns: boolean
101101
hasConfig: boolean
102102
hasRunningExperiment: boolean
103+
hasValidDvcYaml: boolean
103104
rows: Row[]
104105
sorts: SortDefinition[]
105106
filteredCounts: FilteredCounts

extension/src/experiments/webview/messages.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export class WebviewMessages {
4343
private readonly hasStages: () => Promise<string>
4444

4545
private hasConfig = false
46+
private hasValidDvcYaml = true
4647

4748
private readonly addStage: () => Promise<boolean>
4849

@@ -74,8 +75,11 @@ export class WebviewMessages {
7475
this.addStage = addStage
7576
}
7677

77-
public async changeHasConfig() {
78-
this.hasConfig = !!(await this.hasStages())
78+
public async changeHasConfig(update?: boolean) {
79+
const stages = await this.hasStages()
80+
this.hasValidDvcYaml = stages !== undefined
81+
this.hasConfig = !!stages
82+
update && this.sendWebviewMessage()
7983
}
8084

8185
public sendWebviewMessage() {
@@ -218,14 +222,14 @@ export class WebviewMessages {
218222
hasColumns: this.columns.hasNonDefaultColumns(),
219223
hasConfig: this.hasConfig,
220224
hasRunningExperiment: this.experiments.hasRunningExperiment(),
225+
hasValidDvcYaml: this.hasValidDvcYaml,
221226
rows: this.experiments.getRowData(),
222227
sorts: this.experiments.getSorts()
223228
}
224229
}
225230

226231
private async addConfiguration() {
227232
await this.addStage()
228-
await this.changeHasConfig()
229233
}
230234

231235
private async setMaxTableHeadDepth() {

extension/src/test/fixtures/expShow/base/tableData.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const tableDataFixture: TableData = {
1010
hasCheckpoints: true,
1111
hasConfig: true,
1212
hasRunningExperiment: true,
13+
hasValidDvcYaml: true,
1314
hasColumns: true,
1415
sorts: [],
1516
changes: [],

extension/src/test/fixtures/expShow/dataTypes/tableData.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export const data: TableData = {
1111
hasCheckpoints: false,
1212
hasConfig: true,
1313
hasRunningExperiment: false,
14+
hasValidDvcYaml: true,
1415
sorts: [],
1516
columns,
1617
hasColumns: true,

extension/src/test/fixtures/expShow/deeplyNested/tableData.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const data: TableData = {
1414
hasCheckpoints: false,
1515
hasConfig: true,
1616
hasRunningExperiment: false,
17+
hasValidDvcYaml: true,
1718
sorts: [
1819
{
1920
path: 'params:params.yaml:nested1.doubled',

extension/src/test/fixtures/expShow/survival/tableData.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const data: TableData = {
1111
hasConfig: true,
1212
hasRunningExperiment: true,
1313
hasColumns: true,
14+
hasValidDvcYaml: true,
1415
sorts: [],
1516
changes: [],
1617
columnOrder: [],

extension/src/test/suite/experiments/index.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ suite('Experiments Test Suite', () => {
153153
hasColumns: true,
154154
hasConfig: true,
155155
hasRunningExperiment: true,
156+
hasValidDvcYaml: true,
156157
rows: rowsFixture,
157158
sorts: []
158159
}
@@ -208,6 +209,7 @@ suite('Experiments Test Suite', () => {
208209
hasColumns: true,
209210
hasConfig: false,
210211
hasRunningExperiment: true,
212+
hasValidDvcYaml: true,
211213
rows: rowsFixture,
212214
sorts: []
213215
}
@@ -236,6 +238,7 @@ suite('Experiments Test Suite', () => {
236238
hasColumns: true,
237239
hasConfig: true,
238240
hasRunningExperiment: true,
241+
hasValidDvcYaml: true,
239242
rows: rowsFixture,
240243
sorts: []
241244
}
@@ -968,6 +971,7 @@ suite('Experiments Test Suite', () => {
968971
hasColumns: true,
969972
hasConfig: true,
970973
hasRunningExperiment: true,
974+
hasValidDvcYaml: true,
971975
rows: rowsFixture,
972976
sorts: []
973977
}

extension/src/test/suite/experiments/model/filterBy/tree.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ suite('Experiments Filter By Tree Test Suite', () => {
127127
hasColumns: true,
128128
hasConfig: true,
129129
hasRunningExperiment: true,
130+
hasValidDvcYaml: true,
130131
rows: filteredRows,
131132
sorts: []
132133
}
@@ -159,6 +160,7 @@ suite('Experiments Filter By Tree Test Suite', () => {
159160
hasColumns: true,
160161
hasConfig: true,
161162
hasRunningExperiment: true,
163+
hasValidDvcYaml: true,
162164
rows: [workspace, main],
163165
sorts: []
164166
}
@@ -426,6 +428,7 @@ suite('Experiments Filter By Tree Test Suite', () => {
426428
hasColumns: true,
427429
hasConfig: true,
428430
hasRunningExperiment: true,
431+
hasValidDvcYaml: true,
429432
rows: filteredRows,
430433
sorts: []
431434
}

webview/src/experiments/components/AddStage.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,28 @@ import { IconButton } from '../../shared/components/button/IconButton'
55
import { Add } from '../../shared/components/icons'
66
import { sendMessage } from '../../shared/vscode'
77

8-
export const AddStage: React.FC = () => (
8+
interface AddStageProps {
9+
hasValidDvcYaml: boolean
10+
}
11+
12+
export const AddStage: React.FC<AddStageProps> = ({ hasValidDvcYaml }) => (
913
<div className={styles.addConfigButton}>
1014
<p>Easily and efficiently reproduce your experiments </p>
1115
<IconButton
1216
icon={Add}
1317
onClick={() =>
18+
hasValidDvcYaml &&
1419
sendMessage({ type: MessageFromWebviewType.ADD_CONFIGURATION })
1520
}
1621
text="Add a Pipeline Stage"
22+
disabled={!hasValidDvcYaml}
1723
/>
24+
{!hasValidDvcYaml && (
25+
<p className={styles.error}>
26+
Your dvc.yaml file should contain valid yaml before adding any pipeline
27+
stages.
28+
</p>
29+
)}
1830
<p>
1931
<a href="https://dvc.org/doc/user-guide/project-structure/dvcyaml-files#stages">
2032
Learn more

0 commit comments

Comments
 (0)