mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-09 06:55:03 +00:00
Fix/example naming (#6002)
* fix: example naming * fix: request not being saved when initialized with empty url * remove check for method * fix: improve the logic for get initial name * fix test
This commit is contained in:
@@ -8,6 +8,7 @@ import { uuid } from 'utils/common';
|
||||
import toast from 'react-hot-toast';
|
||||
import CreateExampleModal from 'components/ResponseExample/CreateExampleModal';
|
||||
import { getBodyType } from 'utils/responseBodyProcessor';
|
||||
import { getInitialExampleName } from 'utils/collections/index';
|
||||
import classnames from 'classnames';
|
||||
import StyledWrapper from './StyledWrapper';
|
||||
|
||||
@@ -23,33 +24,6 @@ const ResponseBookmark = ({ item, collection, responseSize }) => {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Generate initial name for the example
|
||||
const getInitialExampleName = () => {
|
||||
const baseName = 'example';
|
||||
const existingExamples = item.draft?.examples || item.examples || [];
|
||||
|
||||
// Check if any existing example has the same base name
|
||||
const hasSameBaseName = existingExamples.some((example) => {
|
||||
const exampleName = example.name || '';
|
||||
return exampleName === baseName || exampleName.startsWith(baseName);
|
||||
});
|
||||
|
||||
if (!hasSameBaseName) {
|
||||
return baseName;
|
||||
}
|
||||
|
||||
// Find the highest existing counter
|
||||
let maxCounter = 0;
|
||||
existingExamples.forEach((example) => {
|
||||
const exampleName = example.name || '';
|
||||
if (exampleName.startsWith(baseName)) {
|
||||
maxCounter++;
|
||||
}
|
||||
});
|
||||
|
||||
return `${baseName} (${maxCounter})`;
|
||||
};
|
||||
|
||||
const handleSaveClick = () => {
|
||||
if (!response || response.error) {
|
||||
toast.error('No valid response to save as example');
|
||||
@@ -147,7 +121,7 @@ const ResponseBookmark = ({ item, collection, responseSize }) => {
|
||||
onClose={() => setShowSaveResponseExampleModal(false)}
|
||||
onSave={saveAsExample}
|
||||
title="Save Response as Example"
|
||||
initialName={getInitialExampleName()}
|
||||
initialName={getInitialExampleName(item)}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -33,7 +33,7 @@ import ExampleItem from './ExampleItem';
|
||||
import { scrollToTheActiveTab } from 'utils/tabs';
|
||||
import { isTabForItemActive as isTabForItemActiveSelector, isTabForItemPresent as isTabForItemPresentSelector } from 'src/selectors/tab';
|
||||
import { isEqual } from 'lodash';
|
||||
import { calculateDraggedItemNewPathname } from 'utils/collections/index';
|
||||
import { calculateDraggedItemNewPathname, getInitialExampleName } from 'utils/collections/index';
|
||||
import { sortByNameThenSequence } from 'utils/common/index';
|
||||
import CreateExampleModal from 'components/ResponseExample/CreateExampleModal';
|
||||
|
||||
@@ -346,19 +346,6 @@ const CollectionItem = ({ item, collectionUid, collectionPathname, searchText })
|
||||
setCreateExampleModalOpen(false);
|
||||
};
|
||||
|
||||
const getInitialExampleName = () => {
|
||||
const baseName = 'example';
|
||||
const existingExamples = item.draft?.examples || item.examples || [];
|
||||
let maxCounter = 0;
|
||||
existingExamples.forEach((example) => {
|
||||
const exampleName = example.name || '';
|
||||
if (exampleName.startsWith(baseName)) {
|
||||
maxCounter++;
|
||||
}
|
||||
});
|
||||
return `${baseName} (${maxCounter})`;
|
||||
};
|
||||
|
||||
const folderItems = sortByNameThenSequence(filter(item.items, (i) => isItemAFolder(i)));
|
||||
const requestItems = sortItemsBySequence(filter(item.items, (i) => isItemARequest(i)));
|
||||
|
||||
@@ -439,7 +426,7 @@ const CollectionItem = ({ item, collectionUid, collectionPathname, searchText })
|
||||
onClose={() => setCreateExampleModalOpen(false)}
|
||||
onSave={handleCreateExample}
|
||||
title="Create Response Example"
|
||||
initialName={getInitialExampleName()}
|
||||
initialName={getInitialExampleName(item)}
|
||||
/>
|
||||
<div
|
||||
className={itemRowClassName}
|
||||
|
||||
Reference in New Issue
Block a user