From 536dfac6e4365db0828a860aef207d0223277492 Mon Sep 17 00:00:00 2001 From: estib Date: Tue, 24 Sep 2024 09:54:13 +0200 Subject: [PATCH 1/3] IntegrateUpstreamModal: Factor out the modal Factor out the modal for upstream integration into a dedicated component so that it can be shared easily --- .../src/lib/components/BaseBranch.svelte | 41 ++- .../components/IntegrateUpstreamModal.svelte | 252 ++++++++++++++++ .../lib/components/UpdateBaseButton.svelte | 268 +----------------- .../vbranches/upstreamIntegrationService.ts | 56 +++- 4 files changed, 333 insertions(+), 284 deletions(-) create mode 100644 apps/desktop/src/lib/components/IntegrateUpstreamModal.svelte diff --git a/apps/desktop/src/lib/components/BaseBranch.svelte b/apps/desktop/src/lib/components/BaseBranch.svelte index a19cfb1e06..cc5b4bdc9a 100644 --- a/apps/desktop/src/lib/components/BaseBranch.svelte +++ b/apps/desktop/src/lib/components/BaseBranch.svelte @@ -1,8 +1,8 @@
@@ -51,23 +68,17 @@
{#if base.upstreamCommits?.length > 0} - + diff --git a/apps/desktop/src/lib/components/IntegrateUpstreamModal.svelte b/apps/desktop/src/lib/components/IntegrateUpstreamModal.svelte new file mode 100644 index 0000000000..2f8c4619d5 --- /dev/null +++ b/apps/desktop/src/lib/components/IntegrateUpstreamModal.svelte @@ -0,0 +1,252 @@ + + + + + + + + {#snippet controls()} + + + {/snippet} + + + diff --git a/apps/desktop/src/lib/components/UpdateBaseButton.svelte b/apps/desktop/src/lib/components/UpdateBaseButton.svelte index 5160223506..6135b43def 100644 --- a/apps/desktop/src/lib/components/UpdateBaseButton.svelte +++ b/apps/desktop/src/lib/components/UpdateBaseButton.svelte @@ -1,129 +1,34 @@ - - - {#if $base} -
- {#each $base.upstreamCommits.slice(0, 2) as commit, index} - { - if (expanded) { - return $base.upstreamCommits.length - 1 === index; - } else { - if ($base.upstreamCommits.length > 2) { - return index === 1; - } else { - return $base.upstreamCommits.length - 1 === index; - } - } - })()} - isUnapplied={true} - commitUrl={$gitHost?.commitUrl(commit.id)} - type="remote" - filesToggleable={false} - /> - {/each} - {#if $base.upstreamCommits.length > 2} - {#if expanded} - {#each $base.upstreamCommits.slice(2) as commit, index} - - {/each} -
- -
- {:else} -
- -
- {/if} - {/if} -
- {/if} -
- {#each statuses as { branch, status }} -
-
-
{branch?.name || 'Unknown'}
- {#if status.type === 'conflicted'} -

Conflicted

- {:else if status.type === 'saflyUpdatable' || status.type === 'empty'} -

No Conflicts

- {:else if status.type === 'fullyIntegrated'} -

Integrated

- {/if} -
- -
- {#if status.type === 'fullyIntegrated'} -

Changes included in base branch

- {:else if results.get(branch.id)} - - {/if} -
-
- {/each} -
-
+ - {#snippet controls()} - - - {/snippet} -
- -{#if showButton && ($base?.upstreamCommits.length || 0) > 0} +{#if displayButton} {/if} - - diff --git a/apps/desktop/src/lib/vbranches/upstreamIntegrationService.ts b/apps/desktop/src/lib/vbranches/upstreamIntegrationService.ts index 3079797e2f..2f8ab47e4c 100644 --- a/apps/desktop/src/lib/vbranches/upstreamIntegrationService.ts +++ b/apps/desktop/src/lib/vbranches/upstreamIntegrationService.ts @@ -16,14 +16,7 @@ export type BranchStatus = }; }; -type BranchStatuses = - | { - type: 'upToDate'; - } - | { - type: 'updatesRequired'; - subject: [string, BranchStatus][]; - }; +export type BranchStatusInfo = { branch: VirtualBranch; status: BranchStatus }; export type BranchStatusesWithBranches = | { @@ -31,7 +24,7 @@ export type BranchStatusesWithBranches = } | { type: 'updatesRequired'; - subject: { branch: VirtualBranch; status: BranchStatus }[]; + subject: BranchStatusInfo[]; }; export type ResolutionApproach = { @@ -44,6 +37,42 @@ export type Resolution = { approach: ResolutionApproach; }; +export function getResolutionApproach(statusInfo: BranchStatusInfo): ResolutionApproach { + if (statusInfo.status.type === 'fullyIntegrated') { + return { type: 'delete' }; + } + + if (statusInfo.branch.allowRebasing) { + return { type: 'rebase' }; + } + + return { type: 'merge' }; +} + +export function sortStatusInfo(a: BranchStatusInfo, b: BranchStatusInfo): number { + if ( + (a.status.type !== 'fullyIntegrated' && b.status.type !== 'fullyIntegrated') || + (a.status.type === 'fullyIntegrated' && b.status.type === 'fullyIntegrated') + ) { + return (a.branch?.name || 'Unknown').localeCompare(b.branch?.name || 'Unknown'); + } + + if (a.status.type === 'fullyIntegrated') { + return 1; + } else { + return -1; + } +} + +type BranchStatusesResponse = + | { + type: 'upToDate'; + } + | { + type: 'updatesRequired'; + subject: [string, BranchStatus][]; + }; + export class UpstreamIntegrationService { constructor( private project: Project, @@ -51,10 +80,10 @@ export class UpstreamIntegrationService { ) {} upstreamStatuses(): Readable { - const branchStatuses = readable(undefined, (set) => { - invoke('upstream_integration_statuses', { projectId: this.project.id }).then( - set - ); + const branchStatuses = readable(undefined, (set) => { + invoke('upstream_integration_statuses', { + projectId: this.project.id + }).then(set); }); const branchStatusesWithBranches = derived( @@ -85,7 +114,6 @@ export class UpstreamIntegrationService { } async integrateUpstream(resolutions: Resolution[]) { - console.log(resolutions); return await invoke('integrate_upstream', { projectId: this.project.id, resolutions }); } } From 6ce77554fea59ca5220bf44a54987fc480abc213 Mon Sep 17 00:00:00 2001 From: estib Date: Tue, 24 Sep 2024 13:36:25 +0200 Subject: [PATCH 2/3] Modal: Expose the open or closed state Expose the state of whether the modal is open or not. [Some more info about this pattern.](https://github.com/sveltejs/svelte/issues/11974#issuecomment-2157837477) --- packages/ui/src/lib/Modal.svelte | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/ui/src/lib/Modal.svelte b/packages/ui/src/lib/Modal.svelte index 34b18e4360..6135a3acf4 100644 --- a/packages/ui/src/lib/Modal.svelte +++ b/packages/ui/src/lib/Modal.svelte @@ -42,6 +42,12 @@ onClose?.(); dialogElement?.close(); } + + export const imports = { + get open() { + return open; + } + }; Date: Tue, 24 Sep 2024 13:37:58 +0200 Subject: [PATCH 3/3] Use the exposed state of the integrate upstream modal Export the state of whether the modal is open or not. Use it in the base branch page and the update base button. --- apps/desktop/src/lib/components/BaseBranch.svelte | 15 +++------------ .../lib/components/IntegrateUpstreamModal.svelte | 6 ++++++ .../src/lib/components/UpdateBaseButton.svelte | 9 ++------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/apps/desktop/src/lib/components/BaseBranch.svelte b/apps/desktop/src/lib/components/BaseBranch.svelte index cc5b4bdc9a..56510a3eca 100644 --- a/apps/desktop/src/lib/components/BaseBranch.svelte +++ b/apps/desktop/src/lib/components/BaseBranch.svelte @@ -30,7 +30,6 @@ let updateTargetModal: Modal; let integrateUpstreamModal: IntegrateUpstreamModal | undefined; - let integrateUpstreamModalOpen = false; let mergeUpstreamWarningDismissedCheckbox = false; $: multiple = base ? base.upstreamCommits.length > 1 || base.upstreamCommits.length === 0 : false; @@ -42,13 +41,8 @@ } } - function closeIntegrateUpstreamModal() { - integrateUpstreamModalOpen = false; - } - function mergeUpstream() { if (project.succeedingRebases) { - integrateUpstreamModalOpen = true; integrateUpstreamModal?.show(); } else { if (mergeUpstreamWarningDismissedCheckbox) { @@ -68,16 +62,13 @@ {#if base.upstreamCommits?.length > 0} - +