Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add action buttons to empty plot sections #4694

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions extension/src/plots/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,7 @@ export class Plots extends BaseRepository<TPlotsData> {
errors,
experiments,
() => this.getWebview(),
() => this.selectPlots(),
() => this.addCustomPlot()
() => this.selectPlots()
)
this.dispose.track(
this.onDidReceivedWebviewMessage(message =>
Expand Down
82 changes: 1 addition & 81 deletions extension/src/plots/model/custom.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { checkForCustomPlotOptions, cleanupOldOrderValue } from './custom'
import { customPlotsOrderFixture } from '../../test/fixtures/expShow/base/customPlots'
import { ColumnType } from '../../experiments/webview/contract'
import { cleanupOldOrderValue } from './custom'

describe('cleanupOlderValue', () => {
it('should update value if contents are outdated', () => {
Expand All @@ -23,81 +21,3 @@ describe('cleanupOlderValue', () => {
expect(output).toStrictEqual(value)
})
})

describe('checkForCustomPlotOptions', () => {
it('should return true if there are plots available', () => {
const output = checkForCustomPlotOptions(
[
{
hasChildren: false,
label: 'log_file',
path: 'params:params.yaml:log_file',
type: ColumnType.PARAMS
},
{
hasChildren: false,
label: 'log_file',
path: 'params:params.yaml:epochs',
type: ColumnType.PARAMS
},
{
hasChildren: false,
label: 'accuracy',
path: 'metrics:summary.json:loss',
type: ColumnType.METRICS
},
{
hasChildren: false,
label: 'accuracy',
path: 'metrics:summary.json:accuracy',
type: ColumnType.METRICS
}
],
customPlotsOrderFixture
)
expect(output).toStrictEqual(true)
})

it('should return false if there are no plots available', () => {
const output = checkForCustomPlotOptions(
[
{
hasChildren: false,
label: 'log_file',
path: 'params:params.yaml:log_file',
type: ColumnType.PARAMS
},
{
hasChildren: false,
label: 'log_file',
path: 'params:params.yaml:epochs',
type: ColumnType.PARAMS
},
{
hasChildren: false,
label: 'accuracy',
path: 'metrics:summary.json:loss',
type: ColumnType.METRICS
},
{
hasChildren: false,
label: 'accuracy',
path: 'metrics:summary.json:accuracy',
type: ColumnType.METRICS
}
],
[
...customPlotsOrderFixture,
{
metric: 'summary.json:accuracy',
param: 'params.yaml:log_file'
},
{
metric: 'summary.json:loss',
param: 'params.yaml:epochs'
}
]
)
expect(output).toStrictEqual(false)
})
})
18 changes: 0 additions & 18 deletions extension/src/plots/model/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,6 @@ export const getCustomPlotPathsFromColumns = (
return { metrics, params }
}

export const checkForCustomPlotOptions = (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently our "Add Plot" shows the custom plot option even if you can't create any more custom plots. We could technically add an extra check but then our choose plot quick pick would have only one item.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the option fails under these conditions with a clear message then that is ok.

I think the chances of real users hitting this is low.

Copy link
Contributor Author

@julieg18 julieg18 Sep 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the option fails under these conditions with a clear message then that is ok.

Yes, the option fails with an error toast message.

columns: Column[],
customPlotOrder: CustomPlotsOrderValue[]
): boolean => {
const { metrics, params } = getCustomPlotPathsFromColumns(columns)
const plotIds = getCustomPlotIds(customPlotOrder)

for (const metric of metrics) {
for (const param of params) {
if (!plotIds.has(getCustomPlotId(metric, param))) {
return true
}
}
}

return false
}

const getSpecDataType = (type: string) =>
type === 'number' ? 'quantitative' : 'nominal'

Expand Down
11 changes: 1 addition & 10 deletions extension/src/plots/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ import {
collectSelectedComparisonPlots
} from './collect'
import { getRevisionSummaryColumns } from './util'
import {
checkForCustomPlotOptions,
cleanupOldOrderValue,
CustomPlotsOrderValue
} from './custom'
import { cleanupOldOrderValue, CustomPlotsOrderValue } from './custom'
import {
Revision,
DEFAULT_SECTION_COLLAPSED,
Expand Down Expand Up @@ -156,10 +152,6 @@ export class PlotsModel extends ModelWithPersistence {
const experiments = this.experiments.getUnfilteredCommitsAndExperiments()
const hasUnfilteredExperiments = experiments.length > 0
const plotsOrderValues = this.getCustomPlotsOrder()
const enablePlotCreation = checkForCustomPlotOptions(
this.experiments.getColumnTerminalNodes(),
plotsOrderValues
)
const height = this.getHeight(PlotsSection.CUSTOM_PLOTS)
const nbItemsPerRow = this.getNbItemsPerRowOrWidth(
PlotsSection.CUSTOM_PLOTS
Expand All @@ -173,7 +165,6 @@ export class PlotsModel extends ModelWithPersistence {
)

return {
enablePlotCreation,
hasAddedPlots,
hasUnfilteredExperiments,
height,
Expand Down
1 change: 0 additions & 1 deletion extension/src/plots/webview/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export type CustomPlotData = CustomPlot & {
export type CustomPlotsData = {
plots: CustomPlotData[]
nbItemsPerRow: number
enablePlotCreation: boolean
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed since our "Add Custom Plot" action buttons will only appear in the case of there being no custom plots at all.

height: PlotHeight
hasUnfilteredExperiments: boolean
hasAddedPlots: boolean
Expand Down
12 changes: 1 addition & 11 deletions extension/src/plots/webview/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export class WebviewMessages {

private readonly getWebview: () => BaseWebview<TPlotsData> | undefined
private readonly selectPlots: () => Promise<void>
private readonly addCustomPlot: () => Promise<void>

constructor(
dvcRoot: string,
Expand All @@ -50,8 +49,7 @@ export class WebviewMessages {
errors: ErrorsModel,
experiments: Experiments,
getWebview: () => BaseWebview<TPlotsData> | undefined,
selectPlots: () => Promise<void>,
addCustomPlot: () => Promise<void>
selectPlots: () => Promise<void>
) {
this.dvcRoot = dvcRoot
this.paths = paths
Expand All @@ -60,7 +58,6 @@ export class WebviewMessages {
this.experiments = experiments
this.getWebview = getWebview
this.selectPlots = selectPlots
this.addCustomPlot = addCustomPlot
}

public async sendWebviewMessage() {
Expand All @@ -79,8 +76,6 @@ export class WebviewMessages {
RegisteredCommands.ADD_PLOT,
this.dvcRoot
)
case MessageFromWebviewType.ADD_CUSTOM_PLOT:
return this.addCustomPlotFromWebview()
case MessageFromWebviewType.EXPORT_PLOT_DATA_AS_CSV:
return this.exportPlotDataAsCsv(message.payload)
case MessageFromWebviewType.EXPORT_PLOT_DATA_AS_TSV:
Expand Down Expand Up @@ -309,11 +304,6 @@ export class WebviewMessages {
)
}

private addCustomPlotFromWebview() {
void this.addCustomPlot()
sendTelemetryEvent(EventName.VIEWS_PLOTS_CUSTOM_ADD, undefined, undefined)
}

private setExperimentStatus(id: string) {
this.experiments.toggleExperimentStatus(id)
sendTelemetryEvent(
Expand Down
2 changes: 0 additions & 2 deletions extension/src/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export const EventName = Object.assign(
VIEWS_PLOTS_COMPARISON_ROWS_REORDERED:
'views.plots.comparisonRowsReordered',
VIEWS_PLOTS_CREATED: 'views.plots.created',
VIEWS_PLOTS_CUSTOM_ADD: 'views.plots.addCustomPlot',
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',
Expand Down Expand Up @@ -288,7 +287,6 @@ export interface IEventNamePropertyMapping {

[EventName.VIEWS_PLOTS_CLOSED]: undefined
[EventName.VIEWS_PLOTS_CREATED]: undefined
[EventName.VIEWS_PLOTS_CUSTOM_ADD]: undefined
[EventName.VIEWS_PLOTS_FOCUS_CHANGED]: WebviewFocusChangedProperties
[EventName.VIEWS_PLOTS_REVISIONS_REORDERED]: undefined
[EventName.VIEWS_PLOTS_COMPARISON_ROWS_REORDERED]: undefined
Expand Down
1 change: 0 additions & 1 deletion extension/src/test/fixtures/expShow/base/customPlots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ export const experimentsWithCommits: Experiment[] = [
]

const data: CustomPlotsData = {
enablePlotCreation: true,
plots: [
{
id: 'custom-summary.json:loss-params.yaml:log_file',
Expand Down
21 changes: 0 additions & 21 deletions extension/src/test/suite/plots/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1106,27 +1106,6 @@ suite('Plots Test Suite', () => {
)
}).timeout(WEBVIEW_TEST_TIMEOUT)

it('should handle an add custom plot message from the webview', async () => {
const { mockMessageReceived, plots } = await buildPlotsWebview({
disposer: disposable,
plotsDiff: plotsDiffFixture
})

const mockAddCustomPlot = stub(plots, 'addCustomPlot')
const mockSendTelemetryEvent = stub(Telemetry, 'sendTelemetryEvent')

mockMessageReceived.fire({
type: MessageFromWebviewType.ADD_CUSTOM_PLOT
})

expect(mockAddCustomPlot).to.be.calledOnce
expect(mockSendTelemetryEvent).to.be.calledWithExactly(
EventName.VIEWS_PLOTS_CUSTOM_ADD,
undefined,
undefined
)
})

it('should handle a remove custom plot message from the webview', async () => {
const { mockMessageReceived } = await buildPlotsWebview({
disposer: disposable,
Expand Down
4 changes: 0 additions & 4 deletions extension/src/webview/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export enum MessageFromWebviewType {
APPLY_EXPERIMENT_TO_WORKSPACE = 'apply-experiment-to-workspace',
ADD_STARRED_EXPERIMENT_FILTER = 'add-starred-experiment-filter',
ADD_PLOT = 'add-plot',
ADD_CUSTOM_PLOT = 'add-custom-plot',
CREATE_BRANCH_FROM_EXPERIMENT = 'create-branch-from-experiment',
COPY_TO_CLIPBOARD = 'copy-to-clipboard',
COPY_STUDIO_LINK = 'copy-studio-link',
Expand Down Expand Up @@ -108,9 +107,6 @@ export type PlotsTemplatesReordered = {
}[]

export type MessageFromWebview =
| {
type: MessageFromWebviewType.ADD_CUSTOM_PLOT
}
| {
type: MessageFromWebviewType.ADD_PLOT
}
Expand Down
Loading
Loading