Skip to content

Commit

Permalink
Revert to section variable name to reduce number of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephanie Roy committed Feb 23, 2023
1 parent 37a334c commit 4d0eef2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
32 changes: 15 additions & 17 deletions webview/src/plots/components/templatePlots/TemplatePlots.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useDispatch, useSelector } from 'react-redux'
import { MessageFromWebviewType } from 'dvc/src/webview/contract'
import { AddedSection } from './AddedSection'
import { TemplatePlotsGrid } from './TemplatePlotsGrid'
import { PlotGroup, updateUserSections } from './templatePlotsSlice'
import { PlotGroup, updateSections } from './templatePlotsSlice'
import { removeFromPreviousAndAddToNewSection } from './util'
import { sendMessage } from '../../../shared/vscode'
import { createIDWithIndex, getIDIndex } from '../../../util/ids'
Expand All @@ -24,9 +24,7 @@ export enum NewSectionBlock {
}

export const TemplatePlots: React.FC = () => {
const { size, userSections } = useSelector(
(state: PlotsState) => state.template
)
const { size, sections } = useSelector((state: PlotsState) => state.template)
const draggedOverGroup = useSelector(
(state: PlotsState) => state.dragAndDrop.draggedOverGroup
)
Expand Down Expand Up @@ -56,7 +54,7 @@ export const TemplatePlots: React.FC = () => {
/* Although the following dispatch duplicates the work the reducer will do when the state returns
from the extension, this is necessary to not see any flickering in the order as the returned state
sometimes takes a while to come back */
dispatch(updateUserSections(sections))
dispatch(updateSections(sections))
sendReorderMessage(sections)
},
[dispatch, sendReorderMessage]
Expand All @@ -75,7 +73,7 @@ export const TemplatePlots: React.FC = () => {
const oldGroupId = getIDIndex(draggedGroup)
const newGroupId = getIDIndex(groupId)
const updatedSections = removeFromPreviousAndAddToNewSection(
userSections,
sections,
oldGroupId,
draggedId,
newGroupId,
Expand All @@ -84,30 +82,30 @@ export const TemplatePlots: React.FC = () => {

setSections(updatedSections)
},
[setSections, userSections]
[setSections, sections]
)

const setSectionEntries = useCallback(
(index: number, entries: string[]) => {
const updatedSections = [...userSections]
const updatedSections = [...sections]
updatedSections[index] = {
...updatedSections[index],
entries
}
setSections(updatedSections)
},
[setSections, userSections]
[setSections, sections]
)

if (sectionIsLoading(selectedRevisions)) {
return <LoadingSection />
}
if (!userSections || userSections.length === 0) {
if (!sections || sections.length === 0) {
return <EmptyState isFullScreen={false}>No Plots to Display</EmptyState>
}

const firstSection = userSections[0]
const lastSection = userSections.slice(-1)[0]
const firstSection = sections[0]
const lastSection = sections.slice(-1)[0]

if (!firstSection || !lastSection) {
return null
Expand All @@ -121,12 +119,12 @@ export const TemplatePlots: React.FC = () => {
const draggedId = draggedRef.itemId

const updatedSections = removeFromPreviousAndAddToNewSection(
userSections,
sections,
draggedSectionId,
draggedId
)

const { group } = userSections[draggedSectionId]
const { group } = sections[draggedSectionId]

setHoveredSection('')
const newSection = {
Expand Down Expand Up @@ -163,7 +161,7 @@ export const TemplatePlots: React.FC = () => {
id={NewSectionBlock.TOP}
closestSection={firstSection}
/>
{userSections.map((section, i) => {
{sections.map((section, i) => {
const groupId = createIDWithIndex(section.group, i)
const useVirtualizedGrid = shouldUseVirtualizedGrid(
Object.keys(section.entries).length,
Expand All @@ -186,11 +184,11 @@ export const TemplatePlots: React.FC = () => {

if (draggedRef.group === groupId) {
const order = section.entries
const updatedSections = [...userSections]
const updatedSections = [...sections]

const newOrder = changeOrderWithDraggedInfo(order, draggedRef)
updatedSections[i] = {
...userSections[i],
...sections[i],
entries: newOrder
}
setSections(updatedSections)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const TemplatePlotsGrid: React.FC<TemplatePlotsGridProps> = ({
const dispatch = useDispatch()
const currentSize = useSelector((state: PlotsState) => state.template.size)
const entries = useSelector(
(state: PlotsState) => state.template.userSections[groupIndex].entries
(state: PlotsState) => state.template.sections[groupIndex].entries
)

const disabledDragPlotIds = useSelector(
Expand Down
22 changes: 11 additions & 11 deletions webview/src/plots/components/templatePlots/templatePlotsSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface TemplatePlotsState extends Omit<TemplatePlotsData, 'plots'> {
isCollapsed: boolean
hasData: boolean
plotsSnapshots: { [key: string]: string }
userSections: PlotGroup[]
sections: PlotGroup[]
disabledDragPlotIds: string[]
}

Expand All @@ -22,8 +22,8 @@ export const templatePlotsInitialState: TemplatePlotsState = {
hasData: false,
isCollapsed: DEFAULT_SECTION_COLLAPSED[Section.TEMPLATE_PLOTS],
plotsSnapshots: {},
size: DEFAULT_SECTION_SIZES[Section.TEMPLATE_PLOTS],
userSections: []
sections: [],
size: DEFAULT_SECTION_SIZES[Section.TEMPLATE_PLOTS]
}

export const templatePlotsSlice = createSlice({
Expand Down Expand Up @@ -58,17 +58,17 @@ export const templatePlotsSlice = createSlice({
...state,
hasData: !!action.payload,
plotsSnapshots: snapShots,
size: Math.abs(action.payload.size),
userSections:
JSON.stringify(plotSections) === JSON.stringify(state.userSections)
? state.userSections
: plotSections
sections:
JSON.stringify(plotSections) === JSON.stringify(state.sections)
? state.sections
: plotSections,
size: Math.abs(action.payload.size)
}
},
updateUserSections: (state, action: PayloadAction<PlotGroup[]>) => {
updateSections: (state, action: PayloadAction<PlotGroup[]>) => {
return {
...state,
userSections: action.payload
sections: action.payload
}
}
}
Expand All @@ -79,7 +79,7 @@ export const {
setCollapsed,
changeSize,
changeDisabledDragIds,
updateUserSections
updateSections
} = templatePlotsSlice.actions

export default templatePlotsSlice.reducer

0 comments on commit 4d0eef2

Please sign in to comment.