Skip to content

Commit

Permalink
Remove code that refreshes a single plot revision (no longer possible) (
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon authored Apr 2, 2023
1 parent 0fc62cc commit c0443af
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 110 deletions.
20 changes: 3 additions & 17 deletions extension/src/plots/webview/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,8 @@ export class WebviewMessages {
return this.selectExperimentsFromWebview()
case MessageFromWebviewType.REMOVE_CUSTOM_PLOTS:
return this.removeCustomPlots()
case MessageFromWebviewType.REFRESH_REVISION:
return this.attemptToRefreshRevData(message.payload)
case MessageFromWebviewType.REFRESH_REVISIONS:
return this.attemptToRefreshSelectedData(message.payload)
return this.refreshData()
case MessageFromWebviewType.TOGGLE_EXPERIMENT:
return this.setExperimentStatus(message.payload)
case MessageFromWebviewType.ZOOM_PLOT:
Expand Down Expand Up @@ -326,24 +324,12 @@ export class WebviewMessages {
)
}

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

private attemptToRefreshSelectedData(revisions: string[]) {
private refreshData() {
void Toast.infoWithOptions('Attempting to refresh visible plots data.')
void this.updateData()
sendTelemetryEvent(
EventName.VIEWS_PLOTS_MANUAL_REFRESH,
{ revisions: revisions.length },
undefined,
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 @@ -243,7 +243,7 @@ export interface IEventNamePropertyMapping {
[EventName.VIEWS_PLOTS_CUSTOM_PLOT_REMOVED]: undefined
[EventName.VIEWS_PLOTS_CUSTOM_PLOT_ADDED]: undefined
[EventName.VIEWS_PLOTS_FOCUS_CHANGED]: WebviewFocusChangedProperties
[EventName.VIEWS_PLOTS_MANUAL_REFRESH]: { revisions: number }
[EventName.VIEWS_PLOTS_MANUAL_REFRESH]: undefined
[EventName.VIEWS_PLOTS_REVISIONS_REORDERED]: undefined
[EventName.VIEWS_PLOTS_COMPARISON_ROWS_REORDERED]: undefined
[EventName.VIEWS_PLOTS_SECTION_RESIZED]: {
Expand Down
51 changes: 2 additions & 49 deletions extension/src/test/suite/plots/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -601,47 +601,7 @@ suite('Plots Test Suite', () => {
)
}).timeout(WEBVIEW_TEST_TIMEOUT)

it('should handle a message to manually refresh a revision 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: 'main',
type: MessageFromWebviewType.REFRESH_REVISION
})

await dataUpdateEvent

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

it('should handle a message to manually refresh all visible plots from the webview', async () => {
it('should handle a message to manually refresh plot revisions from the webview', async () => {
const { data, plots, mockPlotsDiff, messageSpy } = await buildPlots(
disposable,
plotsDiffFixture
Expand All @@ -661,13 +621,6 @@ suite('Plots Test Suite', () => {
)

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

Expand All @@ -676,7 +629,7 @@ suite('Plots Test Suite', () => {
expect(mockSendTelemetryEvent).to.be.calledOnce
expect(mockSendTelemetryEvent).to.be.calledWithExactly(
EventName.VIEWS_PLOTS_MANUAL_REFRESH,
{ revisions: 5 },
undefined,
undefined
)
expect(mockPlotsDiff).to.be.called
Expand Down
3 changes: 1 addition & 2 deletions extension/src/webview/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,7 @@ export type MessageFromWebview =
| { type: MessageFromWebviewType.SELECT_EXPERIMENTS }
| { type: MessageFromWebviewType.SELECT_PYTHON_INTERPRETER }
| { type: MessageFromWebviewType.SELECT_PLOTS }
| { type: MessageFromWebviewType.REFRESH_REVISION; payload: string }
| { type: MessageFromWebviewType.REFRESH_REVISIONS; payload: string[] }
| { type: MessageFromWebviewType.REFRESH_REVISIONS }
| { type: MessageFromWebviewType.SELECT_COLUMNS }
| { type: MessageFromWebviewType.FOCUS_FILTERS_TREE }
| { type: MessageFromWebviewType.FOCUS_SORTS_TREE }
Expand Down
7 changes: 0 additions & 7 deletions webview/src/plots/components/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1874,13 +1874,6 @@ describe('App', () => {

expect(mockPostMessage).toHaveBeenCalledTimes(1)
expect(mockPostMessage).toHaveBeenCalledWith({
payload: [
EXPERIMENT_WORKSPACE_ID,
'main',
'4fb124a',
'42b8736',
'1ba7bcd'
],
type: MessageFromWebviewType.REFRESH_REVISIONS
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,7 @@ describe('ComparisonTable', () => {
fireEvent.click(button)
expect(mockPostMessage).toHaveBeenCalledTimes(1)
expect(mockPostMessage).toHaveBeenCalledWith({
payload: revisionWithNoData,
type: MessageFromWebviewType.REFRESH_REVISION
type: MessageFromWebviewType.REFRESH_REVISIONS
})
mockPostMessage.mockReset()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import React from 'react'
import { MessageFromWebviewType } from 'dvc/src/webview/contract'
import { ComparisonPlot } from 'dvc/src/plots/webview/contract'
import styles from './styles.module.scss'
import { RefreshButton } from '../../../shared/components/button/RefreshButton'
import { sendMessage } from '../../../shared/vscode'
import { zoomPlot } from '../messages'
import { refreshRevisions, zoomPlot } from '../messages'
import { Error } from '../../../shared/components/icons'
import { ErrorTooltip } from '../../../shared/components/tooltip/ErrorTooltip'

Expand All @@ -22,14 +20,7 @@ const MissingPlotTableCell: React.FC<{ plot: ComparisonPlot }> = ({ plot }) => (
<Error height={48} width={48} className={styles.errorIcon} />
</div>
</ErrorTooltip>
<RefreshButton
onClick={() =>
sendMessage({
payload: plot.revision,
type: MessageFromWebviewType.REFRESH_REVISION
})
}
/>
<RefreshButton onClick={refreshRevisions} />
</>
) : (
<p className={styles.emptyIcon}>-</p>
Expand Down
18 changes: 18 additions & 0 deletions webview/src/plots/components/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,21 @@ import { sendMessage } from '../../shared/vscode'

export const zoomPlot = (imagePath?: string) =>
sendMessage({ payload: imagePath, type: MessageFromWebviewType.ZOOM_PLOT })

export const removeRevision = (revision: string) => {
sendMessage({
payload: revision,
type: MessageFromWebviewType.TOGGLE_EXPERIMENT
})
}

export const refreshRevisions = () =>
sendMessage({
type: MessageFromWebviewType.REFRESH_REVISIONS
})

export const selectRevisions = () => {
sendMessage({
type: MessageFromWebviewType.SELECT_EXPERIMENTS
})
}
22 changes: 1 addition & 21 deletions webview/src/plots/components/ribbon/Ribbon.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import cx from 'classnames'
import { MessageFromWebviewType } from 'dvc/src/webview/contract'
import React, { useCallback, useEffect, useRef } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { useInView } from 'react-intersection-observer'
import styles from './styles.module.scss'
import { RibbonBlock } from './RibbonBlock'
import { update } from './ribbonSlice'
import { sendMessage } from '../../../shared/vscode'
import { IconButton } from '../../../shared/components/button/IconButton'
import { PlotsState } from '../../store'
import { Lines, Refresh } from '../../../shared/components/icons'
import { refreshRevisions, removeRevision, selectRevisions } from '../messages'

const MAX_NB_EXP = 7

Expand Down Expand Up @@ -45,25 +44,6 @@ export const Ribbon: React.FC = () => {
}
}, [changeRibbonHeight])

const removeRevision = (revision: string) => {
sendMessage({
payload: revision,
type: MessageFromWebviewType.TOGGLE_EXPERIMENT
})
}

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

const selectRevisions = () => {
sendMessage({
type: MessageFromWebviewType.SELECT_EXPERIMENTS
})
}

return (
<ul
ref={node => {
Expand Down

0 comments on commit c0443af

Please sign in to comment.