Skip to content

Commit

Permalink
feat(admin): get name from query
Browse files Browse the repository at this point in the history
  • Loading branch information
asewilhelmsen committed Jul 13, 2023
1 parent 5983d7e commit 11c9316
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@ import { GetQuayQuery } from 'graphql/index'
import { useQuery } from 'graphql/utils'
import { TQuayTile } from 'types/tile'
import { fieldsNotNull } from 'utils/typeguards'
import { TileSettingsWrapper } from './TileSettingsWrapper'

function QuaySettings({ tile }: { tile: TQuayTile }) {
const { data } = useQuery(GetQuayQuery, { quayId: tile.placeId })

const lines = data?.quay?.lines.filter(fieldsNotNull) ?? []

return <SelectLines tile={tile} lines={lines} />
const name = !data
? data
: (data.quay?.name ?? tile.placeId) +
' - ' +
(data.quay?.description ?? data.quay?.publicCode)

return (
<TileSettingsWrapper name={name}>
<SelectLines tile={tile} lines={lines} />
</TileSettingsWrapper>
)
}
export { QuaySettings }
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { StopPlaceSettingsQuery } from 'graphql/index'
import { useQuery } from 'graphql/utils'
import { TStopPlaceTile } from 'types/tile'
import { fieldsNotNull } from 'utils/typeguards'
import { TileSettingsWrapper } from './TileSettingsWrapper'

function StopPlaceSettings({ tile }: { tile: TStopPlaceTile }) {
const { data } = useQuery(StopPlaceSettingsQuery, { id: tile.placeId })
Expand All @@ -12,7 +13,13 @@ function StopPlaceSettings({ tile }: { tile: TStopPlaceTile }) {
?.flatMap((q) => q?.lines)
.filter(fieldsNotNull) || []

return <SelectLines tile={tile} lines={lines} />
const name = !data ? data : data.stopPlace?.name ?? tile.placeId

return (
<TileSettingsWrapper name={name}>
<SelectLines tile={tile} lines={lines} />
</TileSettingsWrapper>
)
}

export { StopPlaceSettings }
7 changes: 4 additions & 3 deletions next-tavla/src/Admin/scenarios/TileSettings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import classes from './styles.module.css'
import { StopPlaceSettings } from './components/StopPlaceSettings'
import { QuaySettings } from './components/QuaySettings'

function TileSettings({ tile, name }: { tile?: TTile; name?: string }) {
function TileSettings({ tile }: { tile?: TTile; name?: string }) {
if (!tile) {
return (
<TileSettingsWrapper className={classes.emptyTileWrapper}>
Expand All @@ -20,10 +20,11 @@ function TileSettings({ tile, name }: { tile?: TTile; name?: string }) {
}

return (
<TileSettingsWrapper name={name}>
<div>
<h3>Rediger holdeplass</h3>
{tile.type === 'stop_place' && <StopPlaceSettings tile={tile} />}
{tile.type === 'quay' && <QuaySettings tile={tile} />}
</TileSettingsWrapper>
</div>
)
}

Expand Down
4 changes: 1 addition & 3 deletions next-tavla/src/Admin/scenarios/TilesOverview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import React from 'react'
import { TileSettings } from '../TileSettings'

function TilesOverview({ tiles }: { tiles: TTile[] }) {
const name = 'Majorstuen'

return <TileSettings tile={tiles[0]} name={name} />
return <TileSettings tile={tiles[0]} />
}

export { TilesOverview }

0 comments on commit 11c9316

Please sign in to comment.