From 83ddfc33d268434966fa1c28ad00bfb338dff474 Mon Sep 17 00:00:00 2001 From: Abhishek S Lal Date: Sat, 14 Mar 2026 01:15:10 +0530 Subject: [PATCH] refactor(OpenAPISyncTab): streamline component logic and enhance user feedback (#7483) - Removed unused props and improved error handling in OpenAPISyncTab components. - Updated messaging in CollectionStatusSection and OverviewSection for clarity. - Enhanced the SpecDiffModal to provide better visual feedback on changes. - Refactored sync flow logic to ensure accurate endpoint categorization and improved performance. - Added new utility functions for better handling of spec changes and endpoint comparisons. --- .../CollectionStatusSection/index.js | 4 +- .../OpenAPISyncTab/OverviewSection/index.js | 28 +- .../OpenAPISyncTab/SpecDiffModal/index.js | 2 +- .../OpenAPISyncTab/SpecStatusSection/index.js | 30 +- .../OpenAPISyncTab/SyncReviewPage/index.js | 22 +- .../OpenAPISyncTab/hooks/useOpenAPISync.js | 28 +- .../OpenAPISyncTab/hooks/useSyncFlow.js | 37 +- .../src/components/OpenAPISyncTab/index.js | 1 - .../bruno-electron/src/ipc/openapi-sync.js | 411 ++++++++---------- 9 files changed, 275 insertions(+), 288 deletions(-) diff --git a/packages/bruno-app/src/components/OpenAPISyncTab/CollectionStatusSection/index.js b/packages/bruno-app/src/components/OpenAPISyncTab/CollectionStatusSection/index.js index 1b2ef9463..ae7fdf580 100644 --- a/packages/bruno-app/src/components/OpenAPISyncTab/CollectionStatusSection/index.js +++ b/packages/bruno-app/src/components/OpenAPISyncTab/CollectionStatusSection/index.js @@ -71,6 +71,8 @@ const CollectionStatusSection = ({ variant: 'muted', message: 'Collection has changes since last sync', badges: { modifiedCount, missingCount, localOnlyCount }, + version, + lastSyncDate, actions: ['revert-all'] }; } @@ -244,7 +246,7 @@ const CollectionStatusSection = ({

No changes in collection

-

The collection matches the last synced spec. Nothing to review.

+

The collection endpoints match the last synced spec. Nothing to review.

)} {/* Action confirmation modal */} diff --git a/packages/bruno-app/src/components/OpenAPISyncTab/OverviewSection/index.js b/packages/bruno-app/src/components/OpenAPISyncTab/OverviewSection/index.js index 630c14c88..6c7708ab6 100644 --- a/packages/bruno-app/src/components/OpenAPISyncTab/OverviewSection/index.js +++ b/packages/bruno-app/src/components/OpenAPISyncTab/OverviewSection/index.js @@ -6,7 +6,6 @@ import { countEndpoints } from '../utils'; import moment from 'moment'; import { IconCheck } from '@tabler/icons'; import Button from 'ui/Button'; -import StatusBadge from 'ui/StatusBadge'; import Help from 'components/Help'; const capitalize = (str) => str ? str.charAt(0).toUpperCase() + str.slice(1) : str; @@ -40,7 +39,7 @@ const SUMMARY_CARDS = [ } ]; -const OverviewSection = ({ collection, storedSpec, collectionDrift, specDrift, remoteDrift, onTabSelect, error, fileNotFound, onOpenSettings }) => { +const OverviewSection = ({ collection, storedSpec, collectionDrift, specDrift, remoteDrift, onTabSelect, error, onOpenSettings }) => { const openApiSyncConfig = collection?.brunoConfig?.openapi?.[0]; const reduxError = useSelector((state) => state.openapiSync?.collectionUpdates?.[collection.uid]?.error); @@ -48,6 +47,8 @@ const OverviewSection = ({ collection, storedSpec, collectionDrift, specDrift, r const activeError = error || reduxError; const version = storedSpec?.info?.version ?? specMeta?.version; + const newVersion = specDrift?.newVersion; + const hasVersionChange = version && newVersion && version !== newVersion; const endpointCount = countEndpoints(storedSpec) ?? specMeta?.endpointCount ?? null; const lastSyncDate = openApiSyncConfig?.lastSyncDate; const groupBy = openApiSyncConfig?.groupBy || 'tags'; @@ -89,7 +90,7 @@ const OverviewSection = ({ collection, storedSpec, collectionDrift, specDrift, r }; const details = [ - { label: 'Spec Version', value: version ? `v${version}` : '–' }, + { label: 'Spec Version', value: hasVersionChange ? `v${version} → v${newVersion}` : version ? `v${version}` : '–' }, { label: 'Endpoints in Spec', value: endpointCount != null ? endpointCount : '–' }, { label: 'Last Synced At', value: lastSyncDate ? moment(lastSyncDate).fromNow() : '–', tooltip: lastSyncDate ? moment(lastSyncDate).format('MMMM D, YYYY [at] h:mm A') : undefined }, { label: 'Folder Grouping', value: capitalize(groupBy) }, @@ -100,6 +101,10 @@ const OverviewSection = ({ collection, storedSpec, collectionDrift, specDrift, r const hasSpecUpdates = specUpdatesPending > 0; const bannerState = useMemo(() => { + const versionInfo = (specDrift?.storedVersion && specDrift?.newVersion && specDrift.storedVersion !== specDrift.newVersion) + ? ` (v${specDrift.storedVersion} → v${specDrift.newVersion})` + : ''; + if (activeError) { return { variant: 'danger', @@ -128,7 +133,7 @@ const OverviewSection = ({ collection, storedSpec, collectionDrift, specDrift, r if (hasSpecUpdates && hasCollectionChanges) { return { variant: 'warning', - title: 'The API spec has new updates and the collection has changes', + title: `The API spec has new updates${versionInfo} and the collection has changes`, subtitle: 'New or changed requests are available. Some collection changes may be overwritten.', buttons: ['sync', 'changes'] }; @@ -136,7 +141,7 @@ const OverviewSection = ({ collection, storedSpec, collectionDrift, specDrift, r if (hasSpecUpdates) { return { variant: 'warning', - title: 'The API spec has new updates', + title: `The API spec has new updates${versionInfo}`, subtitle: 'New or changed requests are available.', buttons: ['sync'] }; @@ -156,7 +161,7 @@ const OverviewSection = ({ collection, storedSpec, collectionDrift, specDrift, r // buttons: [] // }; return null; - }, [activeError, fileNotFound, hasDriftData, hasSpecUpdates, hasCollectionChanges, specDrift?.storedSpecMissing, lastSyncDate]); + }, [activeError, hasDriftData, hasSpecUpdates, hasCollectionChanges, specDrift?.storedSpecMissing, specDrift?.storedVersion, specDrift?.newVersion, lastSyncDate]); return (
@@ -168,12 +173,6 @@ const OverviewSection = ({ collection, storedSpec, collectionDrift, specDrift, r ? :
} {bannerState.title} - {bannerState.showBadge && ( - {specUpdatesPending} {specUpdatesPending === 1 ? 'spec update' : 'spec updates'} - )} - {bannerState.showChangesBadge && ( - {changedInCollection} {changedInCollection === 1 ? 'collection change' : 'collection changes'} - )}
{bannerState.subtitle && (

{bannerState.subtitle}

@@ -201,6 +200,11 @@ const OverviewSection = ({ collection, storedSpec, collectionDrift, specDrift, r Restore Spec File )} + {bannerState.buttons.includes('spec-details') && ( + + )} {bannerState.buttons.includes('open-settings') && (