Skip to content

Commit

Permalink
remove duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
mattseddon committed May 17, 2023
1 parent a533f6c commit 6ce5d7d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
11 changes: 2 additions & 9 deletions webview/src/setup/components/dvc/Dvc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { ProjectUninitialized } from './ProjectUninitialized'
import { CliUnavailable } from './CliUnavailable'
import { EmptyState } from '../../../shared/components/emptyState/EmptyState'
import { usePrevious } from '../../hooks/usePrevious'
import { updateSectionCollapsed } from '../../state/webviewSlice'
import { SetupState } from '../../store'
import { closeSection } from '../shared/util'

export const Dvc: React.FC = () => {
const dispatch = useDispatch()
Expand All @@ -29,14 +29,7 @@ export const Dvc: React.FC = () => {
}

if (previousIsComplete === false && isComplete) {
dispatch(
updateSectionCollapsed({
[SetupSection.DVC]: true,
[SetupSection.EXPERIMENTS]: false,
[SetupSection.REMOTES]: false,
[SetupSection.STUDIO]: false
})
)
dispatch(closeSection(SetupSection.DVC))
}
}, [
dispatch,
Expand Down
13 changes: 2 additions & 11 deletions webview/src/setup/components/shared/FocusDvcSection.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
import React from 'react'
import { useDispatch } from 'react-redux'
import { SetupSection } from 'dvc/src/setup/webview/contract'
import { updateSectionCollapsed } from '../../state/webviewSlice'
import { focusSection } from './util'
import { Button } from '../../../shared/components/button/Button'

export const FocusDvcSection = () => {
const dispatch = useDispatch()
return (
<Button
text="Setup DVC"
onClick={() =>
dispatch(
updateSectionCollapsed({
[SetupSection.DVC]: false,
[SetupSection.EXPERIMENTS]: true,
[SetupSection.REMOTES]: true,
[SetupSection.STUDIO]: true
})
)
}
onClick={() => dispatch(focusSection(SetupSection.DVC))}
/>
)
}
21 changes: 21 additions & 0 deletions webview/src/setup/components/shared/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { SetupSection } from 'dvc/src/setup/webview/contract'
import { updateSectionCollapsed } from '../../state/webviewSlice'

const getAllSections = (collaspsed: boolean) => ({
[SetupSection.DVC]: collaspsed,
[SetupSection.EXPERIMENTS]: collaspsed,
[SetupSection.REMOTES]: collaspsed,
[SetupSection.STUDIO]: collaspsed
})

export const focusSection = (section: SetupSection) =>
updateSectionCollapsed({
...getAllSections(true),
[section]: false
})

export const closeSection = (section: SetupSection) =>
updateSectionCollapsed({
...getAllSections(false),
[section]: true
})

0 comments on commit 6ce5d7d

Please sign in to comment.