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
3 changes: 1 addition & 2 deletions test-db-manager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
"pg": "^8.16.3",
"rollup": "^4.53.3",
"rollup-plugin-dts": "^6.3.0",
"ts-node": "^10.9.2",
"uuid": "^11.1.0"
"ts-node": "^10.9.2"
},
"devDependencies": {
"@types/geojson": "^7946.0.16",
Expand Down
3 changes: 1 addition & 2 deletions test-db-manager/src/builders/timetables/block.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Duration } from 'luxon';
import { v4 as uuid } from 'uuid';
import {
BlockInsertInputDeep,
VehicleServiceBlockInsertInput,
Expand All @@ -20,7 +19,7 @@ export const buildBlock = (
vehicleServiceId: UUID,
blockBase: BlockInstanceBuilder,
): VehicleServiceBlockInsertInput => ({
block_id: uuid(),
block_id: crypto.randomUUID(),
...blockBase,
vehicle_service_id: vehicleServiceId,
});
Expand Down
3 changes: 1 addition & 2 deletions test-db-manager/src/builders/timetables/journeyPatternRef.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { DateTime } from 'luxon';
import { v4 as uuid } from 'uuid';
import {
JourneyPatternRefInsertInput,
JourneyPatternRefInsertInputDeep,
Expand All @@ -16,7 +15,7 @@ export const buildJourneyPatternRefInstance = (
journeyPatternId: UUID,
journeyPatternRefBase: JourneyPatternRefInstanceBuilder,
): JourneyPatternRefInsertInput => ({
journey_pattern_ref_id: uuid(),
journey_pattern_ref_id: crypto.randomUUID(),
observation_timestamp: DateTime.fromISO('2023-01-01'),
snapshot_timestamp: DateTime.fromISO('2022-12-01'),
...journeyPatternRefBase,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { v4 as uuid } from 'uuid';
import {
PartialKeys,
RequiredKeysOnly,
Expand All @@ -13,7 +12,7 @@ export const buildStopInJourneyPatternRefInstance = (
journeyPatternRefId: UUID,
stopBase: StopInJourneyPatternInstanceBuilder,
): StopInJourneyPatternRefInsertInput => ({
scheduled_stop_point_in_journey_pattern_ref_id: uuid(),
scheduled_stop_point_in_journey_pattern_ref_id: crypto.randomUUID(),
...stopBase,
journey_pattern_ref_id: journeyPatternRefId,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Duration } from 'luxon';
import { v4 as uuid } from 'uuid';
import {
PartialKeys,
RequiredKeysOnly,
Expand Down Expand Up @@ -31,7 +30,7 @@ export const buildTimetabledPassingTimeInstance = (
stopInJourneyPatternRefId: UUID,
timetabledPassingTimeBase: TimetabledPassingTimeInstanceBuilder,
): TimetabledPassingTimeInsertInput => ({
timetabled_passing_time_id: uuid(),
timetabled_passing_time_id: crypto.randomUUID(),
...timetabledPassingTimeBase,
vehicle_journey_id: vehicleJourneyId,
scheduled_stop_point_in_journey_pattern_ref_id: stopInJourneyPatternRefId,
Expand Down
3 changes: 1 addition & 2 deletions test-db-manager/src/builders/timetables/vehicleJourney.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Duration } from 'luxon';
import { v4 as uuid } from 'uuid';
import {
JourneyPatternRefInsertInputDeep,
JourneyType,
Expand Down Expand Up @@ -33,7 +32,7 @@ export const buildVehicleJourneyInstance = (
journeyPatternRefId: UUID,
vehicleJourneyBase: VehicleJourneyInstanceBuilder,
): VehicleJourneyInsertInput => ({
vehicle_journey_id: uuid(),
vehicle_journey_id: crypto.randomUUID(),
contract_number: 'DEFAULT_CONTRACT',
journey_type: JourneyType.Standard,
is_backup_journey: false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { v4 as uuid } from 'uuid';
import {
RequiredKeys,
VehicleScheduleFrameInsertInput,
Expand All @@ -19,7 +18,7 @@ export type VehicleScheduleFrameInstanceBuilder = RequiredKeys<
export const buildVehicleScheduleFrameInstance = (
vehicleScheduleFrameBase: VehicleScheduleFrameInstanceBuilder,
): VehicleScheduleFrameInsertInput => ({
vehicle_schedule_frame_id: uuid(),
vehicle_schedule_frame_id: crypto.randomUUID(),
...vehicleScheduleFrameBase,
name_i18n: buildLocalizedString(expectValue(vehicleScheduleFrameBase.label)),
});
Expand Down
3 changes: 1 addition & 2 deletions test-db-manager/src/builders/timetables/vehicleService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Duration } from 'luxon';
import { v4 as uuid } from 'uuid';
import { DayTypeId } from '../../datasets';
import {
VehicleServiceInsertInput,
Expand All @@ -24,7 +23,7 @@ export const buildVehicleServiceInstance = (
dayTypeId: DayTypeId,
vehicleServiceBase: VehicleServiceInstanceBuilder,
): VehicleServiceInsertInput => ({
vehicle_service_id: uuid(),
vehicle_service_id: crypto.randomUUID(),
...vehicleServiceBase,
vehicle_schedule_frame_id: vehicleScheduleFrameId,
day_type_id: dayTypeId,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import padStart from 'lodash/padStart';
import range from 'lodash/range';
import { v4 as uuid } from 'uuid';
import { StopInJourneyPatternRefInsertInput } from '../../types';
import { expectValue } from '../../utils';
import { seedJourneyPatternRefs } from './journeyPatternRefs';
Expand All @@ -19,7 +18,7 @@ const buildLabels = ({
};

const buildStopInJourneyPatternRef = ({
id = uuid(),
id = crypto.randomUUID(),
journeyPatternRefId,
label,
sequenceNumber,
Expand Down
21 changes: 14 additions & 7 deletions test-db-manager/src/datasets/timetables/vehicleJourneys.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import times from 'lodash/times';
import { v4 as uuid } from 'uuid';
import { JourneyType, VehicleJourneyInsertInput } from '../../types';
import { expectValue } from '../../utils';
import { seedJourneyPatternRefs } from './journeyPatternRefs';
Expand Down Expand Up @@ -47,32 +46,40 @@ const buildVehicleJourney = ({

export const seedVehicleJourneys: VehicleJourneyInsertInput[] = [
// Journeys 1-20, all belong to same journey pattern and service block (Vehicle 1 Mon-Fri)
...times(20, () => buildVehicleJourney({ vehicleJourneyId: uuid() })),
...times(20, () =>
buildVehicleJourney({ vehicleJourneyId: crypto.randomUUID() }),
),
// Journeys 21-25, opposite direction (Vehicle 1 Mon-Fri)
...times(5, () =>
buildVehicleJourney({
vehicleJourneyId: uuid(),
vehicleJourneyId: crypto.randomUUID(),
journeyPatternRefId: expectValue(
seedJourneyPatternRefs[1].journey_pattern_ref_id,
),
}),
),
// Journeys 26-29, all belong to same journey pattern and service block (Vehicle 1 Sat)
...times(4, () =>
buildVehicleJourney({ vehicleJourneyId: uuid(), blockId: satBlockId }),
buildVehicleJourney({
vehicleJourneyId: crypto.randomUUID(),
blockId: satBlockId,
}),
),
// journey 30, belongs to service block (Vehicle 1 Sun)
buildVehicleJourney({ vehicleJourneyId: uuid(), blockId: sunBlockId }),
buildVehicleJourney({
vehicleJourneyId: crypto.randomUUID(),
blockId: sunBlockId,
}),
// journeys 31-40 (Vehicle 1 Mon-Fri December 2023, special priority)
...times(10, () =>
buildVehicleJourney({
vehicleJourneyId: uuid(),
vehicleJourneyId: crypto.randomUUID(),
blockId: decBlockId,
}),
),
// Journey 41: for hidden variant Mon-Fri block.
buildVehicleJourney({
vehicleJourneyId: uuid(),
vehicleJourneyId: crypto.randomUUID(),
journeyPatternRefId: expectValue(
seedJourneyPatternRefs[2].journey_pattern_ref_id,
),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { v4 as uuid } from 'uuid';
import { VehicleServiceBlockInsertInput } from '../../types';
import { seedVehicleServicesByName } from './vehicleServices';

const buildVehicleServiceBlock = ({
blockId = uuid(),
blockId = crypto.randomUUID(),
vehicleServiceId,
}: {
blockId?: UUID;
Expand Down
11 changes: 5 additions & 6 deletions test-db-manager/src/datasets/timetables/vehicleServices.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { v4 as uuid } from 'uuid';
import { VehicleServiceInsertInput } from '../../types';
import { MON_FRI_DAY_TYPE, SAT_DAY_TYPE, SUN_DAY_TYPE } from './dayTypes';
import { seedVehicleScheduleFramesByName } from './vehicleScheduleFrames';
Expand All @@ -12,31 +11,31 @@ const dec23VehicleScheduleFrameId =
export const seedVehicleServicesByName = {
// vehicle 1, Mon-Fri
v1MonFri: {
vehicle_service_id: uuid(),
vehicle_service_id: crypto.randomUUID(),
day_type_id: MON_FRI_DAY_TYPE,
vehicle_schedule_frame_id: basicVehicleScheduleFrameId,
},
// vehicle 1, Sat
v1Sat: {
vehicle_service_id: uuid(),
vehicle_service_id: crypto.randomUUID(),
day_type_id: SAT_DAY_TYPE,
vehicle_schedule_frame_id: basicVehicleScheduleFrameId,
},
// vehicle 1, Sun
v1Sun: {
vehicle_service_id: uuid(),
vehicle_service_id: crypto.randomUUID(),
day_type_id: SUN_DAY_TYPE,
vehicle_schedule_frame_id: basicVehicleScheduleFrameId,
},
// vehicle 1, December 2023
v1Dec2023: {
vehicle_service_id: uuid(),
vehicle_service_id: crypto.randomUUID(),
day_type_id: MON_FRI_DAY_TYPE,
vehicle_schedule_frame_id: dec23VehicleScheduleFrameId,
},
// Hidden variant, Mon-Fri
hiddenVariantMonFri: {
vehicle_service_id: uuid(),
vehicle_service_id: crypto.randomUUID(),
day_type_id: MON_FRI_DAY_TYPE,
vehicle_schedule_frame_id: basicVehicleScheduleFrameId,
},
Expand Down
32 changes: 1 addition & 31 deletions ui/src/components/common/AsyncTaskList/AsyncTaskList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,11 @@ export function useAsyncTasks() {
return useContext(AsyncTaskListContext).tasks;
}

/**
* Generates a V7 type UUID with not so good random bits.
*/
function fallbackUUID() {
const timestampHex = BigInt(Date.now()).toString(16).padStart(12, '0');
const timestampHead = timestampHex.substring(0, 8);
const timestampTail = timestampHex.substring(8, 12);

const randomIntString = Math.random().toString().replace('0.', '');
const randomHex = BigInt(randomIntString)
.toString(16)
.padStart(12)
.substring(0, 12);

return `${timestampHead}-${timestampTail}-7000-8000-${randomHex}`;
}

/**
* Get V4 UUID, if on local host or on HTTPS connection.
* Falls back on custom V7 generator on HTTP connection,
* such as when running Cypress tests in Github.
*/
function genId() {
if (window.crypto.randomUUID) {
return window.crypto.randomUUID();
}

return fallbackUUID();
}

export const AsyncTaskListProvider: FC<PropsWithChildren> = ({ children }) => {
const [tasks, setTasks] = useState<ReadonlyArray<Task>>([]);

const registerTask = useCallback((register: RegisterTask) => {
const id = genId();
const id = crypto.randomUUID();

const onProgress: OnProgress = (progress) => {
setTasks((existingTaskStates) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ const InfoSpotsFormComponent: ForwardRefRenderFunction<
lines: '',
toBeDeletedPoster: false,
// Random unique ID for new posters as it is used as key, it is not sent to the backend
id: window.crypto.randomUUID
? window.crypto.randomUUID()
: Math.random().toString(16).slice(2),
id: crypto.randomUUID(),
};

setValue(`infoSpots.${infoSpotIndex}.poster`, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ export function mapInfoSpotDataToFormState(
zoneLabel: infoSpot.zoneLabel ?? null,
poster: compact(infoSpot.poster).map((poster) => ({
// Just use random ID to use as key for poster components
id:
poster.id ??
(window.crypto.randomUUID
? window.crypto.randomUUID()
: Math.random().toString(16).slice(2)),
id: poster.id ?? crypto.randomUUID(),
label: poster.label ?? null,
lines: poster.lines ?? null,
size: determineItemSize(poster),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@ const TerminalInfoSpotsFormComponent: ForwardRefRenderFunction<
label: '',
lines: '',
toBeDeletedPoster: false,
id: window.crypto.randomUUID
? window.crypto.randomUUID()
: Math.random().toString(16).slice(2),
id: crypto.randomUUID(),
};

setValue('poster', [...(getValues('poster') ?? []), newPoster]);
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12329,11 +12329,6 @@ uuid-validate@^0.0.3:
resolved "https://registry.yarnpkg.com/uuid-validate/-/uuid-validate-0.0.3.tgz#e30617f75dc742a0e4f95012a11540faf9d39ab4"
integrity sha512-Fykw5U4eZESbq739BeLvEBFRuJODfrlmjx5eJux7W817LjRaq4b7/i4t2zxQmhcX+fAj4nMfRdTzO4tmwLKn0w==

uuid@^11.1.0:
version "11.1.0"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-11.1.0.tgz#9549028be1753bb934fc96e2bca09bb4105ae912"
integrity sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A==

uuid@^8.3.2:
version "8.3.2"
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
Expand Down
Loading