mirror of
https://github.com/usebruno/bruno.git
synced 2026-07-08 06:28:33 +00:00
* feat: move import collection from git url and spec url from enterprise edition to opensource
* fix: corrected a typo
* test: add unit and e2e tests for import collection migration
* fix: guard against missing userAgentData platform in getOSName — Default platform to '' to prevent TypeError when navigator.userAgentData is unavailable (GitNotFoundModal/index.js)
fix: UID mismatch between status tracking and UI rendering in bulk import — Preserve synthetic file-${index} UID on converted collections so initialStatus, rename tracking, and the render loop all use the same key (BulkImportCollectionLocation/index.js)
fix: isConfirmDisabled returning non-boolean value — Changed .length checks to explicit comparisons (> 0, === 0) so the function always returns true/false (CloneGitRespository/index.js)
fix: missing ipcRenderer declaration in cloneGitRepository and scanForBrunoFiles — Added const { ipcRenderer } = window; to both actions to prevent ReferenceError at runtime (collections/actions.js)
fix: use strict equality in filterItemsInCollection — Changed == to === for item.name and item.type comparisons (importers/common.js)
fix: variable shadowing in transformItemsInCollection and hydrateSeqInCollection — Renamed forEach callback parameter from collection to col to avoid shadowing the outer parameter (importers/common.js)
fix: scanForBrunoFiles traversing node_modules and .git directories — Added exclusion for node_modules and .git to match getCollectionStats pattern, preventing app freezes on large repos (filesystem.js)
fix: diff hunk header using string character count instead of line count — Preserved prefixedLines array to compute lineCount before joining, so the @@ header has the correct line count (git.js)
fix: test locators not scoped to modal in bulk import e2e test — Changed page.getByTestId to bulkImportModal.getByTestId for grouping dropdown interactions (002-all-collection-types.spec.ts)
fix: missing afterEach cleanup in GitHub repository import test — Added closeAllCollections hook to match sibling test specs, replaced unused dotenv/config import (github-repository-import.spec.ts)
* fix: batch name tracking and git utility fixes
- Fix usedNamesInBatch tracking original name instead of final name, which
could produce duplicate environment names within the same batch
(BulkImportCollectionLocation/index.js)
- Remove unused lodash import (git.js)
- Add missing early return in fetchRemotes when gitRootPath is falsy,
preventing getSimpleGitInstanceForPath from running with undefined (git.js)
* fix: correct variable naming and state management in CloneGitRepository component
- Renamed `collectionpaths` to `collectionPaths` for consistency and clarity.
- Updated references throughout the component to use the corrected variable name.
- Removed error toast notification to streamline error handling during repository cloning.
299 lines
8.7 KiB
JavaScript
299 lines
8.7 KiB
JavaScript
import { useState, useMemo } from 'react';
|
|
import toast from 'react-hot-toast';
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
import {
|
|
IconArrowsSort,
|
|
IconDotsVertical,
|
|
IconDownload,
|
|
IconFolder,
|
|
IconPlus,
|
|
IconSearch,
|
|
IconSortAscendingLetters,
|
|
IconSortDescendingLetters,
|
|
IconSquareX,
|
|
IconBox,
|
|
IconTerminal2
|
|
} from '@tabler/icons';
|
|
|
|
import { importCollection, openCollection, importCollectionFromZip } from 'providers/ReduxStore/slices/collections/actions';
|
|
import { sortCollections } from 'providers/ReduxStore/slices/collections/index';
|
|
import { normalizePath } from 'utils/common/path';
|
|
import { isScratchCollection } from 'utils/collections';
|
|
|
|
import MenuDropdown from 'ui/MenuDropdown';
|
|
import ActionIcon from 'ui/ActionIcon';
|
|
import ImportCollection from 'components/Sidebar/ImportCollection';
|
|
import ImportCollectionLocation from 'components/Sidebar/ImportCollectionLocation';
|
|
import BulkImportCollectionLocation from 'components/Sidebar/BulkImportCollectionLocation';
|
|
import CloneGitRepository from 'components/Sidebar/CloneGitRespository';
|
|
import RemoveCollectionsModal from 'components/Sidebar/Collections/RemoveCollectionsModal/index';
|
|
import CreateCollection from 'components/Sidebar/CreateCollection';
|
|
import Collections from 'components/Sidebar/Collections';
|
|
import SidebarSection from 'components/Sidebar/SidebarSection';
|
|
import { openDevtoolsAndSwitchToTerminal } from 'utils/terminal';
|
|
|
|
const CollectionsSection = () => {
|
|
const [showSearch, setShowSearch] = useState(false);
|
|
const dispatch = useDispatch();
|
|
|
|
const { workspaces, activeWorkspaceUid } = useSelector((state) => state.workspaces);
|
|
const activeWorkspace = workspaces.find((w) => w.uid === activeWorkspaceUid);
|
|
|
|
const { collections } = useSelector((state) => state.collections);
|
|
const { collectionSortOrder } = useSelector((state) => state.collections);
|
|
const [collectionsToClose, setCollectionsToClose] = useState([]);
|
|
|
|
const [importData, setImportData] = useState(null);
|
|
const [createCollectionModalOpen, setCreateCollectionModalOpen] = useState(false);
|
|
const [importCollectionModalOpen, setImportCollectionModalOpen] = useState(false);
|
|
const [importCollectionLocationModalOpen, setImportCollectionLocationModalOpen] = useState(false);
|
|
const [showCloneGitModal, setShowCloneGitModal] = useState(false);
|
|
const [gitRepositoryUrl, setGitRepositoryUrl] = useState(null);
|
|
|
|
const workspaceCollections = useMemo(() => {
|
|
if (!activeWorkspace) return [];
|
|
|
|
return collections.filter((c) => {
|
|
if (isScratchCollection(c, workspaces)) {
|
|
return false;
|
|
}
|
|
return activeWorkspace.collections?.some((wc) => normalizePath(wc.path) === normalizePath(c.pathname));
|
|
});
|
|
}, [activeWorkspace, collections, workspaces]);
|
|
|
|
const handleImportCollection = ({ rawData, type, repositoryUrl, ...rest }) => {
|
|
setImportCollectionModalOpen(false);
|
|
|
|
if (type === 'git-repository') {
|
|
setGitRepositoryUrl(repositoryUrl);
|
|
setShowCloneGitModal(true);
|
|
return;
|
|
}
|
|
|
|
setImportData({ rawData, type, ...rest });
|
|
setImportCollectionLocationModalOpen(true);
|
|
};
|
|
|
|
const handleImportCollectionLocation = (convertedCollection, collectionLocation, options = {}) => {
|
|
const importAction = options.isZipImport
|
|
? importCollectionFromZip(convertedCollection.zipFilePath, collectionLocation)
|
|
: importCollection(convertedCollection, collectionLocation, options);
|
|
|
|
dispatch(importAction)
|
|
.then(() => {
|
|
setImportCollectionLocationModalOpen(false);
|
|
setImportData(null);
|
|
});
|
|
};
|
|
|
|
const handleCloseGitModal = () => {
|
|
setShowCloneGitModal(false);
|
|
setGitRepositoryUrl(null);
|
|
};
|
|
|
|
const handleToggleSearch = () => {
|
|
setShowSearch((prev) => !prev);
|
|
};
|
|
|
|
const handleSortCollections = () => {
|
|
let order;
|
|
switch (collectionSortOrder) {
|
|
case 'default':
|
|
order = 'alphabetical';
|
|
break;
|
|
case 'alphabetical':
|
|
order = 'reverseAlphabetical';
|
|
break;
|
|
case 'reverseAlphabetical':
|
|
order = 'default';
|
|
break;
|
|
default:
|
|
order = 'default';
|
|
break;
|
|
}
|
|
dispatch(sortCollections({ order }));
|
|
};
|
|
|
|
const getSortIcon = () => {
|
|
switch (collectionSortOrder) {
|
|
case 'alphabetical':
|
|
return IconSortDescendingLetters;
|
|
case 'reverseAlphabetical':
|
|
return IconArrowsSort;
|
|
default:
|
|
return IconSortAscendingLetters;
|
|
}
|
|
};
|
|
|
|
const getSortLabel = () => {
|
|
switch (collectionSortOrder) {
|
|
case 'alphabetical':
|
|
return 'Sort Z-A';
|
|
case 'reverseAlphabetical':
|
|
return 'Clear sort';
|
|
default:
|
|
return 'Sort A-Z';
|
|
}
|
|
};
|
|
|
|
const selectAllCollectionsToClose = () => {
|
|
setCollectionsToClose(workspaceCollections.map((c) => c.uid));
|
|
};
|
|
|
|
const clearCollectionsToClose = () => {
|
|
setCollectionsToClose([]);
|
|
};
|
|
|
|
const handleOpenCollection = () => {
|
|
const options = {};
|
|
if (activeWorkspace?.pathname) {
|
|
options.workspaceId = activeWorkspace.pathname;
|
|
}
|
|
|
|
dispatch(openCollection(options)).catch((err) => {
|
|
toast.error('An error occurred while opening the collection');
|
|
});
|
|
};
|
|
|
|
const addDropdownItems = [
|
|
{
|
|
id: 'create',
|
|
leftSection: IconPlus,
|
|
label: 'Create collection',
|
|
onClick: () => {
|
|
setCreateCollectionModalOpen(true);
|
|
}
|
|
},
|
|
{
|
|
id: 'open',
|
|
leftSection: IconFolder,
|
|
label: 'Open collection',
|
|
onClick: () => {
|
|
handleOpenCollection();
|
|
}
|
|
},
|
|
{
|
|
id: 'import',
|
|
leftSection: IconDownload,
|
|
label: 'Import collection',
|
|
onClick: () => {
|
|
setImportCollectionModalOpen(true);
|
|
}
|
|
}
|
|
];
|
|
|
|
const actionsDropdownItems = [
|
|
{
|
|
id: 'sort',
|
|
leftSection: getSortIcon(),
|
|
label: getSortLabel(),
|
|
onClick: () => {
|
|
handleSortCollections();
|
|
}
|
|
},
|
|
{
|
|
id: 'close-all',
|
|
leftSection: IconSquareX,
|
|
label: 'Close all',
|
|
onClick: () => {
|
|
selectAllCollectionsToClose();
|
|
}
|
|
},
|
|
{
|
|
id: 'open-in-terminal',
|
|
leftSection: IconTerminal2,
|
|
label: 'Open in Terminal',
|
|
onClick: () => {
|
|
openDevtoolsAndSwitchToTerminal(dispatch, activeWorkspace?.pathname);
|
|
}
|
|
}
|
|
];
|
|
|
|
const sectionActions = (
|
|
<>
|
|
<ActionIcon
|
|
onClick={handleToggleSearch}
|
|
label="Search requests"
|
|
>
|
|
<IconSearch size={14} stroke={1.5} aria-hidden="true" />
|
|
</ActionIcon>
|
|
|
|
<MenuDropdown
|
|
data-testid="collections-header-add-menu"
|
|
items={addDropdownItems}
|
|
placement="bottom-end"
|
|
>
|
|
<ActionIcon
|
|
label="Add new collection"
|
|
>
|
|
<IconPlus size={14} stroke={1.5} aria-hidden="true" />
|
|
</ActionIcon>
|
|
</MenuDropdown>
|
|
|
|
<MenuDropdown
|
|
data-testid="collections-header-actions-menu"
|
|
items={actionsDropdownItems}
|
|
placement="bottom-end"
|
|
>
|
|
<ActionIcon
|
|
label="More actions"
|
|
>
|
|
<IconDotsVertical size={14} stroke={1.5} aria-hidden="true" />
|
|
</ActionIcon>
|
|
</MenuDropdown>
|
|
|
|
{collectionsToClose.length > 0 && (
|
|
<RemoveCollectionsModal collectionUids={collectionsToClose} onClose={clearCollectionsToClose} />
|
|
)}
|
|
</>
|
|
);
|
|
|
|
return (
|
|
<>
|
|
{createCollectionModalOpen && (
|
|
<CreateCollection
|
|
onClose={() => setCreateCollectionModalOpen(false)}
|
|
/>
|
|
)}
|
|
{importCollectionModalOpen && (
|
|
<ImportCollection
|
|
onClose={() => setImportCollectionModalOpen(false)}
|
|
handleSubmit={handleImportCollection}
|
|
/>
|
|
)}
|
|
{importCollectionLocationModalOpen && importData && (importData.type !== 'multiple' && importData.type !== 'bulk') && (
|
|
<ImportCollectionLocation
|
|
rawData={importData.rawData}
|
|
format={importData.type}
|
|
onClose={() => setImportCollectionLocationModalOpen(false)}
|
|
handleSubmit={handleImportCollectionLocation}
|
|
/>
|
|
)}
|
|
{importCollectionLocationModalOpen && importData && (importData.type === 'multiple' || importData.type === 'bulk') && (
|
|
<BulkImportCollectionLocation
|
|
importData={importData}
|
|
onClose={() => setImportCollectionLocationModalOpen(false)}
|
|
handleSubmit={handleImportCollectionLocation}
|
|
/>
|
|
)}
|
|
{showCloneGitModal && (
|
|
<CloneGitRepository
|
|
onClose={handleCloseGitModal}
|
|
onFinish={handleCloseGitModal}
|
|
collectionRepositoryUrl={gitRepositoryUrl}
|
|
/>
|
|
)}
|
|
<SidebarSection
|
|
id="collections"
|
|
title="Collections"
|
|
icon={IconBox}
|
|
actions={sectionActions}
|
|
>
|
|
<Collections showSearch={showSearch} />
|
|
</SidebarSection>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default CollectionsSection;
|