feat: generate uuid based on pathname

This commit is contained in:
lohxt1 2024-09-27 15:53:10 +05:30
parent 2e4051b022
commit 5e7e248282
4 changed files with 20 additions and 11 deletions

View File

@ -44,6 +44,7 @@ import { parsePathParams, parseQueryParams, splitOnFirst } from 'utils/url/index
import { sendCollectionOauth2Request as _sendCollectionOauth2Request } from 'utils/network/index';
import { name } from 'file-loader';
import slash from 'utils/common/slash';
import { generateUidBasedOnHash } from 'utils/common/index';
export const renameCollection = (newName, collectionUid) => (dispatch, getState) => {
const state = getState();
@ -460,7 +461,7 @@ export const cloneItem = (newName, itemUid, collectionUid) => (dispatch, getStat
dispatch(
insertTaskIntoQueue({
uid: uuid(),
uid: generateUidBasedOnHash(fullName),
type: 'OPEN_REQUEST',
collectionUid,
itemPathname: fullName
@ -489,7 +490,7 @@ export const cloneItem = (newName, itemUid, collectionUid) => (dispatch, getStat
dispatch(
insertTaskIntoQueue({
uid: uuid(),
uid: generateUidBasedOnHash(fullName),
type: 'OPEN_REQUEST',
collectionUid,
itemPathname: fullName
@ -767,7 +768,7 @@ export const newHttpRequest = (params) => (dispatch, getState) => {
// task middleware will track this and open the new request in a new tab once request is created
dispatch(
insertTaskIntoQueue({
uid: uuid(),
uid: generateUidBasedOnHash(fullName),
type: 'OPEN_REQUEST',
collectionUid,
itemPathname: fullName
@ -793,7 +794,7 @@ export const newHttpRequest = (params) => (dispatch, getState) => {
// task middleware will track this and open the new request in a new tab once request is created
dispatch(
insertTaskIntoQueue({
uid: uuid(),
uid: generateUidBasedOnHash(fullName),
type: 'OPEN_REQUEST',
collectionUid,
itemPathname: fullName

View File

@ -18,6 +18,7 @@ import {
import { parsePathParams, parseQueryParams, splitOnFirst, stringifyQueryParams } from 'utils/url';
import { getDirectoryName, getSubdirectoriesFromRoot, PATH_SEPARATOR } from 'utils/common/platform';
import toast from 'react-hot-toast';
import { generateUidBasedOnHash } from 'utils/common/index';
const initialState = {
collections: [],
@ -228,7 +229,7 @@ export const collectionsSlice = createSlice({
secret: false,
enabled: true,
type: 'text',
uid: uuid()
uid: generateUidBasedOnHash(`${collection?.pathname}/environments/${key}`)
});
}
}
@ -1443,9 +1444,10 @@ export const collectionsSlice = createSlice({
for (const directoryName of subDirectories) {
let childItem = currentSubItems.find((f) => f.type === 'folder' && f.name === directoryName);
if (!childItem) {
let pathname = `${currentPath}${PATH_SEPARATOR}${directoryName}`;
childItem = {
uid: uuid(),
pathname: `${currentPath}${PATH_SEPARATOR}${directoryName}`,
uid: generateUidBasedOnHash(pathname),
pathname,
name: directoryName,
collapsed: true,
type: 'folder',
@ -1498,9 +1500,10 @@ export const collectionsSlice = createSlice({
for (const directoryName of subDirectories) {
let childItem = currentSubItems.find((f) => f.type === 'folder' && f.name === directoryName);
if (!childItem) {
let pathname = `${currentPath}${PATH_SEPARATOR}${directoryName}`;
childItem = {
uid: uuid(),
pathname: `${currentPath}${PATH_SEPARATOR}${directoryName}`,
uid: generateUidBasedOnHash(pathname),
pathname,
name: directoryName,
collapsed: true,
type: 'folder',

View File

@ -158,3 +158,8 @@ export const humanizeDate = (dateString) => {
day: 'numeric'
});
};
export const generateUidBasedOnHash = (str) => {
const hash = simpleHash(str);
return `${hash}`.padEnd(21, '0');
};

View File

@ -11,13 +11,13 @@
*/
const requestUids = new Map();
const { uuid } = require('../utils/common');
const { generateUidBasedOnHash } = require('../utils/common');
const getRequestUid = (pathname) => {
let uid = requestUids.get(pathname);
if (!uid) {
uid = uuid();
uid = generateUidBasedOnHash(pathname);
requestUids.set(pathname, uid);
}