Skip to content

Commit 2b8786e

Browse files
committed
Get update history data for quays
1 parent 8c96196 commit 2b8786e

File tree

9 files changed

+277
-15
lines changed

9 files changed

+277
-15
lines changed

cypress/e2e/stop-registry/stopDetails.cy.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,12 @@ describe('Stop details', () => {
526526
.shouldHaveText('Pohjoisesplanadi|Norraesplanaden');
527527
stopDetailsPage.validityPeriod().should('contain', '20.3.2020-31.5.2050');
528528

529+
stopDetailsPage
530+
.changeHistoryLink()
531+
.shouldBeVisible()
532+
.invoke('text')
533+
.should('match', /\d{2}\.\d{2}\.\d{4}\s+\d{2}:\d{2}/); // Matches format: DD.MM.YYYY HH:mm
534+
529535
stopDetailsPage.headerSummaryRow.lineCount().should('have.text', 0);
530536

531537
stopDetailsPage.basicDetailsTabPanel().should('be.visible');

cypress/pageObjects/stop-registry/StopDetailsPage.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ export class StopDetailsPage {
5858
return cy.getByTestId('StopDetailsPage::editStopValidityButton');
5959
}
6060

61+
changeHistoryLink() {
62+
return cy.getByTestId('StopDetailsPage::changeHistoryLink');
63+
}
64+
6165
basicDetailsTabButton() {
6266
return cy.getByTestId('StopDetailsPage::basicDetailsTabButton');
6367
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { gql } from '@apollo/client';
2+
import {
3+
StopsDatabaseQuayBoolExp,
4+
useGetLatestQuayChangeQuery,
5+
useGetQuayChangeHistoryQuery,
6+
} from '../../../../generated/graphql';
7+
8+
const GQL_GET_QUAY_CHANGE_HISTORY = gql`
9+
query GetQuayChangeHistory($where: stops_database_quay_bool_exp) {
10+
stopsDb: stops_database {
11+
quay: stops_database_quay(where: $where, order_by: { version: desc }) {
12+
changed
13+
changed_by
14+
public_code
15+
version
16+
version_comment
17+
}
18+
}
19+
}
20+
`;
21+
22+
const GQL_GET_LATEST_QUAY_CHANGE = gql`
23+
query GetLatestQuayChange($where: stops_database_quay_bool_exp) {
24+
stopsDb: stops_database {
25+
quay: stops_database_quay(
26+
where: $where
27+
order_by: { version: desc }
28+
limit: 1
29+
) {
30+
changed
31+
changed_by
32+
public_code
33+
}
34+
}
35+
}
36+
`;
37+
38+
export const useGetQuayChangeHistory = (where: StopsDatabaseQuayBoolExp) => {
39+
const { data, ...rest } = useGetQuayChangeHistoryQuery({
40+
variables: { where },
41+
});
42+
43+
const quayVersions = data?.stopsDb?.quay ?? [];
44+
45+
return {
46+
...rest,
47+
quayVersions,
48+
};
49+
};
50+
51+
export const useGetLatestQuayChange = (where: StopsDatabaseQuayBoolExp) => {
52+
const { data, ...rest } = useGetLatestQuayChangeQuery({
53+
variables: { where },
54+
});
55+
56+
const latestQuay = data?.stopsDb?.quay?.[0];
57+
58+
const latestQuayChangeData = {
59+
changed: latestQuay?.changed ?? null,
60+
changedBy: latestQuay?.changed_by ?? null,
61+
};
62+
63+
return {
64+
...rest,
65+
latestQuayChangeData,
66+
};
67+
};

ui/src/components/stop-registry/stops/stop-details/StopDetailsPage.tsx

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { FC, useContext, useState } from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { MdWarning } from 'react-icons/md';
4+
import { Link } from 'react-router';
45
import { useRequiredParams } from '../../../../hooks';
56
import { Container, Visible } from '../../../../layoutComponents';
6-
import { mapToShortDate } from '../../../../time';
7+
import { Path, routeDetails } from '../../../../router/routeDetails';
8+
import { mapToShortDate, mapUTCToDateTime } from '../../../../time';
79
import { LoadingWrapper } from '../../../../uiComponents/LoadingWrapper';
810
import { navigationBlockerContext } from '../../../forms/common/NavigationBlocker';
911
import { BasicDetailsSection } from './basic-details';
@@ -33,6 +35,7 @@ const testIds = {
3335
technicalFeaturesTabPanel: 'StopDetailsPage::technicalFeaturesTabPanel',
3436
infoSpotsTabPanel: 'StopDetailsPage::infoSpotsTabPanel',
3537
loadingStopDetails: 'StopDetailsPage::loadingStopDetails',
38+
changeHistoryLink: 'StopDetailsPage::changeHistoryLink',
3639
};
3740

3841
export const StopDetailsPage: FC = () => {
@@ -54,17 +57,28 @@ export const StopDetailsPage: FC = () => {
5457
<StopHeaderSummaryRow className="my-2" stopDetails={stopDetails} />
5558
<StopDetailsVersion label={label} />
5659
<hr className="my-4" />
57-
<div className="my-4 flex items-center gap-2">
58-
<h2>{t('stopDetails.stopDetails')}</h2>
59-
<div
60-
title={t('accessibility:stops.validityPeriod')}
61-
data-testid={testIds.validityPeriod}
62-
>
63-
{mapToShortDate(stopDetails?.validity_start)}
64-
<span className="mx-1">-</span>
65-
{mapToShortDate(stopDetails?.validity_end)}
60+
<div className="my-4 flex">
61+
<div className="flex items-center gap-2">
62+
<h2>{t('stopDetails.stopDetails')}</h2>
63+
<div
64+
title={t('accessibility:stops.validityPeriod')}
65+
data-testid={testIds.validityPeriod}
66+
>
67+
{mapToShortDate(stopDetails?.validity_start)}
68+
<span className="mx-1">-</span>
69+
{mapToShortDate(stopDetails?.validity_end)}
70+
</div>
71+
<EditStopValidityButton stop={stopDetails} />
6672
</div>
67-
<EditStopValidityButton stop={stopDetails} />
73+
<Link
74+
to={routeDetails[Path.stopDetails].getLink(label)}
75+
className="ml-auto flex items-center text-base text-tweaked-brand hover:underline"
76+
data-testid={testIds.changeHistoryLink}
77+
>
78+
{mapUTCToDateTime(stopDetails?.quay?.changed)} |{' '}
79+
{stopDetails?.quay?.changedByUserName ?? 'HSL'}{' '}
80+
<i className="icon-history text-xl" aria-hidden />
81+
</Link>
6882
</div>
6983
<DetailTabSelector
7084
className="mb-3"

ui/src/components/stop-registry/stops/stop-details/useGetStopDetails.ts

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
useObservationDateQueryParam,
1616
useUrlQuery,
1717
} from '../../../../hooks/urlQuery';
18+
import { useGetUserNames } from '../../../../hooks/useGetUserNames';
1819
import { useRequiredParams } from '../../../../hooks/useRequiredParams';
1920
import {
2021
EnrichedStopPlace,
@@ -31,6 +32,7 @@ import {
3132
getStopPlacesFromQueryResult,
3233
} from '../../../../utils';
3334
import { mapToEnrichedQuay } from '../../utils';
35+
import { useGetLatestQuayChange } from '../queries/useGetQuayChangeHistory';
3436

3537
const GQL_SCHEDULED_STOP_POINT_DETAIL_FIELDS = gql`
3638
fragment scheduled_stop_point_detail_fields on service_pattern_scheduled_stop_point {
@@ -367,6 +369,11 @@ const getStopDetails = (
367369
observationDateTs: number,
368370
priority: number,
369371
label: string,
372+
getUserNameById: (userId: string | null | undefined) => string | null,
373+
quayChangeData?: {
374+
changed: string | null;
375+
changedBy: string | null;
376+
},
370377
): StopWithDetails | null => {
371378
const stopPlaceResults = data?.stopsDb?.newestVersion ?? [];
372379

@@ -397,13 +404,18 @@ const getStopDetails = (
397404
return null;
398405
}
399406

407+
const changeData = quayChangeData;
408+
const changedByUserName = getUserNameById(changeData?.changedBy);
409+
400410
return {
401411
...result.stopPoint,
402412
location: getGeometryPoint(result.stopPoint.measured_location),
403413
stop_place: getEnrichedStopPlace(result.stopPlace),
404414
quay: mapToEnrichedQuay(
405415
result.selectedQuay,
406416
result.stopPlace?.accessibilityAssessment,
417+
changeData?.changed,
418+
changedByUserName,
407419
),
408420
};
409421
};
@@ -426,24 +438,53 @@ export const useGetStopDetails = () => {
426438
const { observationDate } = useObservationDateQueryParam();
427439
const { queryParams } = useUrlQuery();
428440
const priority = Number(queryParams.priority);
441+
const { getUserNameById } = useGetUserNames();
429442

430443
const where = getWhereCondition(label);
431444
const { data, ...rest } = useGetStopDetailsQuery({ variables: { where } });
432445

446+
const { latestQuayChangeData } = useGetLatestQuayChange({
447+
public_code: { _eq: label },
448+
});
449+
433450
const observationDateTs = observationDate.valueOf();
434451
const stopDetails = useMemo(
435-
() => getStopDetails(data, observationDateTs, priority, label),
436-
[data, observationDateTs, priority, label],
452+
() =>
453+
getStopDetails(
454+
data,
455+
observationDateTs,
456+
priority,
457+
label,
458+
getUserNameById,
459+
latestQuayChangeData,
460+
),
461+
[
462+
data,
463+
observationDateTs,
464+
priority,
465+
label,
466+
getUserNameById,
467+
latestQuayChangeData,
468+
],
437469
);
438470

439471
return { ...rest, stopDetails };
440472
};
441473

442474
export const useGetStopDetailsLazy = () => {
443475
const [getStopDetailsLazy] = useGetStopDetailsLazyQuery();
476+
const { getUserNameById } = useGetUserNames();
444477

445478
return useCallback(
446-
async (label: string, observationDate: DateTime, priority: number) => {
479+
async (
480+
label: string,
481+
observationDate: DateTime,
482+
priority: number,
483+
quayChangeData?: {
484+
changed: string | null;
485+
changedBy: string | null;
486+
},
487+
) => {
447488
const where = getWhereCondition(label);
448489
const { data, ...rest } = await getStopDetailsLazy({
449490
variables: { where },
@@ -455,11 +496,13 @@ export const useGetStopDetailsLazy = () => {
455496
observationDateTs,
456497
priority,
457498
label,
499+
getUserNameById,
500+
quayChangeData,
458501
);
459502

460503
return { ...rest, stopDetails };
461504
},
462-
[getStopDetailsLazy],
505+
[getStopDetailsLazy, getUserNameById],
463506
);
464507
};
465508

ui/src/components/stop-registry/utils/mapToEnrichedQuay.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ export function mapToEnrichedQuay(
2929
| AccessibilityAssessmentDetailsFragment
3030
| null
3131
| undefined,
32+
changed?: string | null,
33+
changedByUserName?: string | null,
3234
): EnrichedQuay | null {
3335
if (!quay) {
3436
return null;
@@ -37,6 +39,8 @@ export function mapToEnrichedQuay(
3739
return {
3840
...quay,
3941
...getQuayDetailsForEnrichment(quay, accessibilityAssessment),
42+
changed,
43+
changedByUserName,
4044
infoSpots: sortInfoSpots(quay.infoSpots).map((infoSpot) => ({
4145
...infoSpot,
4246
poster: sortPosters(infoSpot.poster),

0 commit comments

Comments
 (0)