Skip to content

Commit

Permalink
Merge branch 'main' into make-method-protected
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon authored Apr 27, 2023
2 parents 5d20e4c + 4f4c7e5 commit 226f6f1
Show file tree
Hide file tree
Showing 34 changed files with 806 additions and 406 deletions.
2 changes: 1 addition & 1 deletion extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,7 @@
"mock-require": "3.0.3",
"process-exists": "4.1.0",
"shx": "0.3.4",
"sinon": "15.0.3",
"sinon": "15.0.4",
"sinon-chai": "3.7.0",
"ts-loader": "9.4.2",
"vscode-uri": "3.0.7",
Expand Down
56 changes: 42 additions & 14 deletions extension/src/setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import {
} from 'vscode'
import { Disposable, Disposer } from '@hediet/std/disposable'
import isEmpty from 'lodash.isempty'
import { SetupSection, SetupData as TSetupData } from './webview/contract'
import {
DvcCliDetails,
SetupSection,
SetupData as TSetupData
} from './webview/contract'
import { collectSectionCollapsed } from './collect'
import { WebviewMessages } from './webview/messages'
import { validateTokenInput } from './inputBox'
Expand All @@ -20,7 +24,6 @@ import { BaseWebview } from '../webview'
import { ViewKey } from '../webview/constants'
import { BaseRepository } from '../webview/repository'
import { Resource } from '../resourceLocator'
import { isPythonExtensionInstalled } from '../extensions/python'
import {
findAbsoluteDvcRootPath,
findDvcRootPaths,
Expand Down Expand Up @@ -52,6 +55,7 @@ import { GLOBAL_WEBVIEW_DVCROOT } from '../webview/factory'
import { ConfigKey, getConfigValue } from '../vscode/config'
import { getValidInput } from '../vscode/inputBox'
import { Title } from '../vscode/title'
import { getOptions } from '../cli/dvc/options'

export type SetupWebviewWebview = BaseWebview<TSetupData>

Expand Down Expand Up @@ -334,10 +338,34 @@ export class Setup
return this.sendDataToWebview()
}

public async getDvcCliDetails(): Promise<DvcCliDetails> {
const dvcPath = this.config.getCliPath()
const pythonBinPath = this.config.getPythonBinPath()
const cwd = getFirstWorkspaceFolder()

const { args, executable } = getOptions(pythonBinPath, dvcPath, cwd || '')
const commandArgs = args.length === 0 ? '' : ` ${args.join(' ')}`
const command = executable + commandArgs

return {
command,
version: cwd ? await this.getCliVersion(cwd) : undefined
}
}

private isDVCBeingUsedGlobally() {
const dvcPath = this.config.getCliPath()
const pythonBinPath = this.config.getPythonBinPath()

return dvcPath || !pythonBinPath
}

