Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cypress/e2e/stop-registry/stopAreaDetails.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,9 @@ describe('Stop area details', () => {
stopAreaDetailsPage.versioningRow
.getValidityPeriod()
.shouldHaveText('1.1.2000-1.1.2052');

stopAreaDetailsPage.memberStops.getStopRow('E2E011').shouldBeVisible();

stopAreaDetailsPage.memberStops.getStopRow('E2E011').within(() => {
cy.get('[title="Voimassaolo"]').should(
'have.text',
Expand Down
6 changes: 6 additions & 0 deletions cypress/e2e/stop-registry/stopDetails.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,12 @@ describe('Stop details', () => {
.shouldHaveText('Pohjoisesplanadi|Norraesplanaden');
stopDetailsPage.validityPeriod().should('contain', '20.3.2020-31.5.2050');

stopDetailsPage
.changeHistoryLink()
.shouldBeVisible()
.invoke('text')
.should('match', /\d{2}\.\d{2}\.\d{4}\s+\d{2}:\d{2}/); // Matches format: DD.MM.YYYY HH:mm

stopDetailsPage.headerSummaryRow.lineCount().should('have.text', 0);

stopDetailsPage.basicDetailsTabPanel().should('be.visible');
Expand Down
4 changes: 4 additions & 0 deletions cypress/pageObjects/stop-registry/StopDetailsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export class StopDetailsPage {
return cy.getByTestId('StopDetailsPage::editStopValidityButton');
}

changeHistoryLink() {
return cy.getByTestId('StopDetailsPage::changeHistoryLink');
}

basicDetailsTabButton() {
return cy.getByTestId('StopDetailsPage::basicDetailsTabButton');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { gql } from '@apollo/client';
import {
StopsDatabaseQuayBoolExp,
useGetLatestQuayChangeQuery,
useGetQuayChangeHistoryQuery,
} from '../../../../generated/graphql';

const GQL_GET_QUAY_CHANGE_HISTORY = gql`
query GetQuayChangeHistory($where: stops_database_quay_bool_exp!) {
stopsDb: stops_database {
quay: stops_database_quay(where: $where, order_by: { version: desc }) {
changed
changed_by
public_code
version
version_comment
}
}
}
`;

const GQL_GET_LATEST_QUAY_CHANGE = gql`
query GetLatestQuayChange($where: stops_database_quay_bool_exp!) {
stopsDb: stops_database {
quay: stops_database_quay(
where: $where
order_by: { version: desc }
limit: 1
) {
changed
changed_by
public_code
}
}
}
`;

export function useGetQuayChangeHistory(where: StopsDatabaseQuayBoolExp) {
const { data, ...rest } = useGetQuayChangeHistoryQuery({
variables: { where },
});

const quayVersions = data?.stopsDb?.quay ?? [];

return {
...rest,
quayVersions,
};
}

export function useGetLatestQuayChange(where: StopsDatabaseQuayBoolExp) {
const { data, ...rest } = useGetLatestQuayChangeQuery({
variables: { where },
});

const latestQuay = data?.stopsDb?.quay?.[0];

const latestQuayChangeData = {
changed: latestQuay?.changed ?? null,
changedBy: latestQuay?.changed_by ?? null,
};

return {
...rest,
latestQuayChangeData,
};
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { FC, useContext, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { MdWarning } from 'react-icons/md';
import { Link } from 'react-router';
import { useRequiredParams } from '../../../../hooks';
import { Container, Visible } from '../../../../layoutComponents';
import { mapToShortDate } from '../../../../time';
import { Path, routeDetails } from '../../../../router/routeDetails';
import { mapToShortDate, mapUTCToDateTime } from '../../../../time';
import { LoadingWrapper } from '../../../../uiComponents/LoadingWrapper';
import { navigationBlockerContext } from '../../../forms/common/NavigationBlocker';
import { BasicDetailsSection } from './basic-details';
Expand Down Expand Up @@ -33,6 +35,7 @@ const testIds = {
technicalFeaturesTabPanel: 'StopDetailsPage::technicalFeaturesTabPanel',
infoSpotsTabPanel: 'StopDetailsPage::infoSpotsTabPanel',
loadingStopDetails: 'StopDetailsPage::loadingStopDetails',
changeHistoryLink: 'StopDetailsPage::changeHistoryLink',
};

export const StopDetailsPage: FC = () => {
Expand All @@ -54,17 +57,28 @@ export const StopDetailsPage: FC = () => {
<StopHeaderSummaryRow className="my-2" stopDetails={stopDetails} />
<StopDetailsVersion label={label} />
<hr className="my-4" />
<div className="my-4 flex items-center gap-2">
<h2>{t('stopDetails.stopDetails')}</h2>
<div
title={t('accessibility:stops.validityPeriod')}
data-testid={testIds.validityPeriod}
>
{mapToShortDate(stopDetails?.validity_start)}
<span className="mx-1">-</span>
{mapToShortDate(stopDetails?.validity_end)}
<div className="my-4 flex">
<div className="flex items-center gap-2">
<h2>{t('stopDetails.stopDetails')}</h2>
<div
title={t('accessibility:stops.validityPeriod')}
data-testid={testIds.validityPeriod}
>
{mapToShortDate(stopDetails?.validity_start)}
<span className="mx-1">-</span>
{mapToShortDate(stopDetails?.validity_end)}
</div>
<EditStopValidityButton stop={stopDetails} />
</div>
<EditStopValidityButton stop={stopDetails} />
<Link
to={routeDetails[Path.stopDetails].getLink(label)}
className="ml-auto flex items-center text-base text-tweaked-brand hover:underline"
data-testid={testIds.changeHistoryLink}
>
{mapUTCToDateTime(stopDetails?.quay?.changed)} |{' '}
{stopDetails?.quay?.changedByUserName ?? 'HSL'}{' '}
<i className="icon-history text-xl" aria-hidden />
</Link>
</div>
<DetailTabSelector
className="mb-3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ export const useEditStopBasicDetails = () => {
const changesToTiamatDb = prepareEditForTiamatDb(editParams);
await updateStopPlaceMutation({
variables: changesToTiamatDb,
refetchQueries: ['GetStopDetails', 'GetLatestQuayChange'],
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const useEditStopExternalLinks = () => {
const changesToTiamatDb = prepareEditForTiamatDb(editParams);
await updateStopPlaceMutation({
variables: changesToTiamatDb,
refetchQueries: ['GetStopDetails', 'GetLatestQuayChange'],
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export const useEditStopLocationDetails = () => {
const changesToTiamatDb = prepareEditForTiamatDb(editParams);
await updateStopPlaceMutation({
variables: changesToTiamatDb,
refetchQueries: ['GetStopDetails', 'GetLatestQuayChange'],
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export const useEditStopMaintenanceDetails = () => {
const changesToTiamatDb = prepareEditForTiamatDb(editParams);
await updateStopPlaceMutation({
variables: changesToTiamatDb,
refetchQueries: ['GetStopDetails', 'GetLatestQuayChange'],
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ export const useEditStopMeasurementDetails = () => {
const changesToTiamatDb = prepareEditForTiamatDb(editParams);
await updateStopPlaceMutation({
variables: changesToTiamatDb,
refetchQueries: ['GetStopDetails', 'GetLatestQuayChange'],
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export const useEditStopShelters = () => {
const changesToTiamatDb = prepareEditForTiamatDb(editParams);
await updateStopPlaceMutation({
variables: changesToTiamatDb,
refetchQueries: ['GetStopDetails', 'GetLatestQuayChange'],
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const useEditStopSignageDetails = () => {
const changesToTiamatDb = prepareEditForTiamatDb(editParams);
await updateStopPlaceMutation({
variables: changesToTiamatDb,
refetchQueries: ['GetStopDetails', 'GetLatestQuayChange'],
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
useObservationDateQueryParam,
useUrlQuery,
} from '../../../../hooks/urlQuery';
import { useGetUserNames } from '../../../../hooks/useGetUserNames';
import { useRequiredParams } from '../../../../hooks/useRequiredParams';
import {
EnrichedStopPlace,
Expand All @@ -31,6 +32,7 @@ import {
getStopPlacesFromQueryResult,
} from '../../../../utils';
import { mapToEnrichedQuay } from '../../utils';
import { useGetLatestQuayChange } from '../queries/useGetQuayChangeHistory';

const GQL_SCHEDULED_STOP_POINT_DETAIL_FIELDS = gql`
fragment scheduled_stop_point_detail_fields on service_pattern_scheduled_stop_point {
Expand Down Expand Up @@ -367,6 +369,11 @@ const getStopDetails = (
observationDateTs: number,
priority: number,
label: string,
getUserNameById: (userId: string | null | undefined) => string | null,
quayChangeData?: {
changed: string | null;
changedBy: string | null;
},
): StopWithDetails | null => {
const stopPlaceResults = data?.stopsDb?.newestVersion ?? [];

Expand Down Expand Up @@ -397,13 +404,18 @@ const getStopDetails = (
return null;
}

const changeData = quayChangeData;
const changedByUserName = getUserNameById(changeData?.changedBy);

return {
...result.stopPoint,
location: getGeometryPoint(result.stopPoint.measured_location),
stop_place: getEnrichedStopPlace(result.stopPlace),
quay: mapToEnrichedQuay(
result.selectedQuay,
result.stopPlace?.accessibilityAssessment,
changeData?.changed,
changedByUserName,
),
};
};
Expand All @@ -426,24 +438,53 @@ export const useGetStopDetails = () => {
const { observationDate } = useObservationDateQueryParam();
const { queryParams } = useUrlQuery();
const priority = Number(queryParams.priority);
const { getUserNameById } = useGetUserNames();

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

const { latestQuayChangeData } = useGetLatestQuayChange({
public_code: { _eq: label },
});

const observationDateTs = observationDate.valueOf();
const stopDetails = useMemo(
() => getStopDetails(data, observationDateTs, priority, label),
[data, observationDateTs, priority, label],
() =>
getStopDetails(
data,
observationDateTs,
priority,
label,
getUserNameById,
latestQuayChangeData,
),
[
data,
observationDateTs,
priority,
label,
getUserNameById,
latestQuayChangeData,
],
);

return { ...rest, stopDetails };
};

export const useGetStopDetailsLazy = () => {
const [getStopDetailsLazy] = useGetStopDetailsLazyQuery();
const { getUserNameById } = useGetUserNames();

return useCallback(
async (label: string, observationDate: DateTime, priority: number) => {
async (
label: string,
observationDate: DateTime,
priority: number,
quayChangeData?: {
changed: string | null;
changedBy: string | null;
},
) => {
const where = getWhereCondition(label);
const { data, ...rest } = await getStopDetailsLazy({
variables: { where },
Expand All @@ -455,11 +496,13 @@ export const useGetStopDetailsLazy = () => {
observationDateTs,
priority,
label,
getUserNameById,
quayChangeData,
);

return { ...rest, stopDetails };
},
[getStopDetailsLazy],
[getStopDetailsLazy, getUserNameById],
);
};

Expand Down
4 changes: 4 additions & 0 deletions ui/src/components/stop-registry/utils/mapToEnrichedQuay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export function mapToEnrichedQuay(
| AccessibilityAssessmentDetailsFragment
| null
| undefined,
changed?: string | null,
changedByUserName?: string | null,
): EnrichedQuay | null {
if (!quay) {
return null;
Expand All @@ -37,6 +39,8 @@ export function mapToEnrichedQuay(
return {
...quay,
...getQuayDetailsForEnrichment(quay, accessibilityAssessment),
changed,
changedByUserName,
infoSpots: sortInfoSpots(quay.infoSpots).map((infoSpot) => ({
...infoSpot,
poster: sortPosters(infoSpot.poster),
Expand Down
Loading