Skip to content

Commit

Permalink
feat(board): merge column settings from db with default (#1118)
Browse files Browse the repository at this point in the history
* feat(board): adds settingsMerger utils and merge columns function

* feat(board): implements column settings merged with default

* refactor(table): inline merging default columns with settings
  • Loading branch information
stianjsu authored Jul 13, 2023
1 parent e599241 commit e8f2a86
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion next-tavla/src/Board/scenarios/QuayTile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export function QuayTile({
placeId,
whitelistedLines,
whitelistedTransportModes,
columns,
}: TQuayTile) {
const { data } = useQuery(
GetQuayQuery,
Expand Down Expand Up @@ -44,7 +45,7 @@ export function QuayTile({
return (
<Tile className={classes.quayTile}>
<TableHeader heading={heading} transportModes={transportModes} />
<Table departures={data.quay.estimatedCalls} />
<Table columns={columns} departures={data.quay.estimatedCalls} />
</Tile>
)
}
6 changes: 5 additions & 1 deletion next-tavla/src/Board/scenarios/StopPlaceTile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export function StopPlaceTile({
placeId,
whitelistedLines,
whitelistedTransportModes,
columns,
}: TStopPlaceTile) {
const { data } = useQuery(
StopPlaceQuery,
Expand All @@ -31,7 +32,10 @@ export function StopPlaceTile({
heading={data.stopPlace.name}
transportModes={data.stopPlace.transportMode}
/>
<Table departures={data.stopPlace.estimatedCalls} />
<Table
departures={data.stopPlace.estimatedCalls}
columns={columns}
/>
</Tile>
)
}
10 changes: 7 additions & 3 deletions next-tavla/src/Board/scenarios/Table/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { TDepartureFragment } from 'graphql/index'
import {
Columns,
TColumn,
DefaultColumns,
TColumnSize,
TColumnSettings,
DefaultColumns,
} from 'types/column'
import React from 'react'
import classes from './styles.module.css'
Expand Down Expand Up @@ -49,12 +49,16 @@ function ColumnTableHeader({ type, size }: TColumnSize) {

function Table({
departures,
columns = DefaultColumns,
columns,
}: {
departures: TDepartureFragment[]
columns?: TColumnSettings
}) {
const filteredColumnOrder = ColumnOrder.filter(({ type }) => columns[type])
const mergedColumns = { ...DefaultColumns, ...columns }

const filteredColumnOrder = ColumnOrder.filter(
({ type }) => mergedColumns[type],
)

return (
<div className={classes.container}>
Expand Down

0 comments on commit e8f2a86

Please sign in to comment.