From 62a73fa3ec1afde8fcb4519c20c54164cb716959 Mon Sep 17 00:00:00 2001 From: James Gatz Date: Thu, 22 Feb 2024 13:12:35 +0100 Subject: [PATCH] add labels for branch names when resolving conflicts (#7105) --- packages/insomnia/src/sync/vcs/insomnia-sync.ts | 3 ++- packages/insomnia/src/sync/vcs/vcs.ts | 7 ++++--- .../src/ui/components/modals/sync-merge-modal.tsx | 13 ++++++++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/packages/insomnia/src/sync/vcs/insomnia-sync.ts b/packages/insomnia/src/sync/vcs/insomnia-sync.ts index e93311e3c..878151b0f 100644 --- a/packages/insomnia/src/sync/vcs/insomnia-sync.ts +++ b/packages/insomnia/src/sync/vcs/insomnia-sync.ts @@ -13,10 +13,11 @@ export const VCSInstance = () => { const driver = FileSystemDriver.create( process.env['INSOMNIA_DATA_PATH'] || window.app.getPath('userData'), ); - vcs = new VCS(driver, async conflicts => { + vcs = new VCS(driver, async (conflicts, labels) => { return new Promise(resolve => { showModal(SyncMergeModal, { conflicts, + labels, handleDone: (conflicts?: MergeConflict[]) => resolve(conflicts || []), }); diff --git a/packages/insomnia/src/sync/vcs/vcs.ts b/packages/insomnia/src/sync/vcs/vcs.ts index 985b6a558..879944a41 100644 --- a/packages/insomnia/src/sync/vcs/vcs.ts +++ b/packages/insomnia/src/sync/vcs/vcs.ts @@ -43,7 +43,7 @@ import { const EMPTY_HASH = crypto.createHash('sha1').digest('hex').replace(/./g, '0'); -type ConflictHandler = (conflicts: MergeConflict[]) => Promise; +type ConflictHandler = (conflicts: MergeConflict[], labels: { ours: string; theirs: string }) => Promise; // breaks one array into multiple arrays of size chunkSize export function chunkArray(arr: T[], chunkSize: number) { @@ -331,6 +331,7 @@ export class VCS { async handleAnyConflicts( conflicts: MergeConflict[], + labels: { ours: string; theirs: string }, errorMsg: string, ): Promise { if (conflicts.length === 0) { @@ -341,7 +342,7 @@ export class VCS { throw new Error(errorMsg); } - return this._conflictHandler(conflicts); + return this._conflictHandler(conflicts, labels); } async allDocuments(): Promise> { @@ -674,7 +675,7 @@ export class VCS { latestStateOther, ); // Update state with conflict resolutions applied - const conflictResolutions = await this.handleAnyConflicts(mergeConflicts, ''); + const conflictResolutions = await this.handleAnyConflicts(mergeConflicts, otherBranchName.includes('.hidden') ? { ours: `${trunkBranchName} local`, theirs: `${otherBranchName.replace('.hidden', '')} remote` } : { ours: trunkBranchName, theirs: otherBranchName }, ''); const state = updateStateWithConflictResolutions(stateBeforeConflicts, conflictResolutions); // Sometimes we want to merge into trunk but keep the other branch's history diff --git a/packages/insomnia/src/ui/components/modals/sync-merge-modal.tsx b/packages/insomnia/src/ui/components/modals/sync-merge-modal.tsx index 4870749e5..87e601450 100644 --- a/packages/insomnia/src/ui/components/modals/sync-merge-modal.tsx +++ b/packages/insomnia/src/ui/components/modals/sync-merge-modal.tsx @@ -7,6 +7,7 @@ import { Icon } from '../icon'; export interface SyncMergeModalOptions { conflicts?: MergeConflict[]; + labels: { ours: string; theirs: string }; handleDone?: (conflicts?: MergeConflict[]) => void; } export interface SyncMergeModalHandle { @@ -17,18 +18,21 @@ export const SyncMergeModal = forwardRef((_, ref) => { const [state, setState] = useState({ conflicts: [], isOpen: false, + labels: { ours: '', theirs: '' }, }); useImperativeHandle(ref, () => ({ hide: () => setState({ conflicts: [], isOpen: false, + labels: { ours: '', theirs: '' }, }), - show: ({ conflicts, handleDone }) => { + show: ({ conflicts, labels, handleDone }) => { setState({ conflicts, handleDone, isOpen: true, + labels, }); window.main.trackSegmentEvent({ @@ -46,6 +50,7 @@ export const SyncMergeModal = forwardRef((_, ref) => { !isOpen && setState({ conflicts: [], isOpen: false, + labels: { ours: '', theirs: '' }, }); }} isDismissable @@ -56,6 +61,7 @@ export const SyncMergeModal = forwardRef((_, ref) => { !isOpen && setState({ conflicts: [], isOpen: false, + labels: { ours: '', theirs: '' }, }); }} className="flex flex-col max-w-4xl w-full rounded-md border border-solid border-[--hl-sm] p-[--padding-lg] max-h-full bg-[--color-bg] text-[--color-font]" @@ -95,6 +101,7 @@ export const SyncMergeModal = forwardRef((_, ref) => { setState({ conflicts: [], isOpen: false, + labels: { ours: '', theirs: '' }, }); }} > @@ -162,7 +169,7 @@ export const SyncMergeModal = forwardRef((_, ref) => { > - Accept ours + Accept ours ({state.labels.ours}) ((_, ref) => { > - Accept theirs + Accept theirs ({state.labels.theirs})