diff --git a/packages/bruno-app/src/components/ResponsePane/ResponseBookmark/index.js b/packages/bruno-app/src/components/ResponsePane/ResponseBookmark/index.js index cf004f4d5..b00440c3a 100644 --- a/packages/bruno-app/src/components/ResponsePane/ResponseBookmark/index.js +++ b/packages/bruno-app/src/components/ResponsePane/ResponseBookmark/index.js @@ -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)} /> > ); diff --git a/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js b/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js index 8e7a90973..5d5075e23 100644 --- a/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js +++ b/packages/bruno-app/src/components/Sidebar/Collections/Collection/CollectionItem/index.js @@ -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)} />