-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(edit): select tile component for editing tile (#1124)
* chore(admin): folder structure change for editing tiles * style(edit): fits delete button to design * feat(edit): adds tile selector for TileOverview * feat(gql): adds queries for fetching name of stopplace and quay * feat(edit): select tiles queries name of location in own component * feat(edit): styling of radio options to match design * feat(edit): adds grid layout for tiles overview and implementation of SelectTile * chore(edit): rename css class * feat(edit): adds message if tiles-list is empty * refactor(edit): moves select tile to own scenario * feat(edit): implement SelectTile and TileSettings into overview * fix(edit): hover style on delete tile button * fix(edit): platform code no longer displayed in select tile list * fix(test): updates AddTile test for new stopplace list * chore(edit tile): removed unused styles and renamed vars for consistency --------- Co-authored-by: asemwilhelmsen <[email protected]>
- Loading branch information
1 parent
a6713f9
commit 1437f60
Showing
15 changed files
with
276 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
next-tavla/src/Admin/scenarios/SelectTile/components/DeleteButton/styles.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
.deleteButton { | ||
border: none; | ||
font-size: 0.75em; | ||
} | ||
|
||
.deleteButton:hover { | ||
background-color: var(--colors-blues-blue30); | ||
border: solid 1px var(--colors-brand-lavender); | ||
} |
37 changes: 37 additions & 0 deletions
37
next-tavla/src/Admin/scenarios/SelectTile/components/RadioOption/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { RadioPanel } from '@entur/form' | ||
import { Loader } from '@entur/loader' | ||
import { DeleteButton } from '../DeleteButton' | ||
import classes from './styles.module.css' | ||
|
||
function RadioOption({ | ||
isLoading, | ||
name, | ||
uuid, | ||
}: { | ||
isLoading: boolean | ||
name: string | ||
uuid: string | ||
}) { | ||
return ( | ||
<RadioPanel | ||
hideRadioButton | ||
disabled={isLoading} | ||
title="" | ||
value={uuid} | ||
className={classes.radioOption} | ||
> | ||
<div className={classes.radioOptionContent}> | ||
{isLoading ? ( | ||
<Loader /> | ||
) : ( | ||
<> | ||
{name} | ||
<DeleteButton uuid={uuid} /> | ||
</> | ||
)} | ||
</div> | ||
</RadioPanel> | ||
) | ||
} | ||
|
||
export { RadioOption } |
13 changes: 13 additions & 0 deletions
13
next-tavla/src/Admin/scenarios/SelectTile/components/RadioOption/styles.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.radioOption { | ||
width: 100%; | ||
border-radius: 1em; | ||
margin-bottom: 1em; | ||
} | ||
|
||
.radioOptionContent { | ||
display: flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
min-height: 2.1em; | ||
font-size: 1.25em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { TQuayTile, TStopPlaceTile, TTile } from 'types/tile' | ||
import { Heading2, Paragraph } from '@entur/typography' | ||
import classes from './styles.module.css' | ||
import { RadioGroup } from '@entur/form' | ||
import { ChangeEvent } from 'react' | ||
import { useQuery } from 'graphql/utils' | ||
import { QuayNameQuery, StopPlaceNameQuery } from 'graphql/index' | ||
import { RadioOption } from './components/RadioOption' | ||
|
||
function StopPlaceRadioOption({ tile }: { tile: TStopPlaceTile }) { | ||
const { data, isLoading } = useQuery(StopPlaceNameQuery, { | ||
id: tile.placeId, | ||
}) | ||
|
||
const name = data?.stopPlace?.name ?? tile.placeId | ||
|
||
return <RadioOption isLoading={isLoading} name={name} uuid={tile.uuid} /> | ||
} | ||
|
||
function QuayRadioOption({ tile }: { tile: TQuayTile }) { | ||
const { data, isLoading } = useQuery(QuayNameQuery, { | ||
id: tile.placeId, | ||
}) | ||
|
||
const name = data?.quay?.name ?? tile.placeId | ||
|
||
return <RadioOption isLoading={isLoading} name={name} uuid={tile.uuid} /> | ||
} | ||
|
||
function SelectTile({ | ||
tiles, | ||
selectedTileId, | ||
selectTile, | ||
}: { | ||
tiles: TTile[] | ||
selectedTileId?: string | ||
selectTile: (uuid: string) => void | ||
}) { | ||
function handleTileSelected(e: ChangeEvent<HTMLInputElement>) { | ||
const tileuuId = e.target.value | ||
selectTile(tileuuId) | ||
} | ||
|
||
return ( | ||
<div className={classes.selectTileSection}> | ||
<Heading2 className={classes.heading}> | ||
Holdeplasser i avgangstavlen | ||
</Heading2> | ||
<div data-cy="tiles"> | ||
{!tiles.length ? ( | ||
<Paragraph className={classes.emptyTilesMessage}> | ||
Du må legge til en holdeplass for at den skal vises her. | ||
Bruk søkefeltet og trykk “legg til”. | ||
</Paragraph> | ||
) : ( | ||
<RadioGroup | ||
name="select-tile" | ||
value={selectedTileId || null} | ||
onChange={handleTileSelected} | ||
> | ||
{tiles.map((tile) => { | ||
switch (tile.type) { | ||
case 'stop_place': | ||
return ( | ||
<StopPlaceRadioOption | ||
tile={tile} | ||
key={tile.uuid} | ||
/> | ||
) | ||
case 'quay': | ||
return ( | ||
<QuayRadioOption | ||
tile={tile} | ||
key={tile.uuid} | ||
/> | ||
) | ||
} | ||
})} | ||
</RadioGroup> | ||
)} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export { SelectTile } |
13 changes: 13 additions & 0 deletions
13
next-tavla/src/Admin/scenarios/SelectTile/styles.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.selectTileSection { | ||
width: 30%; | ||
min-width: fit-content; | ||
} | ||
|
||
.heading { | ||
font-size: 1.5em; | ||
} | ||
|
||
.emptyTilesMessage { | ||
text-align: center; | ||
width: 20em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
next-tavla/src/Admin/scenarios/TileSettings/styles.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
import { TTile } from 'types/tile' | ||
import React from 'react' | ||
import { TileSettings } from '../TileSettings' | ||
import React, { useState } from 'react' | ||
import { TileSettings } from 'Admin/scenarios/TileSettings' | ||
import { SelectTile } from 'Admin/scenarios/SelectTile' | ||
import classes from './styles.module.css' | ||
|
||
function TilesOverview({ tiles }: { tiles: TTile[] }) { | ||
return <TileSettings tile={tiles[0]} /> | ||
const [selectedTileId, setSelectedTileId] = useState<string>() | ||
|
||
const selectedTile = tiles.find((tile) => tile.uuid === selectedTileId) | ||
|
||
return ( | ||
<div className={classes.overviewWrapper}> | ||
<SelectTile | ||
tiles={tiles} | ||
selectTile={setSelectedTileId} | ||
selectedTileId={selectedTileId} | ||
/> | ||
|
||
<TileSettings tile={selectedTile} /> | ||
</div> | ||
) | ||
} | ||
|
||
export { TilesOverview } |
15 changes: 2 additions & 13 deletions
15
next-tavla/src/Admin/scenarios/TilesOverview/styles.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,4 @@ | ||
.tableTile { | ||
height: 100%; | ||
width: 100%; | ||
padding: 1em; | ||
border-radius: 0.5em; | ||
background-color: var(--secondary-background-color); | ||
color: white; | ||
} | ||
|
||
.tileHeader { | ||
.overviewWrapper { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
padding-bottom: 0.5em; | ||
gap: 2em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
query QuayName($id: String!) { | ||
quay(id: $id) { | ||
name | ||
description | ||
publicCode | ||
id | ||
} | ||
} |
Oops, something went wrong.