-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create Vehicles page #137
Open
Skasix00
wants to merge
23
commits into
production
Choose a base branch
from
digital-79-finalizar-pagina-veiculos
base: production
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Create Vehicles page #137
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
97b90ae
Created the base structure for vehicles page
Skasix00 335775f
Added translations
Skasix00 380d44d
Context mods
Skasix00 9c7ce28
Added lines shapes and popup handling is fixed
Skasix00 3d43b48
Startedd adding the data filters, only need to return the filtered array
Skasix00 75fd96d
Filter 100% working: Conditional Rendering fase
Skasix00 2876da0
Stylyzed the multiselect separated the popup to it's own component
Skasix00 b430640
Refactored some code on vehicle map and vehiclelistcontext
Skasix00 58ac1d5
Added coloes to the lines and added stops waypoints
Skasix00 12416be
Finished the popup
Skasix00 2cbafd0
Ruff layout added, all the functionallity converted to this layout
Skasix00 3b2c79e
Layout fully converted and functionality 100% working
Skasix00 d6d0ae6
Tweaked some names and fixed some bugs
Skasix00 1e45afb
Removed unused JSON formatter settings from VSCode configuration
joao-vasconcelos 644af1f
Use named exports
joao-vasconcelos ff284c2
Remove unused VehiclesListGroup
joao-vasconcelos 7a76f24
Update translation keys for VehiclesList component
joao-vasconcelos 7cd07f8
Merge branch 'production' into digital-79-finalizar-pagina-veiculos
joao-vasconcelos e72ae1f
Whitespace
joao-vasconcelos 96ff24a
Include previous commit changes (before merge with production)
joao-vasconcelos 1c12a39
Added vehicle list box and starting code refactoring
Skasix00 c20a5d7
Add styles for no data container in VehiclesListToolbar
Skasix00 908bd45
Modified VehhicleList Table Data
Skasix00 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* * */ | ||
|
||
import { VehiclesListContextProvider } from '@/contexts/VehiclesList.context'; | ||
|
||
/* * */ | ||
|
||
export default function Layout({ children }) { | ||
return ( | ||
<VehiclesListContextProvider> | ||
{children} | ||
</VehiclesListContextProvider> | ||
); | ||
} |
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 @@ | ||
/* * */ | ||
|
||
import { VehiclesList } from '@/components/vehicles/VehiclesList'; | ||
|
||
/* * */ | ||
|
||
export default function Page() { | ||
return <VehiclesList />; | ||
} |
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
19 changes: 19 additions & 0 deletions
19
frontend/components/vehicles/VehicleListInfoBlock/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,19 @@ | ||
/* * */ | ||
|
||
import { useTranslations } from 'next-intl'; | ||
|
||
/* * */ | ||
export function VehiclesListInfoBlock() { | ||
// | ||
// A. Setup variables | ||
|
||
const t = useTranslations('vehicles.VehiclesListInfoBlock'); | ||
|
||
// | ||
// B. Render components | ||
return ( | ||
<> | ||
<p>{t('heading')}</p> | ||
</> | ||
); | ||
} |
39 changes: 39 additions & 0 deletions
39
frontend/components/vehicles/VehicleListMapBadge/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,39 @@ | ||
'use client'; | ||
|
||
/* * */ | ||
|
||
import type { Line } from '@carrismetropolitana/api-types/network'; | ||
|
||
import classNames from 'classnames/bind'; | ||
|
||
import styles from './styles.module.css'; | ||
|
||
/* * */ | ||
|
||
interface Props { | ||
color?: string | ||
lineData?: Line | ||
shortName?: string | ||
textColor?: string | ||
} | ||
|
||
/* * */ | ||
|
||
const cx = classNames.bind(styles); | ||
|
||
/* * */ | ||
|
||
export function VehicleListMapBadge({ lineData }: Props) { | ||
// A. Render components | ||
return ( | ||
<> | ||
<div className={cx({ badge: true, md: 'md' })} style={{ backgroundColor: lineData?.color, color: lineData?.text_color, marginBottom: '10px' }}> | ||
{lineData?.short_name || '• • •'} | ||
</div> | ||
<div> | ||
<p className={styles.line_name}>{lineData?.long_name}</p> | ||
</div> | ||
</> | ||
); | ||
// | ||
} |
38 changes: 38 additions & 0 deletions
38
frontend/components/vehicles/VehicleListMapBadge/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,38 @@ | ||
/* * */ | ||
/* BADGE */ | ||
|
||
.badge { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
border-radius: 999px; | ||
color: var(--color-system-background-100); | ||
background-color: var(--color-system-text-200); | ||
font-weight: var(--font-weight-extrabold); | ||
letter-spacing: 1px; | ||
line-height: 1; | ||
position: relative; | ||
|
||
} | ||
|
||
.badge.md { | ||
font-size: 16px; | ||
min-width: 65px; | ||
max-width: 65px; | ||
min-height: 26px; | ||
max-height: 26px; | ||
text-align: center; | ||
vertical-align: middle; | ||
display: flex; | ||
|
||
} | ||
|
||
/* * */ | ||
|
||
/* LINE HEADER */ | ||
.line_name{ | ||
color: var(--color-system-text-100); | ||
font-size: var(--font-size-subtitle); | ||
font-weight: var(--font-weight-extrabold); | ||
} | ||
/* * */ |
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,53 @@ | ||
'use client'; | ||
|
||
/* * */ | ||
|
||
import { Section } from '@/components/layout/Section'; | ||
import { Surface } from '@/components/layout/Surface'; | ||
import VehiclesListMap from '@/components/vehicles/VehiclesListMap'; | ||
import VehiclesListToolbar from '@/components/vehicles/VehiclesListToolbar'; | ||
import { useTranslations } from 'next-intl'; | ||
|
||
import { VehiclesListInfoBlock } from '../VehicleListInfoBlock'; | ||
import styles from './styles.module.css'; | ||
|
||
/* * */ | ||
|
||
export function VehiclesList() { | ||
// | ||
|
||
// | ||
// A. Setup variables | ||
|
||
const t = useTranslations('vehicles.VehiclesList'); | ||
|
||
// | ||
// B. Render components | ||
|
||
return ( | ||
<> | ||
<Surface> | ||
<Section heading={t('heading')} subheading={t('subheading')} /> | ||
</Surface> | ||
{/* <Surface> | ||
<Section withGap withPadding> | ||
<VehiclesListInfoBlock /> | ||
</Section> | ||
</Surface> */} | ||
|
||
<Surface> | ||
<Section> | ||
<div className={styles.container}> | ||
<div className={styles.mapWrapper}> | ||
<VehiclesListMap /> | ||
</div> | ||
<VehiclesListToolbar /> | ||
</div> | ||
</Section> | ||
</Surface> | ||
|
||
</> | ||
); | ||
|
||
// | ||
} |
38 changes: 38 additions & 0 deletions
38
frontend/components/vehicles/VehiclesList/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,38 @@ | ||
/* * */ | ||
/* CONTAINER */ | ||
|
||
.container { | ||
display: grid; | ||
grid-template: | ||
"a b" minmax(100vh, auto) / 1fr 1fr; | ||
align-items: flex-start; | ||
justify-content: flex-start; | ||
width: 100%; | ||
} | ||
|
||
@media (width < 1000px) { | ||
.container { | ||
grid-template: | ||
"b" 50vh [b_] | ||
"a" auto [a_] / 1fr; | ||
} | ||
} | ||
|
||
/* * */ | ||
/* MAP WRAPPER */ | ||
|
||
.mapWrapper { | ||
position: sticky; | ||
top: var(--size-height-header); | ||
grid-area: a; | ||
height: 100%; | ||
max-height: calc(100vh - var(--size-height-header)); | ||
border-right: 1px solid var(--color-system-border-100); | ||
} | ||
|
||
@media (width < 1000px) { | ||
.mapWrapper { | ||
position: static; | ||
border: none; | ||
} | ||
} |
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,115 @@ | ||
'use client'; | ||
|
||
import { MapView } from '@/components/map/MapView'; | ||
import { MapViewStylePath } from '@/components/map/MapViewStylePath'; | ||
import { | ||
MapViewStyleVehicles, | ||
MapViewStyleVehiclesInteractiveLayerId, | ||
MapViewStyleVehiclesPrimaryLayerId, | ||
} from '@/components/map/MapViewStyleVehicles'; | ||
import { transformStopDataIntoGeoJsonFeature, useStopsContext } from '@/contexts/Stops.context'; | ||
import { useVehiclesContext } from '@/contexts/Vehicles.context'; | ||
import { useVehiclesListContext } from '@/contexts/VehiclesList.context'; | ||
import { getBaseGeoJsonFeatureCollection } from '@/utils/map.utils'; | ||
import { Routes } from '@/utils/routes'; | ||
import { Pattern } from '@carrismetropolitana/api-types/network'; | ||
import { Feature, FeatureCollection, GeoJsonProperties, Geometry } from 'geojson'; | ||
import { DateTime } from 'luxon'; | ||
import { useMemo, useState } from 'react'; | ||
|
||
export default function Component() { | ||
// A. Setup variables | ||
const vehiclesListContext = useVehiclesListContext(); | ||
const vehiclesContext = useVehiclesContext(); | ||
const stopsContext = useStopsContext(); | ||
|
||
const [pattern, setPattern] = useState<Pattern[] | undefined>(undefined); | ||
const [activePathShapeGeoJson, setActivePathShapeGeoJson] = useState<Feature<Geometry, GeoJsonProperties> | FeatureCollection<Geometry, GeoJsonProperties> | undefined>(undefined); | ||
|
||
const selectedVehicleFromList = vehiclesListContext.data.selected; | ||
const selectedVehicle = selectedVehicleFromList && vehiclesContext.data.vehicles.find(vehicle => vehicle.id === selectedVehicleFromList.id); | ||
|
||
// B. Fetch Data | ||
|
||
const findTodaysDate = () => DateTime.now().toFormat('yyyyLLdd'); | ||
|
||
const fetchPattern = useMemo(async () => { | ||
if (!selectedVehicle) return []; | ||
const date = await findTodaysDate(); | ||
const patternId = vehiclesListContext.data.selected?.pattern_id; | ||
|
||
if (patternId) { | ||
const actualPattern = await fetch(`${Routes.API}/patterns/${patternId}`).then(res => res.json()); | ||
const isAvailable = actualPattern.filter(item => item.valid_on.includes(date)); | ||
|
||
setPattern(isAvailable); | ||
|
||
return isAvailable; | ||
} | ||
}, [vehiclesListContext.data.selected]); | ||
|
||
const fetchShape = useMemo(async () => { | ||
if (!pattern) return []; | ||
const color = pattern.map(item => item.color.toString()); | ||
const shape = await fetch(`${Routes.API}/shapes/${pattern[0].shape_id}`).then(res => res.json()); | ||
|
||
shape.geojson.properties = { ...shape.geojson.properties, color: color[0] }; | ||
|
||
setActivePathShapeGeoJson(shape.geojson); | ||
|
||
return shape.geojson; | ||
}, [pattern]); | ||
|
||
const activeVehiclesGeoJson = useMemo(() => { | ||
if (vehiclesListContext.data.filtered && vehiclesListContext.data.filtered.length > 0) { | ||
const features: Feature<Geometry, GeoJsonProperties>[] = []; | ||
vehiclesListContext.data.filtered.forEach((vehicle) => { | ||
const fc = vehiclesContext.actions.getVehicleByIdGeoJsonFC(vehicle.id); | ||
if (fc && fc.features && fc.features.length > 0) { | ||
features.push(fc.features[0]); | ||
} | ||
}); | ||
return { features, type: 'FeatureCollection' as const }; | ||
} | ||
else { | ||
return vehiclesContext.actions.getAllVehiclesGeoJsonFC(); | ||
} | ||
}, [vehiclesListContext.data.filtered, vehiclesContext.data.vehicles]); | ||
|
||
const activePathWaypointsGeoJson = useMemo(() => { | ||
if (!pattern) return; | ||
const collection = getBaseGeoJsonFeatureCollection(); | ||
pattern.map(pattern => pattern.path.forEach((pathStop) => { | ||
const stopData = stopsContext.actions.getStopById(pathStop.stop_id); | ||
if (!stopData) return; | ||
const result = transformStopDataIntoGeoJsonFeature(stopData); | ||
result.properties = { | ||
...result.properties, | ||
color: pattern.color, | ||
text_color: pattern.text_color, | ||
}; | ||
collection.features.push(result); | ||
})); | ||
return collection; | ||
}, [pattern, vehiclesContext.data.vehicles]); | ||
|
||
// C. Handle actions | ||
function handleLayerClick(event) { | ||
if (event.features.length === 0) { | ||
setActivePathShapeGeoJson(undefined); | ||
setPattern(undefined); | ||
vehiclesListContext.actions.updateSelectedVehicle(''); | ||
} | ||
if (event.features.length !== 0 && event.features[0].source === 'default-source-vehicles') { | ||
vehiclesListContext.actions.updateSelectedVehicle(event.features[0].properties.id); | ||
} | ||
} | ||
// D. Render component | ||
return ( | ||
<MapView id="vehiclesListMap" interactiveLayerIds={[MapViewStyleVehiclesInteractiveLayerId]} onClick={handleLayerClick}> | ||
<MapViewStyleVehicles vehiclesData={activeVehiclesGeoJson} /> | ||
<MapViewStylePath presentBeforeId={MapViewStyleVehiclesPrimaryLayerId} shapeData={activePathShapeGeoJson} waypointsData={activePathWaypointsGeoJson} /> | ||
</MapView> | ||
); | ||
// | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
É intencional não ser possível alterar os estilos nos componentes que utilizam estes layouts principais, para incentivar a consistência de layout em todo o site. Do que vi também acabaste por não usar, então acho que faz sentido retirar.