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

Rename section enums to differentiate types #3470

Merged
merged 2 commits into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions extension/src/cli/dvc/discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
import { getPythonBinPath } from '../../extensions/python'
import { getFirstWorkspaceFolder } from '../../vscode/workspaceFolders'
import { delay } from '../../util/time'
import { Section } from '../../setup/webview/contract'
import { SetupSection } from '../../setup/webview/contract'

export const warnUnableToVerifyVersion = () =>
Toast.warnWithOptions(
Expand Down Expand Up @@ -53,7 +53,7 @@ const warnUserCLIInaccessible = async (

switch (response) {
case Response.SHOW_SETUP:
return setup.showSetup(Section.EXPERIMENTS)
return setup.showSetup(SetupSection.EXPERIMENTS)
case Response.NEVER:
return setUserConfigValue(ConfigKey.DO_NOT_SHOW_CLI_UNAVAILABLE, true)
}
Expand Down
4 changes: 2 additions & 2 deletions extension/src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Section } from './setup/webview/contract'
import { SetupSection } from './setup/webview/contract'

export interface IExtensionSetup {
getCliVersion: (
Expand All @@ -9,7 +9,7 @@ export interface IExtensionSetup {
hasRoots: () => boolean
isPythonExtensionUsed: () => Promise<boolean>

showSetup: (focusedSection?: Section) => void
showSetup: (focusedSection?: SetupSection) => void
shouldWarnUserIfCLIUnavailable: () => boolean

initialize: () => Promise<void[]>
Expand Down
24 changes: 13 additions & 11 deletions extension/src/plots/model/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
DEFAULT_NB_ITEMS_PER_ROW,
DEFAULT_SECTION_COLLAPSED,
DEFAULT_SECTION_NB_ITEMS_PER_ROW,
Section
PlotsSection
} from '../webview/contract'
import { buildMockMemento } from '../../test/util'
import { Experiments } from '../../experiments'
Expand Down Expand Up @@ -68,26 +68,28 @@ describe('plotsModel', () => {
})

it('should change the plotSize when calling setPlotSize', () => {
expect(model.getNbItemsPerRow(Section.CHECKPOINT_PLOTS)).toStrictEqual(
expect(model.getNbItemsPerRow(PlotsSection.CHECKPOINT_PLOTS)).toStrictEqual(
DEFAULT_NB_ITEMS_PER_ROW
)

model.setNbItemsPerRow(Section.CHECKPOINT_PLOTS, 1)
model.setNbItemsPerRow(PlotsSection.CHECKPOINT_PLOTS, 1)

expect(model.getNbItemsPerRow(Section.CHECKPOINT_PLOTS)).toStrictEqual(1)
expect(model.getNbItemsPerRow(PlotsSection.CHECKPOINT_PLOTS)).toStrictEqual(
1
)
})

it('should update the persisted plot size when calling setPlotSize', () => {
const mementoUpdateSpy = jest.spyOn(memento, 'update')

model.setNbItemsPerRow(Section.CHECKPOINT_PLOTS, 2)
model.setNbItemsPerRow(PlotsSection.CHECKPOINT_PLOTS, 2)

expect(mementoUpdateSpy).toHaveBeenCalledTimes(1)
expect(mementoUpdateSpy).toHaveBeenCalledWith(
PersistenceKey.PLOT_NB_ITEMS_PER_ROW + exampleDvcRoot,
{
...DEFAULT_SECTION_NB_ITEMS_PER_ROW,
[Section.CHECKPOINT_PLOTS]: 2
[PlotsSection.CHECKPOINT_PLOTS]: 2
}
)
})
Expand All @@ -97,13 +99,13 @@ describe('plotsModel', () => {

expect(model.getSectionCollapsed()).toStrictEqual(DEFAULT_SECTION_COLLAPSED)

model.setSectionCollapsed({ [Section.CHECKPOINT_PLOTS]: true })
model.setSectionCollapsed({ [PlotsSection.CHECKPOINT_PLOTS]: true })

const expectedSectionCollapsed = {
[Section.CHECKPOINT_PLOTS]: true,
[Section.TEMPLATE_PLOTS]: false,
[Section.CUSTOM_PLOTS]: false,
[Section.COMPARISON_TABLE]: false
[PlotsSection.CHECKPOINT_PLOTS]: true,
[PlotsSection.TEMPLATE_PLOTS]: false,
[PlotsSection.CUSTOM_PLOTS]: false,
[PlotsSection.COMPARISON_TABLE]: false
}

expect(mementoUpdateSpy).toHaveBeenCalledTimes(1)
Expand Down
30 changes: 15 additions & 15 deletions extension/src/plots/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
ComparisonRevisionData,
DEFAULT_SECTION_COLLAPSED,
DEFAULT_SECTION_NB_ITEMS_PER_ROW,
Section,
PlotsSection,
SectionCollapsed,
CustomPlotData,
DEFAULT_HEIGHT,
Expand Down Expand Up @@ -56,8 +56,8 @@ export type CustomPlotsOrderValue = { metric: string; param: string }
export class PlotsModel extends ModelWithPersistence {
private readonly experiments: Experiments

private nbItemsPerRow: Record<Section, number>
private height: Record<Section, PlotHeight>
private nbItemsPerRow: Record<PlotsSection, number>
private height: Record<PlotsSection, PlotHeight>
private customPlotsOrder: CustomPlotsOrderValue[]
private sectionCollapsed: SectionCollapsed
private commitRevisions: Record<string, string> = {}
Expand Down Expand Up @@ -182,8 +182,8 @@ export class PlotsModel extends ModelWithPersistence {

return {
colors,
height: this.getHeight(Section.CHECKPOINT_PLOTS),
nbItemsPerRow: this.getNbItemsPerRow(Section.CHECKPOINT_PLOTS),
height: this.getHeight(PlotsSection.CHECKPOINT_PLOTS),
nbItemsPerRow: this.getNbItemsPerRow(PlotsSection.CHECKPOINT_PLOTS),
plots: this.getPlots(this.checkpointPlots, selectedExperiments),
selectedMetrics: this.getSelectedMetrics()
}
Expand All @@ -194,8 +194,8 @@ export class PlotsModel extends ModelWithPersistence {
return
}
return {
height: this.getHeight(Section.CUSTOM_PLOTS),
nbItemsPerRow: this.getNbItemsPerRow(Section.CUSTOM_PLOTS),
height: this.getHeight(PlotsSection.CUSTOM_PLOTS),
nbItemsPerRow: this.getNbItemsPerRow(PlotsSection.CUSTOM_PLOTS),
plots: this.customPlots
}
}
Expand Down Expand Up @@ -403,24 +403,24 @@ export class PlotsModel extends ModelWithPersistence {
this.persist(PersistenceKey.PLOT_METRIC_ORDER, this.metricOrder)
}

public setNbItemsPerRow(section: Section, nbItemsPerRow: number) {
public setNbItemsPerRow(section: PlotsSection, nbItemsPerRow: number) {
this.nbItemsPerRow[section] = nbItemsPerRow
this.persist(PersistenceKey.PLOT_NB_ITEMS_PER_ROW, this.nbItemsPerRow)
}

public getNbItemsPerRow(section: Section) {
public getNbItemsPerRow(section: PlotsSection) {
if (this.nbItemsPerRow[section]) {
return this.nbItemsPerRow[section]
}
return DEFAULT_NB_ITEMS_PER_ROW
}

public setHeight(section: Section, height: PlotHeight) {
public setHeight(section: PlotsSection, height: PlotHeight) {
this.height[section] = height
this.persist(PersistenceKey.PLOT_HEIGHT, this.height)
}

public getHeight(section: Section) {
public getHeight(section: PlotsSection) {
return this.height[section]
}

Expand Down Expand Up @@ -511,8 +511,8 @@ export class PlotsModel extends ModelWithPersistence {
id,
title: truncateVerticalTitle(
id,
this.getNbItemsPerRow(Section.CHECKPOINT_PLOTS),
this.getHeight(Section.CHECKPOINT_PLOTS)
this.getNbItemsPerRow(PlotsSection.CHECKPOINT_PLOTS),
this.getHeight(PlotsSection.CHECKPOINT_PLOTS)
) as string,
values: values.filter(value =>
selectedExperiments.includes(value.group)
Expand Down Expand Up @@ -563,8 +563,8 @@ export class PlotsModel extends ModelWithPersistence {
selectedRevisions.map(({ revision }) => revision),
this.templates,
this.revisionData,
this.getNbItemsPerRow(Section.TEMPLATE_PLOTS),
this.getHeight(Section.TEMPLATE_PLOTS),
this.getNbItemsPerRow(PlotsSection.TEMPLATE_PLOTS),
this.getHeight(PlotsSection.TEMPLATE_PLOTS),
this.getRevisionColors(selectedRevisions),
this.multiSourceEncoding
)
Expand Down
26 changes: 13 additions & 13 deletions extension/src/plots/webview/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,32 @@ export enum PlotHeight {

export const DEFAULT_PLOT_HEIGHT = PlotHeight.SMALL

export enum Section {
export enum PlotsSection {
CHECKPOINT_PLOTS = 'checkpoint-plots',
TEMPLATE_PLOTS = 'template-plots',
COMPARISON_TABLE = 'comparison-table',
CUSTOM_PLOTS = 'custom-plots'
}

export const DEFAULT_SECTION_NB_ITEMS_PER_ROW = {
[Section.CHECKPOINT_PLOTS]: DEFAULT_NB_ITEMS_PER_ROW,
[Section.TEMPLATE_PLOTS]: DEFAULT_NB_ITEMS_PER_ROW,
[Section.COMPARISON_TABLE]: DEFAULT_NB_ITEMS_PER_ROW,
[Section.CUSTOM_PLOTS]: DEFAULT_NB_ITEMS_PER_ROW
[PlotsSection.CHECKPOINT_PLOTS]: DEFAULT_NB_ITEMS_PER_ROW,
[PlotsSection.TEMPLATE_PLOTS]: DEFAULT_NB_ITEMS_PER_ROW,
[PlotsSection.COMPARISON_TABLE]: DEFAULT_NB_ITEMS_PER_ROW,
[PlotsSection.CUSTOM_PLOTS]: DEFAULT_NB_ITEMS_PER_ROW
}

export const DEFAULT_HEIGHT = {
[Section.CHECKPOINT_PLOTS]: DEFAULT_PLOT_HEIGHT,
[Section.TEMPLATE_PLOTS]: DEFAULT_PLOT_HEIGHT,
[Section.COMPARISON_TABLE]: DEFAULT_PLOT_HEIGHT,
[Section.CUSTOM_PLOTS]: DEFAULT_PLOT_HEIGHT
[PlotsSection.CHECKPOINT_PLOTS]: DEFAULT_PLOT_HEIGHT,
[PlotsSection.TEMPLATE_PLOTS]: DEFAULT_PLOT_HEIGHT,
[PlotsSection.COMPARISON_TABLE]: DEFAULT_PLOT_HEIGHT,
[PlotsSection.CUSTOM_PLOTS]: DEFAULT_PLOT_HEIGHT
}

export const DEFAULT_SECTION_COLLAPSED = {
[Section.CHECKPOINT_PLOTS]: false,
[Section.TEMPLATE_PLOTS]: false,
[Section.COMPARISON_TABLE]: false,
[Section.CUSTOM_PLOTS]: false
[PlotsSection.CHECKPOINT_PLOTS]: false,
[PlotsSection.TEMPLATE_PLOTS]: false,
[PlotsSection.COMPARISON_TABLE]: false,
[PlotsSection.CUSTOM_PLOTS]: false
}

export type SectionCollapsed = typeof DEFAULT_SECTION_COLLAPSED
Expand Down
20 changes: 10 additions & 10 deletions extension/src/plots/webview/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
PlotHeight,
PlotsData as TPlotsData,
Revision,
Section,
PlotsSection,
SectionCollapsed
} from './contract'
import { Logger } from '../../common/logger'
Expand Down Expand Up @@ -128,7 +128,7 @@ export class WebviewMessages {
}

private setPlotSize(
section: Section,
section: PlotsSection,
nbItemsPerRow: number,
height: PlotHeight
) {
Expand All @@ -141,16 +141,16 @@ export class WebviewMessages {
)

switch (section) {
case Section.CHECKPOINT_PLOTS:
case PlotsSection.CHECKPOINT_PLOTS:
this.sendCheckpointPlotsMessage()
break
case Section.COMPARISON_TABLE:
case PlotsSection.COMPARISON_TABLE:
this.sendComparisonPlots()
break
case Section.CUSTOM_PLOTS:
case PlotsSection.CUSTOM_PLOTS:
this.sendCustomPlots()
break
case Section.TEMPLATE_PLOTS:
case PlotsSection.TEMPLATE_PLOTS:
this.sendTemplatePlots()
break
default:
Expand Down Expand Up @@ -367,8 +367,8 @@ export class WebviewMessages {
}

return {
height: this.plots.getHeight(Section.TEMPLATE_PLOTS),
nbItemsPerRow: this.plots.getNbItemsPerRow(Section.TEMPLATE_PLOTS),
height: this.plots.getHeight(PlotsSection.TEMPLATE_PLOTS),
nbItemsPerRow: this.plots.getNbItemsPerRow(PlotsSection.TEMPLATE_PLOTS),
plots
}
}
Expand All @@ -384,8 +384,8 @@ export class WebviewMessages {
}

return {
height: this.plots.getHeight(Section.COMPARISON_TABLE),
nbItemsPerRow: this.plots.getNbItemsPerRow(Section.COMPARISON_TABLE),
height: this.plots.getHeight(PlotsSection.COMPARISON_TABLE),
nbItemsPerRow: this.plots.getNbItemsPerRow(PlotsSection.COMPARISON_TABLE),
plots: comparison.map(({ path, revisions }) => {
return { path, revisions: this.getRevisionsWithCorrectUrls(revisions) }
}),
Expand Down
6 changes: 3 additions & 3 deletions extension/src/setup/collect.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DEFAULT_SECTION_COLLAPSED, Section } from './webview/contract'
import { DEFAULT_SECTION_COLLAPSED, SetupSection } from './webview/contract'

export const collectSectionCollapsed = (
focusedSection?: Section
focusedSection?: SetupSection
): typeof DEFAULT_SECTION_COLLAPSED | undefined => {
if (!focusedSection) {
return undefined
Expand All @@ -10,7 +10,7 @@ export const collectSectionCollapsed = (
const acc = { ...DEFAULT_SECTION_COLLAPSED }
for (const section of Object.keys(acc)) {
if (section !== focusedSection) {
acc[section as Section] = true
acc[section as SetupSection] = true
}
}

Expand Down
6 changes: 3 additions & 3 deletions extension/src/setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from 'vscode'
import { Disposable, Disposer } from '@hediet/std/disposable'
import isEmpty from 'lodash.isempty'
import { Section, SetupData as TSetupData } from './webview/contract'
import { SetupSection, SetupData as TSetupData } from './webview/contract'
import { collectSectionCollapsed } from './collect'
import { WebviewMessages } from './webview/messages'
import { validateTokenInput } from './inputBox'
Expand Down Expand Up @@ -91,7 +91,7 @@ export class Setup
private studioAccessToken: string | undefined = undefined
private studioIsConnected = false

private focusedSection: Section | undefined = undefined
private focusedSection: SetupSection | undefined = undefined

constructor(
context: ExtensionContext,
Expand Down Expand Up @@ -211,7 +211,7 @@ export class Setup
this.config.unsetPythonBinPath()
}

public async showSetup(focusSection?: Section) {
public async showSetup(focusSection?: SetupSection) {
this.focusedSection = focusSection
if (this.webview) {
void this.sendDataToWebview()
Expand Down
6 changes: 3 additions & 3 deletions extension/src/setup/register.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { commands } from 'vscode'
import { Setup } from '.'
import { run } from './runner'
import { Section } from './webview/contract'
import { SetupSection } from './webview/contract'
import { AvailableCommands, InternalCommands } from '../commands/internal'
import { RegisteredCliCommands, RegisteredCommands } from '../commands/external'
import { getFirstWorkspaceFolder } from '../vscode/workspaceFolders'
Expand Down Expand Up @@ -40,14 +40,14 @@ const registerSetupShowCommands = (
internalCommands.registerExternalCommand(
RegisteredCommands.SETUP_SHOW_EXPERIMENTS,
async () => {
await setup.showSetup(Section.EXPERIMENTS)
await setup.showSetup(SetupSection.EXPERIMENTS)
}
)

internalCommands.registerExternalCommand(
RegisteredCommands.SETUP_SHOW_STUDIO,
async () => {
await setup.showSetup(Section.STUDIO)
await setup.showSetup(SetupSection.STUDIO)
}
)
}
Expand Down
6 changes: 3 additions & 3 deletions extension/src/setup/webview/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export type SetupData = {
shareLiveToStudio: boolean
}

export enum Section {
export enum SetupSection {
EXPERIMENTS = 'experiments',
STUDIO = 'studio'
}

export const DEFAULT_SECTION_COLLAPSED = {
[Section.EXPERIMENTS]: false,
[Section.STUDIO]: false
[SetupSection.EXPERIMENTS]: false,
[SetupSection.STUDIO]: false
}

export type SectionCollapsed = typeof DEFAULT_SECTION_COLLAPSED
Expand Down
Loading