Thanks to visit codestin.com
Credit goes to github.com

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
4 changes: 2 additions & 2 deletions site/src/pages/TemplateBuilder/TemplateBuilderPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type FC, useCallback, useEffect, useMemo, useState } from "react";
import { useMutation, useQuery } from "react-query";
import { Navigate, useNavigate, useSearchParams } from "react-router";
import { v4 as uuidv4 } from "uuid";
import { deploymentConfig } from "#/api/queries/deployment";
import {
createTemplateFromBuilder,
Expand All @@ -11,7 +12,6 @@ import { Loader } from "#/components/Loader/Loader";
import { useAuthenticated } from "#/hooks/useAuthenticated";
import { linkToTemplate, useLinks } from "#/modules/navigation";
import { pageTitle } from "#/utils/page";
import { generateUUID } from "#/utils/uuid";
import { TemplateBuilderPageView } from "./TemplateBuilderPageView";
import type {
SelectedBaseMeta,
Expand All @@ -30,7 +30,7 @@ const TemplateBuilderPage: FC = () => {

// Stable session ID for the lifetime of this page mount, shared
// across wizard_entry and compose_completion telemetry events.
const sessionId = useMemo(() => generateUUID(), []);
const sessionId = useMemo(() => uuidv4(), []);

const builderDisabled = data?.config?.template_builder?.disabled ?? false;
const wizardReady =
Expand Down
65 changes: 0 additions & 65 deletions site/src/utils/uuid.test.ts

This file was deleted.

32 changes: 0 additions & 32 deletions site/src/utils/uuid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,3 @@ export const isUUID = (text: string) => {
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
return UUID.test(text);
};

/**
* Generate a random RFC 4122 version 4 UUID.
*
* Uses `crypto.randomUUID()` when the runtime provides it. Falls back to
* generating random bytes with `crypto.getRandomValues()` and formatting
* them as a v4 UUID for environments where `randomUUID` is unavailable
* (for example, non-secure contexts).
*/
export const generateUUID = (): string => {
if (typeof crypto.randomUUID === "function") {
return crypto.randomUUID();
}

const bytes = crypto.getRandomValues(new Uint8Array(16));
// Set the version (4) and variant (RFC 4122) bits.
bytes[6] = (bytes[6] & 0x0f) | 0x40;
bytes[8] = (bytes[8] & 0x3f) | 0x80;

const hex: string[] = [];
for (const byte of bytes) {
hex.push(byte.toString(16).padStart(2, "0"));
}

return [
hex.slice(0, 4).join(""),
hex.slice(4, 6).join(""),
hex.slice(6, 8).join(""),
hex.slice(8, 10).join(""),
hex.slice(10, 16).join(""),
].join("-");
};
Loading