Skip to content

Commit

Permalink
fix: use new uid algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
eirikhaugstulen committed Sep 27, 2023
1 parent a153053 commit 0360762
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import { useMemo } from 'react';
import { useDataQuery } from '@dhis2/app-runtime';
import uuid from 'd2-utilizr/lib/uuid';
import { generateUID } from '../../../utils/uid/generateUID';

export const useCommentDetails = () => {
const { data, error, loading } = useDataQuery(useMemo(() => ({
Expand All @@ -18,6 +18,6 @@ export const useCommentDetails = () => {
return {
error,
currentUser: !loading && data.currentUser,
noteId: uuid(),
noteId: generateUID(),
};
};
18 changes: 18 additions & 0 deletions src/core_modules/capture-core/utils/uid/generateUID.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @flow

export const generateUID = (): string => {
const letters = 'abcdefghijklmnopqrstuvwxyz' + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const allowedChars = `0123456789${letters}`;
const NUMBER_OF_CODEPOINTS = allowedChars.length;
const CODESIZE = 11;
let uid;

// the uid should start with a char
uid = letters.charAt(Math.random() * (letters.length));

for (let i = 1; i < CODESIZE; ++i) {
uid += allowedChars.charAt(Math.random() * (NUMBER_OF_CODEPOINTS));
}

return uid;
};

0 comments on commit 0360762

Please sign in to comment.