Skip to content

Commit 92c2534

Browse files
committed
Get update history data for quays
1 parent abd7162 commit 92c2534

File tree

9 files changed

+284
-14
lines changed

9 files changed

+284
-14
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: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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 getLatestQuayChangeData = () => ({
59+
changed: latestQuay?.changed ?? null,
60+
changedBy: latestQuay?.changed_by ?? null,
61+
publicCode: latestQuay?.public_code ?? null,
62+
});
63+
64+
return {
65+
...rest,
66+
getLatestQuayChangeData,
67+
};
68+
};

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

Lines changed: 24 additions & 10 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 = () => {
@@ -55,16 +58,27 @@ export const StopDetailsPage: FC = () => {
5558
<StopDetailsVersion label={label} />
5659
<hr className="my-4" />
5760
<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)}
61+
<div className="my-4 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: 54 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,12 @@ const getStopDetails = (
367369
observationDateTs: number,
368370
priority: number,
369371
label: string,
372+
getUserNameById: (userId: string | null | undefined) => string | null,
373+
getQuayChangeData: () => {
374+
changed: string | null;
375+
changedBy: string | null;
376+
publicCode: string | null;
377+
},
370378
): StopWithDetails | null => {
371379
const stopPlaceResults = data?.stopsDb?.newestVersion ?? [];
372380

@@ -397,13 +405,18 @@ const getStopDetails = (
397405
return null;
398406
}
399407

408+
const quayChangeData = getQuayChangeData();
409+
const changedByUserName = getUserNameById(quayChangeData.changedBy);
410+
400411
return {
401412
...result.stopPoint,
402413
location: getGeometryPoint(result.stopPoint.measured_location),
403414
stop_place: getEnrichedStopPlace(result.stopPlace),
404415
quay: mapToEnrichedQuay(
405416
result.selectedQuay,
406417
result.stopPlace?.accessibilityAssessment,
418+
quayChangeData.changed,
419+
changedByUserName,
407420
),
408421
};
409422
};
@@ -426,40 +439,77 @@ export const useGetStopDetails = () => {
426439
const { observationDate } = useObservationDateQueryParam();
427440
const { queryParams } = useUrlQuery();
428441
const priority = Number(queryParams.priority);
442+
const { getUserNameById } = useGetUserNames();
429443

430444
const where = getWhereCondition(label);
431445
const { data, ...rest } = useGetStopDetailsQuery({ variables: { where } });
432446

447+
const { getLatestQuayChangeData } = useGetLatestQuayChange({
448+
public_code: { _eq: label },
449+
});
450+
433451
const observationDateTs = observationDate.valueOf();
434452
const stopDetails = useMemo(
435-
() => getStopDetails(data, observationDateTs, priority, label),
436-
[data, observationDateTs, priority, label],
453+
() =>
454+
getStopDetails(
455+
data,
456+
observationDateTs,
457+
priority,
458+
label,
459+
getUserNameById,
460+
getLatestQuayChangeData,
461+
),
462+
[
463+
data,
464+
observationDateTs,
465+
priority,
466+
label,
467+
getUserNameById,
468+
getLatestQuayChangeData,
469+
],
437470
);
438471

439472
return { ...rest, stopDetails };
440473
};
441474

442475
export const useGetStopDetailsLazy = () => {
443476
const [getStopDetailsLazy] = useGetStopDetailsLazyQuery();
477+
const { getUserNameById } = useGetUserNames();
444478

445479
return useCallback(
446-
async (label: string, observationDate: DateTime, priority: number) => {
480+
async (
481+
label: string,
482+
observationDate: DateTime,
483+
priority: number,
484+
getQuayChangeData?: () => {
485+
changed: string | null;
486+
changedBy: string | null;
487+
publicCode: string | null;
488+
},
489+
) => {
447490
const where = getWhereCondition(label);
448491
const { data, ...rest } = await getStopDetailsLazy({
449492
variables: { where },
450493
});
451494

452495
const observationDateTs = observationDate.valueOf();
496+
const defaultChangeData = () => ({
497+
changed: null,
498+
changedBy: null,
499+
publicCode: null,
500+
});
453501
const stopDetails = getStopDetails(
454502
data,
455503
observationDateTs,
456504
priority,
457505
label,
506+
getUserNameById,
507+
getQuayChangeData ?? defaultChangeData,
458508
);
459509

460510
return { ...rest, stopDetails };
461511
},
462-
[getStopDetailsLazy],
512+
[getStopDetailsLazy, getUserNameById],
463513
);
464514
};
465515

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)