add labels for branch names when resolving conflicts (#7105)

This commit is contained in:
James Gatz 2024-02-22 13:12:35 +01:00 committed by GitHub
parent a7125a2314
commit 62a73fa3ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 7 deletions

View File

@ -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 || []),
});

View File

@ -43,7 +43,7 @@ import {
const EMPTY_HASH = crypto.createHash('sha1').digest('hex').replace(/./g, '0');
type ConflictHandler = (conflicts: MergeConflict[]) => Promise<MergeConflict[]>;
type ConflictHandler = (conflicts: MergeConflict[], labels: { ours: string; theirs: string }) => Promise<MergeConflict[]>;
// breaks one array into multiple arrays of size chunkSize
export function chunkArray<T>(arr: T[], chunkSize: number) {
@ -331,6 +331,7 @@ export class VCS {
async handleAnyConflicts(
conflicts: MergeConflict[],
labels: { ours: string; theirs: string },
errorMsg: string,
): Promise<MergeConflict[]> {
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<Record<string, any>> {
@ -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

View File

@ -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<SyncMergeModalHandle>((_, ref) => {
const [state, setState] = useState<SyncMergeModalOptions & { isOpen: boolean }>({
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<SyncMergeModalHandle>((_, ref) => {
!isOpen && setState({
conflicts: [],
isOpen: false,
labels: { ours: '', theirs: '' },
});
}}
isDismissable
@ -56,6 +61,7 @@ export const SyncMergeModal = forwardRef<SyncMergeModalHandle>((_, 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<SyncMergeModalHandle>((_, ref) => {
setState({
conflicts: [],
isOpen: false,
labels: { ours: '', theirs: '' },
});
}}
>
@ -162,7 +169,7 @@ export const SyncMergeModal = forwardRef<SyncMergeModalHandle>((_, ref) => {
>
<Icon icon="laptop" />
<span>
Accept ours
Accept ours ({state.labels.ours})
</span>
</Radio>
<Radio
@ -171,7 +178,7 @@ export const SyncMergeModal = forwardRef<SyncMergeModalHandle>((_, ref) => {
>
<Icon icon="globe" />
<span>
Accept theirs
Accept theirs ({state.labels.theirs})
</span>
</Radio>
</div>