Skip to content

Commit

Permalink
refactor(converters): V5 no longer returns empty object on undefined …
Browse files Browse the repository at this point in the history
…columns. Improved readability
  • Loading branch information
stianjsu committed Jul 10, 2023
1 parent 6a1d7f1 commit ea0b73f
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions next-tavla/src/Shared/utils/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,15 @@ export function V5(setting: ReturnType<typeof V4>) {
return {
...setting,
tiles: setting.tiles.map((tile) => {
if (!tile.columns) return { ...tile, columns: {} }
const { columns: oldColumns, ...rest } = tile
if (!oldColumns || !oldColumns.length) return rest

const oldColumns = tile.columns
type TBaseColumnExtended =
| (typeof oldColumns)[number]['type']
| 'via'
| 'situations'
type TBaseColumnExtended = TBaseColumn | 'via' | 'situations'

const newColumns: Partial<Record<TBaseColumnExtended, boolean>> = {}

oldColumns.forEach((col) => {
newColumns[col.type] = true
})
const newColumns: Partial<Record<TBaseColumnExtended, boolean>> =
oldColumns.reduce((prev, next) => {
return { ...prev, [next.type]: true }
}, {})

return {
...tile,
Expand Down

0 comments on commit ea0b73f

Please sign in to comment.