Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: generate uuid based on pathname #3213

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down Expand Up @@ -228,7 +229,7 @@ export const collectionsSlice = createSlice({
secret: false,
enabled: true,
type: 'text',
uid: uuid()
uid: generateUidBasedOnHash(`${collection?.pathname}/environments/${key}`)
});
}
}
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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',
Expand Down
5 changes: 5 additions & 0 deletions packages/bruno-app/src/utils/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,8 @@ export const humanizeDate = (dateString) => {
day: 'numeric'
});
};

export const generateUidBasedOnHash = (str) => {
const hash = simpleHash(str);
return `${hash}`.padEnd(21, '0');
};
4 changes: 2 additions & 2 deletions packages/bruno-electron/src/cache/requestUids.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down