private async sendDataToWebview() {
const projectInitialized = this.hasRoots()
const hasData = this.getHasData()

const isPythonExtensionUsed = await this.isPythonExtensionUsed()

const needsGitInitialized =
!projectInitialized && !!(await this.needsGitInit())

Expand All @@ -348,11 +376,15 @@ export class Setup

const pythonBinPath = await findPythonBinForInstall()

const dvcCliDetails = await this.getDvcCliDetails()

this.webviewMessages.sendWebviewMessage({
canGitInitialize,
cliCompatible: this.cliCompatible,
dvcCliDetails,
hasData,
isPythonExtensionInstalled: isPythonExtensionInstalled(),
isPythonExtensionUsed:
!this.isDVCBeingUsedGlobally() && isPythonExtensionUsed,
isStudioConnected: this.studioIsConnected,
needsGitCommit,
needsGitInitialized,
Expand Down Expand Up @@ -546,21 +578,17 @@ export class Setup
}

private watchDotFolderForChanges() {
const cwd = getFirstWorkspaceFolder()

if (!cwd) {
return
}

const disposer = Disposable.fn()
this.dotFolderWatcher = disposer
this.dispose.track(this.dotFolderWatcher)

return createFileSystemWatcher(
disposable => disposer.track(disposable),
getRelativePattern(cwd, '**'),
path => this.dotFolderListener(disposer, path)
)
for (const workspaceFolder of getWorkspaceFolders()) {
createFileSystemWatcher(
disposable => disposer.track(disposable),
getRelativePattern(workspaceFolder, '**'),
path => this.dotFolderListener(disposer, path)
)
}
}

private dotFolderListener(disposer: Disposer, path: string) {
Expand Down
8 changes: 7 additions & 1 deletion extension/src/setup/webview/contract.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
export type DvcCliDetails = {
command: string
version: string | undefined
}

export type SetupData = {
canGitInitialize: boolean
cliCompatible: boolean | undefined
dvcCliDetails: DvcCliDetails
hasData: boolean | undefined
isPythonExtensionInstalled: boolean
isPythonExtensionUsed: boolean
isStudioConnected: boolean
needsGitCommit: boolean
needsGitInitialized: boolean | undefined
Expand Down
6 changes: 4 additions & 2 deletions extension/src/setup/webview/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ export class WebviewMessages {
public sendWebviewMessage({
canGitInitialize,
cliCompatible,
dvcCliDetails,
hasData,
isPythonExtensionInstalled,
isPythonExtensionUsed,
isStudioConnected,
needsGitCommit,
needsGitInitialized,
Expand All @@ -48,8 +49,9 @@ export class WebviewMessages {
void this.getWebview()?.show({
canGitInitialize,
cliCompatible,
dvcCliDetails,
hasData,
isPythonExtensionInstalled,
isPythonExtensionUsed,
isStudioConnected,
needsGitCommit,
needsGitInitialized,
Expand Down
8 changes: 3 additions & 5 deletions extension/src/test/e2e/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ describe('Experiments Table Webview', function () {
const headerRows = 3
const workspaceRow = 1
const commitRows = 3
const previousCommitRow = 1
const actionsRow = 1
const initialRows =
headerRows + workspaceRow + commitRows + previousCommitRow + actionsRow
const branchRow = 1
const initialRows = headerRows + workspaceRow + commitRows + branchRow

it('should load as an editor', async function () {
const workbench = await browser.getWorkbench()
Expand Down Expand Up @@ -109,7 +107,7 @@ describe('Experiments Table Webview', function () {

const currentRows = await webview.row$$

const newRow = currentRows[headerRows + workspaceRow + 1]
const newRow = currentRows[headerRows + workspaceRow + branchRow + 1]

const experimentName = (await webview.getExperimentName(newRow)) as string

Expand Down
22 changes: 18 additions & 4 deletions extension/src/test/suite/setup/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ suite('Setup Test Suite', () => {
setup.setCliCompatible(undefined)
setup.setAvailable(false)
await setup.setRoots()
stub(setup, 'getCliVersion').resolves(undefined)

messageSpy.restore()
const mockSendMessage = stub(BaseWebview.prototype, 'show')
Expand All @@ -238,8 +239,9 @@ suite('Setup Test Suite', () => {
expect(mockSendMessage).to.be.calledWithExactly({
canGitInitialize: true,
cliCompatible: undefined,
dvcCliDetails: { command: 'dvc', version: undefined },
hasData: false,
isPythonExtensionInstalled: false,
isPythonExtensionUsed: false,
isStudioConnected: false,
needsGitCommit: true,
needsGitInitialized: true,
Expand Down Expand Up @@ -278,8 +280,9 @@ suite('Setup Test Suite', () => {
expect(mockSendMessage).to.be.calledWithExactly({
canGitInitialize: true,
cliCompatible: true,
dvcCliDetails: { command: 'dvc', version: MIN_CLI_VERSION },
hasData: false,
isPythonExtensionInstalled: false,
isPythonExtensionUsed: false,
isStudioConnected: false,
needsGitCommit: true,
needsGitInitialized: true,
Expand Down Expand Up @@ -324,8 +327,12 @@ suite('Setup Test Suite', () => {
expect(mockSendMessage).to.be.calledWithExactly({
canGitInitialize: false,
cliCompatible: true,
dvcCliDetails: {
command: 'dvc',
version: MIN_CLI_VERSION
},
hasData: false,
isPythonExtensionInstalled: false,
isPythonExtensionUsed: false,
isStudioConnected: false,
needsGitCommit: false,
needsGitInitialized: false,
Expand Down Expand Up @@ -370,8 +377,12 @@ suite('Setup Test Suite', () => {
expect(mockSendMessage).to.be.calledWithExactly({
canGitInitialize: false,
cliCompatible: true,
dvcCliDetails: {
command: 'dvc',
version: MIN_CLI_VERSION
},
hasData: false,
isPythonExtensionInstalled: false,
isPythonExtensionUsed: false,
isStudioConnected: false,
needsGitCommit: true,
needsGitInitialized: false,
Expand Down Expand Up @@ -568,6 +579,7 @@ suite('Setup Test Suite', () => {
mockRunSetup.restore()
stub(config, 'isPythonExtensionUsed').returns(false)
stub(config, 'getPythonBinPath').resolves(join('python'))
stub(setup, 'getDvcCliDetails').resolves(undefined)

mockVersion.resetBehavior()
mockVersion
Expand Down Expand Up @@ -627,6 +639,7 @@ suite('Setup Test Suite', () => {
mockExecuteCommand.restore()
mockRunSetup.restore()
stub(config, 'isPythonExtensionUsed').returns(true)
stub(setup, 'getDvcCliDetails').resolves(undefined)

mockVersion.resetBehavior()
mockVersion.rejects(new Error('no CLI here'))
Expand Down Expand Up @@ -762,6 +775,7 @@ suite('Setup Test Suite', () => {
const mockUpdate = stub()

stub(workspace, 'getConfiguration').returns({
get: stub(),
update: mockUpdate
} as unknown as WorkspaceConfiguration)

Expand Down

This file was deleted.

14 changes: 0 additions & 14 deletions webview/src/experiments/components/table/body/TableBody.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import React from 'react'
import { useSelector } from 'react-redux'
import cx from 'classnames'
import { EXPERIMENT_WORKSPACE_ID } from 'dvc/src/cli/dvc/contract'
import { ExperimentGroup } from './ExperimentGroup'
import { BatchSelectionProp, RowContent } from './Row'
import { WorkspaceRowGroup } from './WorkspaceRowGroup'
import { PreviousCommitsRow } from './PreviousCommitsRow'
import styles from '../styles.module.scss'
import { InstanceProp, RowProp } from '../../../util/interfaces'
import { ExperimentsState } from '../../../store'

interface TableBodyProps extends RowProp, InstanceProp, BatchSelectionProp {
root: HTMLElement | null
tableHeaderHeight: number
showPreviousRow?: boolean
isLast?: boolean
}

Expand All @@ -26,7 +22,6 @@ export const TableBody: React.FC<TableBodyProps> = ({
batchRowSelection,
root,
tableHeaderHeight,
showPreviousRow,
isLast
}) => {
const contentProps = {
Expand All @@ -37,9 +32,6 @@ export const TableBody: React.FC<TableBodyProps> = ({
projectHasCheckpoints,
row
}
const isBranchesView = useSelector(
(state: ExperimentsState) => state.tableData.isBranchesView
)
const content =
row.depth > 0 ? (
<ExperimentGroup {...contentProps} />
Expand All @@ -57,12 +49,6 @@ export const TableBody: React.FC<TableBodyProps> = ({
</WorkspaceRowGroup>
) : (
<>
{showPreviousRow && row.depth === 0 && (
<PreviousCommitsRow
isBranchesView={isBranchesView}
nbColumns={row.getAllCells().length}
/>
)}
<tbody
className={cx(styles.rowGroup, {
[styles.experimentGroup]: row.depth > 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -832,13 +832,7 @@ describe('TableContent', () => {
)
}

it('should not display the branches names before its rows if there is only one branch', () => {
renderTableContent()

expect(screen.queryByTestId('branch-name')).not.toBeInTheDocument()
})

it('should display the branches names before its rows if there are more than one branch', () => {
it('should display the branches names before its rows', () => {
const instanceRows = instance.getRowModel()
const multipleBranchesInstance = {
...instance,
Expand Down
11 changes: 2 additions & 9 deletions webview/src/experiments/components/table/body/TableContent.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React, { Fragment, RefObject, useCallback, useContext } from 'react'
import { useSelector } from 'react-redux'
import { TableBody } from './TableBody'
import { CommitsAndBranchesNavigation } from './commitsAndBranches/CommitsAndBranchesNavigation'
import { BranchDivider } from './branchDivider/BranchDivider'
import { RowSelectionContext } from '../RowSelectionContext'
import { ExperimentsState } from '../../../store'
Expand Down Expand Up @@ -56,19 +55,15 @@ export const TableContent: React.FC<TableContentProps> = ({
<>
{branches.map((branch, branchIndex) => {
const branchRows = rows.filter(row => row.original.branch === branch)
const firstPreviousCommitId = branchRows
.slice(branchIndex === 0 ? 2 : 1)
.find(row => row.depth === 0)?.id

return (
<Fragment key={branch}>
{branchRows.map((row, i) => {
const isFirstRow =
(branchIndex === 0 && i === 1) || (branchIndex !== 0 && i === 0)
return (
<Fragment key={row.id}>
{isFirstRow && branches.length > 1 && (
<BranchDivider>{branch}</BranchDivider>
)}
{isFirstRow && <BranchDivider>{branch}</BranchDivider>}
<TableBody
tableHeaderHeight={tableHeadHeight}
root={tableRef.current}
Expand All @@ -77,13 +72,11 @@ export const TableContent: React.FC<TableContentProps> = ({
hasRunningExperiment={hasRunningExperiment}
projectHasCheckpoints={hasCheckpoints}
batchRowSelection={batchRowSelection}
showPreviousRow={row.id === firstPreviousCommitId}
isLast={i === branchRows.length - 1}
/>
</Fragment>
)
})}
<CommitsAndBranchesNavigation />
</Fragment>
)
})}
Expand Down
Loading

0 comments on commit 226f6f1

Please sign in to comment.