Show the push button when there are differences after undoing commits and the branch requires force pushing

This commit is contained in:
Caleb Owens 2024-02-16 14:31:36 +00:00 committed by Kiril Videlov
parent f708c1568e
commit 5740c16ee8
3 changed files with 80 additions and 58 deletions

View File

@ -25,10 +25,13 @@
$: headCommit = branch.commits[0]; $: headCommit = branch.commits[0];
$: commits = type == 'upstream' ? [] : branch.commits.filter((c) => c.status == type); $: commits = type == 'upstream' ? [] : branch.commits.filter((c) => c.status == type);
$: hasCommits = commits && commits.length > 0;
$: remoteRequiresForcePush = type === 'remote' && branch.requiresForce;
let expanded = true; let expanded = true;
</script> </script>
{#if commits && commits.length > 0} {#if hasCommits || remoteRequiresForcePush }
<div <div
class="commit-list card" class="commit-list card"
class:upstream={type == 'upstream'} class:upstream={type == 'upstream'}

View File

@ -75,7 +75,9 @@
<PushButton <PushButton
wide wide
isLoading={isPushing || $githubServiceState$?.busy} isLoading={isPushing || $githubServiceState$?.busy}
isPushed={type == 'remote'} isPushed={type == 'remote' && !branch.requiresForce}
requiresForcePush={branch.requiresForce}
isPr={$pr$}
{projectId} {projectId}
githubEnabled={$githubEnabled$} githubEnabled={$githubEnabled$}
on:trigger={async (e) => { on:trigger={async (e) => {

View File

@ -7,6 +7,7 @@
</script> </script>
<script lang="ts"> <script lang="ts">
import Button from '$lib/components/Button.svelte';
import DropDownButton from '$lib/components/DropDownButton.svelte'; import DropDownButton from '$lib/components/DropDownButton.svelte';
import ContextMenu from '$lib/components/contextmenu/ContextMenu.svelte'; import ContextMenu from '$lib/components/contextmenu/ContextMenu.svelte';
import ContextMenuItem from '$lib/components/contextmenu/ContextMenuItem.svelte'; import ContextMenuItem from '$lib/components/contextmenu/ContextMenuItem.svelte';
@ -20,6 +21,8 @@
export let isLoading = false; export let isLoading = false;
export let githubEnabled: boolean; export let githubEnabled: boolean;
export let wide = false; export let wide = false;
export let requiresForcePush = false;
export let isPr = false;
function defaultAction(projectId: string): Persisted<BranchAction> { function defaultAction(projectId: string): Persisted<BranchAction> {
const key = 'projectDefaultAction_'; const key = 'projectDefaultAction_';
@ -49,61 +52,75 @@
} }
return preferredAction; return preferredAction;
} }
$: pushLabel = requiresForcePush ? 'Force push to remote' : 'Push to remote'
</script> </script>
<DropDownButton {#if isPr && requiresForcePush }
color="primary" <Button
kind="outlined" color="primary"
loading={isLoading} kind="outlined"
bind:this={dropDown} {wide}
{wide} disabled={isPushed}
{disabled} on:click={() => {
on:click={() => { dispatch('trigger', { action: BranchAction.Push });
dispatch('trigger', { action }); }}>{pushLabel}</Button
}} >
> {:else if !isPr }
{$selection$?.label} <DropDownButton
<ContextMenu color="primary"
type="select" kind="outlined"
slot="context-menu" loading={isLoading}
bind:this={contextMenu} bind:this={dropDown}
on:select={(e) => { {wide}
// TODO: Refactor to use generics if/when that works with Svelte {disabled}
switch (e.detail?.id) { on:click={() => {
case BranchAction.Push: dispatch('trigger', { action });
$preferredAction = BranchAction.Push; }}
break; >
case BranchAction.Pr: {$selection$?.label}
$preferredAction = BranchAction.Pr; <ContextMenu
break; type="select"
case BranchAction.DraftPr: slot="context-menu"
$preferredAction = BranchAction.DraftPr; bind:this={contextMenu}
break; on:select={(e) => {
default: // TODO: Refactor to use generics if/when that works with Svelte
toasts.error('Uknown branch action'); switch (e.detail?.id) {
} case BranchAction.Push:
dropDown.close(); $preferredAction = BranchAction.Push;
}} break;
> case BranchAction.Pr:
<ContextMenuSection> $preferredAction = BranchAction.Pr;
<ContextMenuItem break;
id="push" case BranchAction.DraftPr:
label="Push to remote" $preferredAction = BranchAction.DraftPr;
selected={action == BranchAction.Push} break;
disabled={isPushed} default:
/> toasts.error('Uknown branch action');
<ContextMenuItem }
id="pr" dropDown.close();
label="Create pull request" }}
disabled={!githubEnabled} >
selected={action == BranchAction.Pr} <ContextMenuSection>
/> <ContextMenuItem
<ContextMenuItem id="push"
id="draftPr" label={pushLabel}
label="Create draft pull request" selected={action == BranchAction.Push}
disabled={!githubEnabled} disabled={isPushed}
selected={action == BranchAction.DraftPr} />
/> <ContextMenuItem
</ContextMenuSection> id="pr"
</ContextMenu> label="Create pull request"
</DropDownButton> disabled={!githubEnabled}
selected={action == BranchAction.Pr}
/>
<ContextMenuItem
id="draftPr"
label="Create draft pull request"
disabled={!githubEnabled}
selected={action == BranchAction.DraftPr}
/>
</ContextMenuSection>
</ContextMenu>
</DropDownButton>
{/if}