Skip to content

Commit

Permalink
add refresh all visible action to plots
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed Jun 1, 2022
1 parent dc5ed6f commit e2b2799
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 23 deletions.
23 changes: 19 additions & 4 deletions extension/src/plots/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,9 @@ export class Plots extends BaseRepository<TPlotsData> {
case MessageFromWebviewType.SELECT_EXPERIMENTS:
return this.selectExperimentsFromWebview()
case MessageFromWebviewType.REFRESH_REVISION:
return this.attemptToRefreshData(message.payload)
return this.attemptToRefreshRevData(message.payload)
case MessageFromWebviewType.REFRESH_REVISIONS:
return this.attemptToRefreshSelectedData(message.payload)
case MessageFromWebviewType.TOGGLE_EXPERIMENT:
return this.setExperimentStatus(message.payload)
default:
Expand Down Expand Up @@ -364,13 +366,26 @@ export class Plots extends BaseRepository<TPlotsData> {
)
}

private attemptToRefreshData(revision: string) {
Toast.infoWithOptions(`Attempting to refresh ${revision} plots data.`)
private attemptToRefreshRevData(revision: string) {
Toast.infoWithOptions(`Attempting to refresh plots data for ${revision}.`)
this.plots?.setupManualRefresh(revision)
this.data.managedUpdate()
sendTelemetryEvent(
EventName.VIEWS_PLOTS_MANUAL_REFRESH,
undefined,
{ revisions: 1 },
undefined
)
}

private attemptToRefreshSelectedData(revisions: string[]) {
Toast.infoWithOptions('Attempting to refresh visible plots data.')
for (const revision of revisions) {
this.plots?.setupManualRefresh(revision)
}
this.data.managedUpdate()
sendTelemetryEvent(
EventName.VIEWS_PLOTS_MANUAL_REFRESH,
{ revisions: revisions.length },
undefined
)
}
Expand Down
2 changes: 1 addition & 1 deletion extension/src/telemetry/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ export interface IEventNamePropertyMapping {
[EventName.VIEWS_PLOTS_CLOSED]: undefined
[EventName.VIEWS_PLOTS_CREATED]: undefined
[EventName.VIEWS_PLOTS_FOCUS_CHANGED]: WebviewFocusChangedProperties
[EventName.VIEWS_PLOTS_MANUAL_REFRESH]: undefined
[EventName.VIEWS_PLOTS_MANUAL_REFRESH]: { revisions: number }
[EventName.VIEWS_PLOTS_METRICS_SELECTED]: undefined
[EventName.VIEWS_PLOTS_RENAME_SECTION]: { section: Section }
[EventName.VIEWS_PLOTS_REVISIONS_REORDERED]: undefined
Expand Down
44 changes: 42 additions & 2 deletions extension/src/test/suite/plots/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ suite('Plots Test Suite', () => {
)
}).timeout(WEBVIEW_TEST_TIMEOUT)

it('should handle a manual refresh message from the webview', async () => {
it('should handle a message to manually refresh a revision from the webview', async () => {
const { data, plots, plotsModel, mockPlotsDiff } = await buildPlots(
disposable,
plotsDiffFixture
Expand Down Expand Up @@ -548,13 +548,53 @@ suite('Plots Test Suite', () => {
expect(mockSendTelemetryEvent).to.be.calledOnce
expect(mockSendTelemetryEvent).to.be.calledWithExactly(
EventName.VIEWS_PLOTS_MANUAL_REFRESH,
undefined,
{ revisions: 1 },
undefined
)
expect(mockPlotsDiff).to.be.calledOnce
expect(mockPlotsDiff).to.be.calledWithExactly(dvcDemoPath, 'main')
}).timeout(WEBVIEW_TEST_TIMEOUT)

it('should handle a message to manually refresh all visible plots from the webview', async () => {
const { data, plots, mockPlotsDiff } = await buildPlots(
disposable,
plotsDiffFixture
)

const webview = await plots.showWebview()
mockPlotsDiff.resetHistory()

const mockSendTelemetryEvent = stub(Telemetry, 'sendTelemetryEvent')
const mockMessageReceived = getMessageReceivedEmitter(webview)

const dataUpdateEvent = new Promise(resolve =>
data.onDidUpdate(() => resolve(undefined))
)

mockMessageReceived.fire({
payload: ['1ba7bcd', '42b8736', '4fb124a', 'main', 'workspace'],
type: MessageFromWebviewType.REFRESH_REVISIONS
})

await dataUpdateEvent

expect(mockSendTelemetryEvent).to.be.calledOnce
expect(mockSendTelemetryEvent).to.be.calledWithExactly(
EventName.VIEWS_PLOTS_MANUAL_REFRESH,
{ revisions: 5 },
undefined
)
expect(mockPlotsDiff).to.be.calledOnce
expect(mockPlotsDiff).to.be.calledWithExactly(
dvcDemoPath,
'1ba7bcd',
'42b8736',
'4fb124a',
'main',
'workspace'
)
}).timeout(WEBVIEW_TEST_TIMEOUT)

it('should be able to make the plots webview visible', async () => {
const { plots, messageSpy, mockPlotsDiff } = await buildPlots(
disposable,
Expand Down
2 changes: 2 additions & 0 deletions extension/src/webview/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export enum MessageFromWebviewType {
REORDER_PLOTS_METRICS = 'reorder-plots-metrics',
REORDER_PLOTS_TEMPLATES = 'reorder-plots-templates',
REFRESH_REVISION = 'refresh-revision',
REFRESH_REVISIONS = 'refresh-revisions',
RESIZE_COLUMN = 'resize-column',
RESIZE_PLOTS = 'resize-plots',
SORT_COLUMN = 'sort-column',
Expand Down Expand Up @@ -132,6 +133,7 @@ export type MessageFromWebview =
| { type: MessageFromWebviewType.SELECT_EXPERIMENTS }
| { type: MessageFromWebviewType.SELECT_PLOTS }
| { type: MessageFromWebviewType.REFRESH_REVISION; payload: string }
| { type: MessageFromWebviewType.REFRESH_REVISIONS; payload: string[] }
| { type: MessageFromWebviewType.SELECT_COLUMNS }

export type MessageToWebview<T extends WebviewData> = {
Expand Down
15 changes: 7 additions & 8 deletions webview/src/plots/components/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1609,7 +1609,7 @@ describe('App', () => {
})
})

it('should send messages to refresh each revision when clicking the refresh all button', () => {
it('should send a message to refresh each revision when clicking the refresh all button', () => {
renderAppWithData({
comparison: comparisonTableFixture,
sectionCollapsed: DEFAULT_SECTION_COLLAPSED
Expand All @@ -1619,15 +1619,14 @@ describe('App', () => {
screen.getByTestId('ribbon')
).getAllByRole('button')[1]

mockPostMessage.mockReset()
fireEvent.click(refreshAllButton)

expect(mockPostMessage).toHaveBeenNthCalledWith(
comparisonTableFixture.revisions.length,
{
payload: expect.any(String),
type: MessageFromWebviewType.REFRESH_REVISION
}
)
expect(mockPostMessage).toHaveBeenCalledTimes(1)
expect(mockPostMessage).toBeCalledWith({
payload: ['workspace', 'main', '4fb124a', '42b8736', '1ba7bcd'],
type: MessageFromWebviewType.REFRESH_REVISIONS
})
})

describe('Copy button', () => {
Expand Down
13 changes: 5 additions & 8 deletions webview/src/plots/components/ribbon/Ribbon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@ export const Ribbon: React.FC<RibbonProps> = ({ revisions }) => {
})
}

const refreshRevisions = () => {
for (const revision of revisions) {
sendMessage({
payload: revision.revision,
type: MessageFromWebviewType.REFRESH_REVISION
})
}
}
const refreshRevisions = () =>
sendMessage({
payload: revisions.map(({ revision }) => revision),
type: MessageFromWebviewType.REFRESH_REVISIONS
})

const selectRevisions = () => {
sendMessage({
Expand Down

0 comments on commit e2b2799

Please sign in to comment.