Skip to content

Commit c681e6b

Browse files
ruggiruggishop
andauthored
Rename grid movement strategies (#6621)
**Problem:** The grid "move" strategies should be renamed to better reflect what they do and to be less confusing. **Fix:** This PR is a followup to #6606 1. Rename "move rearrange" to "change grid element location" (and duplicate) 2. Rename "move reorder" to "reorder" Fixes #6620 --------- Co-authored-by: Federico Ruggi <federico.ruggi@shopify.com>
1 parent 3148367 commit c681e6b

9 files changed

+44
-44
lines changed

editor/src/components/canvas/canvas-strategies/canvas-strategies.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ import type { InsertionSubject, InsertionSubjectWrapper } from '../../editor/edi
6767
import { generateUidWithExistingComponents } from '../../../core/model/element-template-utils'
6868
import { retargetStrategyToChildrenOfFragmentLikeElements } from './strategies/fragment-like-helpers'
6969
import { MetadataUtils } from '../../../core/model/element-metadata-utils'
70-
import { gridMoveRearrangeStrategy } from './strategies/grid-move-rearrange-strategy'
70+
import { gridChangeElementLocationStrategy } from './strategies/grid-change-element-location-strategy'
7171
import { resizeGridStrategy } from './strategies/resize-grid-strategy'
7272
import { gridResizeElementStrategy } from './strategies/grid-resize-element-strategy'
73-
import { gridMoveRearrangeDuplicateStrategy } from './strategies/grid-move-rearrange-duplicate-strategy'
73+
import { gridChangeElementLocationDuplicateStrategy } from './strategies/grid-change-element-location-duplicate-strategy'
7474
import { setGridGapStrategy } from './strategies/set-grid-gap-strategy'
7575
import type { CanvasCommand } from '../commands/commands'
7676
import { foldAndApplyCommandsInner } from '../commands/commands'
@@ -79,15 +79,15 @@ import { wrapInContainerCommand } from '../commands/wrap-in-container-command'
7979
import type { ElementPath } from 'utopia-shared/src/types'
8080
import { reparentSubjectsForInteractionTarget } from './strategies/reparent-helpers/reparent-strategy-helpers'
8181
import { getReparentTargetUnified } from './strategies/reparent-helpers/reparent-strategy-parent-lookup'
82-
import { gridRearrangeResizeKeyboardStrategy } from './strategies/grid-rearrange-keyboard-strategy'
82+
import { gridChangeElementLocationResizeKeyboardStrategy } from './strategies/grid-change-element-location-keyboard-strategy'
8383
import createCachedSelector from 're-reselect'
8484
import { getActivePlugin } from '../plugins/style-plugins'
8585
import {
8686
controlsForGridPlaceholders,
8787
GridControls,
8888
isGridControlsProps,
8989
} from '../controls/grid-controls-for-strategies'
90-
import { gridMoveReorderStrategy } from './strategies/grid-move-reorder-strategy'
90+
import { gridReorderStrategy } from './strategies/grid-reorder-strategy'
9191
import { gridMoveAbsoluteStrategy } from './strategies/grid-move-absolute'
9292

9393
export type CanvasStrategyFactory = (
@@ -116,10 +116,10 @@ const moveOrReorderStrategies: MetaCanvasStrategy = (
116116
convertToAbsoluteAndMoveStrategy,
117117
convertToAbsoluteAndMoveAndSetParentFixedStrategy,
118118
reorderSliderStategy,
119-
gridMoveRearrangeStrategy,
120-
gridMoveRearrangeDuplicateStrategy,
121-
gridMoveReorderStrategy,
122-
gridRearrangeResizeKeyboardStrategy,
119+
gridChangeElementLocationStrategy,
120+
gridChangeElementLocationDuplicateStrategy,
121+
gridReorderStrategy,
122+
gridChangeElementLocationResizeKeyboardStrategy,
123123
gridMoveAbsoluteStrategy,
124124
],
125125
)

editor/src/components/canvas/canvas-strategies/strategies/grid-move-rearrange-duplicate-strategy.ts editor/src/components/canvas/canvas-strategies/strategies/grid-change-element-location-duplicate-strategy.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import {
2323
getParentGridTemplatesFromChildMeasurements,
2424
gridMoveStrategiesExtraCommands,
2525
} from './grid-helpers'
26-
import { runGridMoveRearrange } from './grid-move-rearrange-strategy'
26+
import { runGridChangeElementLocation } from './grid-change-element-location-strategy'
2727

28-
export const gridMoveRearrangeDuplicateStrategy: CanvasStrategyFactory = (
28+
export const gridChangeElementLocationDuplicateStrategy: CanvasStrategyFactory = (
2929
canvasState: InteractionCanvasState,
3030
interactionSession: InteractionSession | null,
3131
customState: CustomStrategyState,
@@ -79,9 +79,9 @@ export const gridMoveRearrangeDuplicateStrategy: CanvasStrategyFactory = (
7979
}
8080

8181
return {
82-
id: 'rearrange-grid-move-duplicate-strategy',
83-
name: 'Grid Rearrange (Duplicate)',
84-
descriptiveLabel: 'Grid Rearrange (Duplicate)',
82+
id: 'grid-change-element-location-duplicate-strategy',
83+
name: 'Change Location (Duplicate)',
84+
descriptiveLabel: 'Change Location (Duplicate)',
8585
icon: {
8686
category: 'tools',
8787
type: 'pointer',
@@ -115,7 +115,7 @@ export const gridMoveRearrangeDuplicateStrategy: CanvasStrategyFactory = (
115115
return emptyStrategyApplicationResult
116116
}
117117

118-
const moveCommands = runGridMoveRearrange(
118+
const moveCommands = runGridChangeElementLocation(
119119
canvasState.startingMetadata,
120120
interactionSession.interactionData,
121121
selectedElementMetadata,

editor/src/components/canvas/canvas-strategies/strategies/grid-rearrange-keyboard-strategy.ts editor/src/components/canvas/canvas-strategies/strategies/grid-change-element-location-keyboard-strategy.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { findOriginalGrid, setGridPropsCommands } from './grid-helpers'
1414
import { getGridChildCellCoordBoundsFromCanvas } from './grid-cell-bounds'
1515
import { accumulatePresses } from './shared-keyboard-strategy-helpers'
1616

17-
export function gridRearrangeResizeKeyboardStrategy(
17+
export function gridChangeElementLocationResizeKeyboardStrategy(
1818
canvasState: InteractionCanvasState,
1919
interactionSession: InteractionSession | null,
2020
): CanvasStrategy | null {
@@ -62,10 +62,10 @@ export function gridRearrangeResizeKeyboardStrategy(
6262
interactionSession.interactionData.keyStates.length - 1,
6363
)?.modifiers.shift ?? false
6464

65-
const label = resizing ? 'Grid resize' : 'Grid rearrange'
65+
const label = resizing ? 'Grid resize' : 'Change Location'
6666

6767
return {
68-
id: 'GRID_KEYBOARD_REARRANGE_RESIZE',
68+
id: 'GRID_KEYBOARD_CHANGE_ELEMENT_LOCATION_RESIZE',
6969
name: label,
7070
descriptiveLabel: label,
7171
icon: {

editor/src/components/canvas/canvas-strategies/strategies/grid-move-rearrange-strategy.ts editor/src/components/canvas/canvas-strategies/strategies/grid-change-element-location-strategy.ts

+11-10
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import {
3333
} from './grid-helpers'
3434
import { getTargetGridCellData } from '../../../inspector/grid-helpers'
3535

36-
export const gridMoveRearrangeStrategy: CanvasStrategyFactory = (
36+
export const gridChangeElementLocationStrategy: CanvasStrategyFactory = (
3737
canvasState: InteractionCanvasState,
3838
interactionSession: InteractionSession | null,
3939
) => {
@@ -89,9 +89,9 @@ export const gridMoveRearrangeStrategy: CanvasStrategyFactory = (
8989
}
9090

9191
return {
92-
id: 'rearrange-grid-move-strategy',
93-
name: 'Grid rearrange',
94-
descriptiveLabel: 'Grid rearrange',
92+
id: 'grid-change-element-location-strategy',
93+
name: 'Change Location',
94+
descriptiveLabel: 'Change Location',
9595
icon: {
9696
category: 'tools',
9797
type: 'pointer',
@@ -108,7 +108,7 @@ export const gridMoveRearrangeStrategy: CanvasStrategyFactory = (
108108
return emptyStrategyApplicationResult
109109
}
110110

111-
const { commands, elementsToRerender } = getCommandsAndPatchForGridRearrange(
111+
const { commands, elementsToRerender } = getCommandsAndPatchForGridChangeElementLocation(
112112
canvasState,
113113
interactionSession.interactionData,
114114
selectedElement,
@@ -122,6 +122,7 @@ export const gridMoveRearrangeStrategy: CanvasStrategyFactory = (
122122
parentGridPath,
123123
initialTemplates,
124124
)
125+
125126
return strategyApplicationResult(
126127
[...midInteractionCommands, ...onCompleteCommands, ...commands],
127128
elementsToRerender,
@@ -130,7 +131,7 @@ export const gridMoveRearrangeStrategy: CanvasStrategyFactory = (
130131
}
131132
}
132133

133-
function getCommandsAndPatchForGridRearrange(
134+
function getCommandsAndPatchForGridChangeElementLocation(
134135
canvasState: InteractionCanvasState,
135136
interactionData: DragInteractionData,
136137
selectedElement: ElementPath,
@@ -157,7 +158,7 @@ function getCommandsAndPatchForGridRearrange(
157158
return { commands: [], elementsToRerender: [] }
158159
}
159160

160-
const commands = runGridMoveRearrange(
161+
const commands = runGridChangeElementLocation(
161162
canvasState.startingMetadata,
162163
interactionData,
163164
selectedElementMetadata,
@@ -173,7 +174,7 @@ function getCommandsAndPatchForGridRearrange(
173174
}
174175
}
175176

176-
export function runGridMoveRearrange(
177+
export function runGridChangeElementLocation(
177178
jsxMetadata: ElementInstanceMetadataMap,
178179
interactionData: DragInteractionData,
179180
selectedElementMetadata: ElementInstanceMetadata,
@@ -251,7 +252,7 @@ export function runGridMoveRearrange(
251252
})
252253
.sort(sortElementsByGridPosition(templateColumnsCount))
253254

254-
const indexInSortedCellsForRearrange = cellsSortedByPosition.findIndex((s) =>
255+
const indexInSortedCellsForChangeLocation = cellsSortedByPosition.findIndex((s) =>
255256
EP.pathsEqual(selectedElementMetadata.elementPath, s.path),
256257
)
257258

@@ -267,7 +268,7 @@ export function runGridMoveRearrange(
267268
reorderElement(
268269
'always',
269270
pathForCommands,
270-
absolute(Math.max(indexInSortedCellsForRearrange, 0)),
271+
absolute(Math.max(indexInSortedCellsForChangeLocation, 0)),
271272
),
272273
updateGridControlsCommand,
273274
]

editor/src/components/canvas/canvas-strategies/strategies/grid-rearrange-move-strategy.spec.browser2.tsx editor/src/components/canvas/canvas-strategies/strategies/grid-element-change-location-strategy.spec.browser2.tsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ import { renderTestEditorWithCode } from '../../ui-jsx.test-utils'
2323
import type { GridCellCoordinates } from './grid-cell-bounds'
2424
import { gridCellTargetId } from './grid-cell-bounds'
2525

26-
describe('grid rearrange move strategy', () => {
27-
it('can rearrange elements on a grid', async () => {
26+
describe('grid element change location strategy', () => {
27+
it('can change the location of elements on a grid', async () => {
2828
const editor = await renderTestEditorWithCode(ProjectCode, 'await-first-dom-report')
2929

3030
const testId = 'aaa'
@@ -41,7 +41,7 @@ describe('grid rearrange move strategy', () => {
4141
})
4242
})
4343

44-
it('can rearrange elements in a grid component', async () => {
44+
it('can change the location of elements in a grid component', async () => {
4545
const editor = await renderTestEditorWithCode(
4646
ProjectCodeGridComponent,
4747
'await-first-dom-report',
@@ -61,7 +61,7 @@ describe('grid rearrange move strategy', () => {
6161
})
6262
})
6363

64-
it('can not rearrange multicell element out of the grid', async () => {
64+
it('can not change location of a multicell element out of the grid', async () => {
6565
const editor = await renderTestEditorWithCode(ProjectCode, 'await-first-dom-report')
6666

6767
const testId = 'aaa'
@@ -81,7 +81,7 @@ describe('grid rearrange move strategy', () => {
8181
})
8282
})
8383

84-
it('can rearrange element with no explicit grid props set', async () => {
84+
it('can change the location of element with no explicit grid props set', async () => {
8585
const editor = await renderTestEditorWithCode(ProjectCode, 'await-first-dom-report')
8686

8787
const testId = 'bbb'
@@ -100,7 +100,7 @@ describe('grid rearrange move strategy', () => {
100100
})
101101
})
102102

103-
it('can rearrange elements on a grid (zoom out)', async () => {
103+
it('can change the location of elements on a grid (zoom out)', async () => {
104104
const editor = await renderTestEditorWithCode(ProjectCode, 'await-first-dom-report')
105105

106106
const testId = 'aaa'
@@ -117,7 +117,7 @@ describe('grid rearrange move strategy', () => {
117117
})
118118
})
119119

120-
it('can rearrange elements on a grid (zoom in)', async () => {
120+
it('can change the location of elements on a grid (zoom in)', async () => {
121121
const editor = await renderTestEditorWithCode(ProjectCode, 'await-first-dom-report')
122122

123123
const testId = 'aaa'

editor/src/components/canvas/canvas-strategies/strategies/grid-move-absolute.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
} from '../../../../core/shared/element-template'
99
import type { CanvasRectangle } from '../../../../core/shared/math-utils'
1010
import {
11-
canvasPoint,
1211
canvasRectangle,
1312
isInfinityRectangle,
1413
offsetPoint,
@@ -39,7 +38,7 @@ import {
3938
getParentGridTemplatesFromChildMeasurements,
4039
gridMoveStrategiesExtraCommands,
4140
} from './grid-helpers'
42-
import { runGridMoveRearrange } from './grid-move-rearrange-strategy'
41+
import { runGridChangeElementLocation } from './grid-change-element-location-strategy'
4342
import { getTargetGridCellData } from '../../../inspector/grid-helpers'
4443

4544
export const gridMoveAbsoluteStrategy: CanvasStrategyFactory = (
@@ -226,9 +225,9 @@ function runGridMoveAbsolute(
226225
]
227226
}
228227

229-
// otherwise, return a rearrange move + absolute adjustment
228+
// otherwise, return a change location + absolute adjustment
230229
return [
231-
...runGridMoveRearrange(
230+
...runGridChangeElementLocation(
232231
jsxMetadata,
233232
interactionData,
234233
selectedElementMetadata,

editor/src/components/canvas/canvas-strategies/strategies/grid-move-reorder-strategy.ts editor/src/components/canvas/canvas-strategies/strategies/grid-reorder-strategy.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {
3535
} from './grid-helpers'
3636
import { getTargetGridCellData } from '../../../inspector/grid-helpers'
3737

38-
export const gridMoveReorderStrategy: CanvasStrategyFactory = (
38+
export const gridReorderStrategy: CanvasStrategyFactory = (
3939
canvasState: InteractionCanvasState,
4040
interactionSession: InteractionSession | null,
4141
) => {
@@ -171,7 +171,7 @@ function getCommandsAndPatchForGridReorder(
171171
return { commands: [], elementsToRerender: [] }
172172
}
173173

174-
const commands = runGridMoveReorder(
174+
const commands = runGridReorder(
175175
canvasState.startingMetadata,
176176
interactionData,
177177
selectedElementMetadata,
@@ -186,7 +186,7 @@ function getCommandsAndPatchForGridReorder(
186186
}
187187
}
188188

189-
function runGridMoveReorder(
189+
function runGridReorder(
190190
jsxMetadata: ElementInstanceMetadataMap,
191191
interactionData: DragInteractionData,
192192
selectedElementMetadata: ElementInstanceMetadata,

editor/src/components/canvas/canvas-strategies/strategies/grid-reparent-strategy.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import {
3535
import type { DragInteractionData, InteractionSession, UpdatedPathMap } from '../interaction-state'
3636
import { honoursPropsPosition, shouldKeepMovingDraggedGroupChildren } from './absolute-utils'
3737
import { replaceFragmentLikePathsWithTheirChildrenRecursive } from './fragment-like-helpers'
38-
import { runGridMoveRearrange } from './grid-move-rearrange-strategy'
38+
import { runGridChangeElementLocation } from './grid-change-element-location-strategy'
3939
import { ifAllowedToReparent, isAllowedToReparent } from './reparent-helpers/reparent-helpers'
4040
import { removeAbsolutePositioningProps } from './reparent-helpers/reparent-property-changes'
4141
import type { ReparentTarget } from './reparent-helpers/reparent-strategy-helpers'
@@ -283,7 +283,7 @@ function gridReparentCommands(
283283
return null
284284
}
285285

286-
const gridPropsCommands = runGridMoveRearrange(
286+
const gridPropsCommands = runGridChangeElementLocation(
287287
jsxMetadata,
288288
interactionData,
289289
targetElement,

editor/src/components/canvas/controls/grid-controls.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ const GridControl = React.memo<GridControlProps>(({ grid, controlsVisible }) =>
909909
countedColumn === currentHoveredCell?.column &&
910910
countedRow === currentHoveredCell?.row
911911

912-
const activePositioningTarget = isActiveCell && !dontShowActiveCellHighlight // TODO: move the logic into runGridRearrangeMove and do not set targetCell prop in these cases
912+
const activePositioningTarget = isActiveCell && !dontShowActiveCellHighlight // TODO: move the logic into runGridChangeElementLocation and do not set targetCell prop in these cases
913913

914914
const borderColor = activePositioningTarget
915915
? colorTheme.brandNeonPink.value

0 commit comments

Comments
 (0)