Skip to content

Commit

Permalink
feat(edit): implements V5 column structure in admin (#1115)
Browse files Browse the repository at this point in the history
* feat(edit): adds new version and removes unused column operations

* test(edit): updates tests for new column structure

* chore(types): removed unused types, imports and component

---------

Co-authored-by: asemwilhelmsen <[email protected]>
  • Loading branch information
2 people authored and SharmaTarun1111111 committed Jul 11, 2023
1 parent 6005940 commit 5b19898
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 585 deletions.
73 changes: 0 additions & 73 deletions next-tavla/src/Admin/scenarios/AddColumn/AddColumn.cy.tsx

This file was deleted.

37 changes: 0 additions & 37 deletions next-tavla/src/Admin/scenarios/AddColumn/index.tsx

This file was deleted.

11 changes: 0 additions & 11 deletions next-tavla/src/Admin/scenarios/AddColumn/styles.module.css

This file was deleted.

100 changes: 0 additions & 100 deletions next-tavla/src/Admin/scenarios/ColumnSettings/index.tsx

This file was deleted.

23 changes: 0 additions & 23 deletions next-tavla/src/Admin/scenarios/ColumnSettings/styles.module.css

This file was deleted.

84 changes: 2 additions & 82 deletions next-tavla/src/Admin/scenarios/Edit/reducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,14 @@ import { TAnonTiles } from 'Admin/types'
import { clone, xor } from 'lodash'
import { nanoid } from 'nanoid'
import { TSettings, TTheme } from 'types/settings'
import {
DefaultColumns,
TColumnSetting,
TQuayTile,
TStopPlaceTile,
TTile,
} from 'types/tile'
import { TColumn } from 'types/column'
import { TQuayTile, TStopPlaceTile, TTile } from 'types/tile'

export type Action =
| { type: 'changeTheme'; theme: TTheme }
| { type: 'addTile'; tile: TAnonTiles }
| { type: 'removeTile'; tileId: string }
| { type: 'updateTile'; tileIndex: number; tile: TTile }
| { type: 'swapTiles'; oldIndex: number; newIndex: number }
| { type: 'addColumn'; tileId: string; column: TColumn }
| { type: 'removeColumn'; tileId: string; column: TColumn }
| {
type: 'updateColumn'
tileId: string
columnSetting: TColumnSetting
}
| {
type: 'swapColumns'
tileId: string
oldIndex: number
newIndex: number
}
| { type: 'toggleLine'; tileId: string; lineId: string }

export function settingsReducer(
Expand Down Expand Up @@ -88,72 +68,12 @@ export function settingsReducer(
return {
...settings,
tiles: arrayMove(
settings.tiles ?? [...DefaultColumns],
settings.tiles,
action.oldIndex,
action.newIndex,
),
}
}
// Column operations
case 'addColumn': {
return changeTile<TStopPlaceTile | TQuayTile>(
action.tileId,
(tile) => {
return {
...tile,
columns: [
...(tile.columns || [...DefaultColumns]),
{ type: action.column },
],
}
},
)
}
case 'removeColumn': {
return changeTile<TStopPlaceTile | TQuayTile>(
action.tileId,
(tile) => {
const cols = tile.columns ?? [...DefaultColumns]
return {
...tile,
columns: cols.filter(
(col) => col.type !== action.column,
),
}
},
)
}
case 'updateColumn': {
return changeTile<TStopPlaceTile | TQuayTile>(
action.tileId,
(tile) => {
const cols = tile.columns ?? [...DefaultColumns]
return {
...tile,
columns: cols.map((col) =>
col.type === action.columnSetting.type
? action.columnSetting
: col,
),
}
},
)
}
case 'swapColumns': {
return changeTile<TStopPlaceTile | TQuayTile>(
action.tileId,
(tile) => {
return {
...tile,
columns: arrayMove(
tile.columns || [...DefaultColumns],
action.oldIndex,
action.newIndex,
),
}
},
)
}
// Line operations
case 'toggleLine': {
return changeTile<TStopPlaceTile | TQuayTile>(
Expand Down
23 changes: 8 additions & 15 deletions next-tavla/src/Admin/scenarios/SelectLines/SelectLines.cy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,14 @@ describe('<SelectLines />', () => {
const [settings, dispatch] = useReducer(settingsReducer, {
tiles: [
{
columns: [
{
type: 'platform',
},
{
type: 'line',
},
{
size: 2,
type: 'destination',
},
{
type: 'time',
},
],
columns: {
line: true,
destination: true,
platform: false,
situations: true,
time: true,
via: true,
},
placeId: 'NSR:StopPlace:60066',
type: 'stop_place',
uuid: '1683625543293',
Expand Down
Loading

0 comments on commit 5b19898

Please sign in to comment.