Use crypto.randomUUID()
for random ID generation (#4323)
This commit is contained in:
parent
2f6601febf
commit
b667cfc452
18 changed files with 36 additions and 45 deletions
|
@ -26,7 +26,7 @@ export const AlertContext = createContext<AlertProps | undefined>(undefined);
|
|||
export const useAlerts = () => useContext(AlertContext)!;
|
||||
|
||||
export type AlertType = {
|
||||
id: number;
|
||||
id: string;
|
||||
message: string;
|
||||
variant: AlertVariant;
|
||||
description?: string;
|
||||
|
@ -36,7 +36,7 @@ export const AlertProvider = ({ children }: PropsWithChildren<unknown>) => {
|
|||
const { t } = useTranslation();
|
||||
const [alerts, setAlerts] = useState<AlertType[]>([]);
|
||||
|
||||
const hideAlert = (id: number) => {
|
||||
const hideAlert = (id: string) => {
|
||||
setAlerts((alerts) => alerts.filter((alert) => alert.id !== id));
|
||||
};
|
||||
|
||||
|
@ -47,7 +47,7 @@ export const AlertProvider = ({ children }: PropsWithChildren<unknown>) => {
|
|||
) => {
|
||||
setAlerts([
|
||||
{
|
||||
id: Math.random() * 100,
|
||||
id: crypto.randomUUID(),
|
||||
//@ts-ignore
|
||||
message: t(message),
|
||||
variant,
|
||||
|
|
|
@ -20,8 +20,7 @@ describe("Client authentication subtab", () => {
|
|||
const clientDetailsPage = new ClientDetailsPage();
|
||||
const policiesSubTab = new PoliciesTab();
|
||||
const permissionsSubTab = new PermissionsTab();
|
||||
const clientId =
|
||||
"client-authentication-" + (Math.random() + 1).toString(36).substring(7);
|
||||
const clientId = "client-authentication-" + crypto.randomUUID();
|
||||
|
||||
before(() => {
|
||||
keycloakBefore();
|
||||
|
|
|
@ -299,7 +299,7 @@ describe("Client Scopes test", () => {
|
|||
});
|
||||
|
||||
it("Client scope CRUD test", () => {
|
||||
itemId += "_" + (Math.random() + 1).toString(36).substring(7);
|
||||
itemId += "_" + crypto.randomUUID();
|
||||
|
||||
// Create
|
||||
listingPage.itemExist(itemId, false).goToCreateItem();
|
||||
|
|
|
@ -316,7 +316,7 @@ describe("Clients test", () => {
|
|||
});
|
||||
|
||||
it("Client CRUD test", () => {
|
||||
itemId += "_" + (Math.random() + 1).toString(36).substring(7);
|
||||
itemId += "_" + crypto.randomUUID();
|
||||
|
||||
// Create
|
||||
commonPage.tableUtils().checkRowItemExists(itemId, false);
|
||||
|
@ -491,7 +491,7 @@ describe("Clients test", () => {
|
|||
loginPage.logIn();
|
||||
commonPage.sidebar().goToClients();
|
||||
|
||||
client = "client_" + (Math.random() + 1).toString(36).substring(7);
|
||||
client = "client_" + crypto.randomUUID();
|
||||
|
||||
commonPage.tableToolbarUtils().createClient();
|
||||
|
||||
|
@ -703,7 +703,7 @@ describe("Clients test", () => {
|
|||
|
||||
beforeEach(() => {
|
||||
commonPage.sidebar().goToClients();
|
||||
client = "client_" + (Math.random() + 1).toString(36).substring(7);
|
||||
client = "client_" + crypto.randomUUID();
|
||||
commonPage.tableToolbarUtils().createClient();
|
||||
createClientPage
|
||||
.selectClientType("openid-connect")
|
||||
|
|
|
@ -55,7 +55,7 @@ describe("Group test", () => {
|
|||
keycloakBefore();
|
||||
loginPage.logIn();
|
||||
sidebarPage.goToGroups();
|
||||
groupName = groupNamePrefix + (Math.random() + 1).toString(36).substring(7);
|
||||
groupName = groupNamePrefix + crypto.randomUUID();
|
||||
groupNames.push(groupName);
|
||||
});
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ describe("Realm roles test", () => {
|
|||
});
|
||||
|
||||
it("Realm role CRUD test", () => {
|
||||
itemId += "_" + (Math.random() + 1).toString(36).substring(7);
|
||||
itemId += "_" + crypto.randomUUID();
|
||||
|
||||
// Create
|
||||
listingPage.itemExist(itemId, false).goToCreateItem();
|
||||
|
@ -69,7 +69,7 @@ describe("Realm roles test", () => {
|
|||
});
|
||||
|
||||
it("should delete role from details action", () => {
|
||||
itemId += "_" + (Math.random() + 1).toString(36).substring(7);
|
||||
itemId += "_" + crypto.randomUUID();
|
||||
listingPage.goToCreateItem();
|
||||
createRealmRolePage.fillRealmRoleData(itemId).save();
|
||||
masthead.checkNotificationMessage("Role created", true);
|
||||
|
@ -89,7 +89,7 @@ describe("Realm roles test", () => {
|
|||
});
|
||||
|
||||
it("Add associated roles test", () => {
|
||||
itemId += "_" + (Math.random() + 1).toString(36).substring(7);
|
||||
itemId += "_" + crypto.randomUUID();
|
||||
|
||||
// Create
|
||||
listingPage.itemExist(itemId, false).goToCreateItem();
|
||||
|
@ -183,7 +183,7 @@ describe("Realm roles test", () => {
|
|||
|
||||
it("Should delete associated roles from list test", () => {
|
||||
itemId = "realm_role_crud";
|
||||
itemId += "_" + (Math.random() + 1).toString(36).substring(7);
|
||||
itemId += "_" + crypto.randomUUID();
|
||||
|
||||
// Create
|
||||
listingPage.itemExist(itemId, false).goToCreateItem();
|
||||
|
|
|
@ -12,7 +12,7 @@ const modalUtils = new ModalUtils();
|
|||
const masthead = new Masthead();
|
||||
|
||||
describe("Realm settings client policies tab tests", () => {
|
||||
const realmName = "Realm_" + (Math.random() + 1).toString(36).substring(7);
|
||||
const realmName = "Realm_" + crypto.randomUUID();
|
||||
const realmSettingsPage = new RealmSettingsPage(realmName);
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -14,7 +14,7 @@ const masthead = new Masthead();
|
|||
describe("Realm settings client profiles tab tests", () => {
|
||||
const profileName = "Test";
|
||||
const editedProfileName = "Edit";
|
||||
const realmName = "Realm_" + (Math.random() + 1).toString(36).substring(7);
|
||||
const realmName = "Realm_" + crypto.randomUUID();
|
||||
const realmSettingsPage = new RealmSettingsPage(realmName);
|
||||
|
||||
beforeEach(() => {
|
||||
|
|
|
@ -14,7 +14,7 @@ const modalUtils = new ModalUtils();
|
|||
const realmSettingsPage = new RealmSettingsPage();
|
||||
|
||||
describe("Realm settings events tab tests", () => {
|
||||
const realmName = "Realm_" + (Math.random() + 1).toString(36).substring(7);
|
||||
const realmName = "Realm_" + crypto.randomUUID();
|
||||
const listingPage = new ListingPage();
|
||||
|
||||
beforeEach(() => {
|
||||
|
@ -88,8 +88,8 @@ describe("Realm settings events tab tests", () => {
|
|||
|
||||
const addBundle = () => {
|
||||
realmSettingsPage.addKeyValuePair(
|
||||
"key_" + (Math.random() + 1).toString(36).substring(7),
|
||||
"value_" + (Math.random() + 1).toString(36).substring(7)
|
||||
"key_" + crypto.randomUUID(),
|
||||
"value_" + crypto.randomUUID()
|
||||
);
|
||||
|
||||
return this;
|
||||
|
|
|
@ -11,7 +11,7 @@ const masthead = new Masthead();
|
|||
const realmSettingsPage = new RealmSettingsPage();
|
||||
|
||||
describe("Realm settings general tab tests", () => {
|
||||
const realmName = "Realm_" + (Math.random() + 1).toString(36).substring(7);
|
||||
const realmName = "Realm_" + crypto.randomUUID();
|
||||
|
||||
beforeEach(() => {
|
||||
keycloakBefore();
|
||||
|
|
|
@ -11,7 +11,7 @@ const masthead = new Masthead();
|
|||
const realmSettingsPage = new RealmSettingsPage();
|
||||
|
||||
describe("Realm settings tabs tests", () => {
|
||||
const realmName = "Realm_" + (Math.random() + 1).toString(36).substring(7);
|
||||
const realmName = "Realm_" + crypto.randomUUID();
|
||||
|
||||
beforeEach(() => {
|
||||
keycloakBefore();
|
||||
|
|
|
@ -23,7 +23,7 @@ const clickCreateAttributeButton = () =>
|
|||
userProfileTab.createAttributeButtonClick();
|
||||
|
||||
describe("User profile tabs", () => {
|
||||
const realmName = "Realm_" + (Math.random() + 1).toString(36).substring(7);
|
||||
const realmName = "Realm_" + crypto.randomUUID();
|
||||
const attributeName = "Test";
|
||||
|
||||
before(() => {
|
||||
|
|
|
@ -14,12 +14,9 @@ const createRealmPage = new CreateRealmPage();
|
|||
const realmSettings = new RealmSettings();
|
||||
const modalUtils = new ModalUtils();
|
||||
|
||||
const testRealmName =
|
||||
"Test-realm-" + (Math.random() + 1).toString(36).substring(7);
|
||||
const newRealmName =
|
||||
"New-Test-realm-" + (Math.random() + 1).toString(36).substring(7);
|
||||
const editedRealmName =
|
||||
"Edited-Test-realm-" + (Math.random() + 1).toString(36).substring(7);
|
||||
const testRealmName = "Test-realm-" + crypto.randomUUID();
|
||||
const newRealmName = "New-Test-realm-" + crypto.randomUUID();
|
||||
const editedRealmName = "Edited-Test-realm-" + crypto.randomUUID();
|
||||
const testDisabledName = "Test-Disabled";
|
||||
|
||||
describe("Realm tests", () => {
|
||||
|
|
|
@ -37,7 +37,7 @@ describe("User creation", () => {
|
|||
|
||||
before(() => {
|
||||
for (let i = 0; i <= 2; i++) {
|
||||
groupName += "_" + (Math.random() + 1).toString(36).substring(7);
|
||||
groupName += "_" + crypto.randomUUID();
|
||||
adminClient.createGroup(groupName);
|
||||
groupsList = [...groupsList, groupName];
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ describe("User creation", () => {
|
|||
});
|
||||
|
||||
it("Create user test", () => {
|
||||
itemId += "_" + (Math.random() + 1).toString(36).substring(7);
|
||||
itemId += "_" + crypto.randomUUID();
|
||||
// Create
|
||||
createUserPage.goToCreateUser();
|
||||
|
||||
|
@ -75,7 +75,7 @@ describe("User creation", () => {
|
|||
});
|
||||
|
||||
it("Create user with groups test", () => {
|
||||
itemIdWithGroups += (Math.random() + 1).toString(36).substring(7);
|
||||
itemIdWithGroups += crypto.randomUUID();
|
||||
// Add user from search bar
|
||||
createUserPage.goToCreateUser();
|
||||
|
||||
|
@ -97,7 +97,7 @@ describe("User creation", () => {
|
|||
});
|
||||
|
||||
it("Create user with credentials test", () => {
|
||||
itemIdWithCred += "_" + (Math.random() + 1).toString(36).substring(7);
|
||||
itemIdWithCred += "_" + crypto.randomUUID();
|
||||
|
||||
// Add user from search bar
|
||||
createUserPage.goToCreateUser();
|
||||
|
|
|
@ -19,10 +19,7 @@ export default class UserDetailsPage extends PageObject {
|
|||
this.cancelBtn = "cancel-create-user";
|
||||
this.emailInput = "email-input";
|
||||
this.emailValue = () =>
|
||||
"example" +
|
||||
"_" +
|
||||
(Math.random() + 1).toString(36).substring(7) +
|
||||
"@example.com";
|
||||
"example" + "_" + crypto.randomUUID() + "@example.com";
|
||||
this.firstNameInput = "firstName-input";
|
||||
this.firstNameValue = "firstname";
|
||||
this.lastNameInput = "lastName-input";
|
||||
|
|
|
@ -8,7 +8,7 @@ import type { AlertEntry } from "./Alerts";
|
|||
|
||||
type AlertPanelProps = {
|
||||
alerts: AlertEntry[];
|
||||
onCloseAlert: (id: number) => void;
|
||||
onCloseAlert: (id: string) => void;
|
||||
};
|
||||
|
||||
export function AlertPanel({ alerts, onCloseAlert }: AlertPanelProps) {
|
||||
|
|
|
@ -31,7 +31,7 @@ export const AlertContext = createNamedContext<AlertProps | undefined>(
|
|||
export const useAlerts = () => useRequiredContext(AlertContext);
|
||||
|
||||
export type AlertEntry = {
|
||||
id: number;
|
||||
id: string;
|
||||
message: string;
|
||||
variant: AlertVariant;
|
||||
description?: string;
|
||||
|
@ -42,13 +42,13 @@ export const AlertProvider = ({ children }: PropsWithChildren<unknown>) => {
|
|||
const setTimeout = useSetTimeout();
|
||||
const [alerts, setAlerts] = useState<AlertEntry[]>([]);
|
||||
|
||||
const removeAlert = (id: number) =>
|
||||
const removeAlert = (id: string) =>
|
||||
setAlerts((alerts) => alerts.filter((alert) => alert.id !== id));
|
||||
|
||||
const addAlert = useCallback<AddAlertFunction>(
|
||||
(message, variant = AlertVariant.success, description) => {
|
||||
const alert: AlertEntry = {
|
||||
id: Math.random(),
|
||||
id: crypto.randomUUID(),
|
||||
message,
|
||||
variant,
|
||||
description,
|
||||
|
|
|
@ -18,11 +18,9 @@ import type { ComponentProps } from "./components";
|
|||
import { convertToName } from "./DynamicComponents";
|
||||
|
||||
type IdKeyValueType = KeyValueType & {
|
||||
id: number;
|
||||
id: string;
|
||||
};
|
||||
|
||||
const generateId = () => Math.floor(Math.random() * 100);
|
||||
|
||||
export const MapComponent = ({ name, label, helpText }: ComponentProps) => {
|
||||
const { t } = useTranslation("dynamic");
|
||||
|
||||
|
@ -36,7 +34,7 @@ export const MapComponent = ({ name, label, helpText }: ComponentProps) => {
|
|||
if (!values.length) {
|
||||
values.push({ key: "", value: "" });
|
||||
}
|
||||
setMap(values.map((value) => ({ ...value, id: generateId() })));
|
||||
setMap(values.map((value) => ({ ...value, id: crypto.randomUUID() })));
|
||||
}, [register, getValues]);
|
||||
|
||||
const update = (val = map) => {
|
||||
|
@ -130,7 +128,7 @@ export const MapComponent = ({ name, label, helpText }: ComponentProps) => {
|
|||
variant="link"
|
||||
icon={<PlusCircleIcon />}
|
||||
onClick={() =>
|
||||
setMap([...map, { key: "", value: "", id: generateId() }])
|
||||
setMap([...map, { key: "", value: "", id: crypto.randomUUID() }])
|
||||
}
|
||||
>
|
||||
{t("common:addAttribute")}
|
||||
|
|
Loading…
Reference in a new issue