Skip to content

Update modal component branch #4109

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jun 21, 2024
Merged

Conversation

Caleb-T-Owens
Copy link
Contributor

No description provided.

@Caleb-T-Owens Caleb-T-Owens force-pushed the update-modal-component-branch branch 3 times, most recently from 44e43b9 to b41b27d Compare June 18, 2024 16:26
@Caleb-T-Owens Caleb-T-Owens requested a review from ndom91 June 19, 2024 09:08
Comment on lines +6 to +10
class BranchDragActions {
constructor(
private branchController: BranchController,
private branch: Branch
) {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about whether I should have some

interface DropzoneActions {
  accepts: //...
  onDrop: //...
}

So we'd have one class for each dropzone actions. It would also mean that we could pass something that implements that interface directly to the Dropzone component, but I didn't quite want to go that far yet.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense. Definitely sounds like a good next step. However as you said, lets maybe save that for a more full-scale refactor of the whole drag-n-drop system 👍

Comment on lines +47 to +53
export class BranchDragActionsFactory {
constructor(private branchController: BranchController) {}

build(branch: Branch) {
return new BranchDragActions(this.branchController, branch);
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using a factory so that when we go to use the drag actions, we only need to provide the relevant state, rather than having to also provide a bunch of controllers and servicies

Comment on lines +34 to +43
<div class="canvas-dropzone">
<Dropzone {accepts} ondrop={onDrop}>
{#snippet overlay({ hovered, activated })}
<div class="new-virtual-branch" class:activated class:hovered>
<div class="new-virtual-branch__content">
<div class="stimg">
<div class="stimg__hand">
{@html handSvg}
</div>
<div class="stimg__top-sheet">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this is quite a specialised dropzone, I chose not to have some generic component for the overlay that it uses.

@@ -159,7 +159,7 @@
kind="solid"
on:click={async () => {
await branchController.deleteBranch(branch.id);
deleteBranchModal.close();
close();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😁 a cheeky unrelated change... if only we could work in multiple branches at the same time

Comment on lines +20 to +24
const actions = $derived.by(() => {
if (!$branch) return;

if (commit instanceof RemoteCommit) {
return () => false;
}
return (data: DraggableCommit) => {
if (data.commit.isParentOf(commit)) {
branchController.squashBranchCommit(data.branchId, commit.id);
} else if (commit.isParentOf(data.commit)) {
branchController.squashBranchCommit(data.branchId, data.commit.id);
}
};
}
return commitDragActionsFactory.build($branch, commit);
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was considering saying something like $derived($branch && commitDragActionsFactory.build($branch, commit)), but I decided that I really just want to keep everything as simple as possible, and being explicit and having that sort of guard clause to me just expressed the intent much better

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, makes it more readable too, etc. etc. Good call 👍

Comment on lines +29 to +33
{#if actions}
{@render ammendDropzone()}
{:else}
{@render children()}
{/if}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This component needs to gracefully fall back to not talking to the branchController because its used in the remoteBranch and trunk pages.

I thought about having the snippets inside the if block too, but it ended up looking too messy

Comment on lines +38 to +56
{#snippet ammendDropzone()}
<Dropzone accepts={actions!.acceptAmend.bind(actions)} ondrop={actions!.onAmend.bind(actions)}>
{@render squashDropzone()}

{#snippet overlay({ hovered, activated })}
<CardOverlay {hovered} {activated} label="Ammend commit" />
{/snippet}
</Dropzone>
{/snippet}

{#snippet squashDropzone()}
<Dropzone accepts={actions!.acceptSquash.bind(actions)} ondrop={actions!.onSquash.bind(actions)}>
{@render children()}

{#snippet overlay({ hovered, activated })}
<CardOverlay {hovered} {activated} label="Squash commit" />
{/snippet}
</Dropzone>
{/snippet}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anyone has n idea about how to better express the nesting, I am all ears

Comment on lines +111 to +132
function getReorderDropzoneOffset({
isFirst = false,
isMiddle = false,
isLast = false
}: {
isFirst?: boolean;
isMiddle?: boolean;
isLast?: boolean;
}) {
if (isFirst) return 12;
if (isMiddle) return 6;
if (isLast) return 0;
return 0;
}
</script>

{#snippet reorderDropzone(dropzone: ReorderDropzone, yOffsetPx: number)}
<Dropzone accepts={dropzone.accepts.bind(dropzone)} ondrop={dropzone.onDrop.bind(dropzone)}>
{#snippet overlay({ hovered, activated })}
<LineOverlay {hovered} {activated} {yOffsetPx} />
{/snippet}
</Dropzone>
{/snippet}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think an entire component was required for the Reordering dropzone. I'm willing to be swayed on this position though.

Comment on lines 45 to 47
this.registeredOnDrop = async (e: DragEvent) => await this.onDrop(e, data);
this.registeredOnDragEnter = this.onDragEnter.bind(this);
this.registeredOnDragLeave = this.onDragLeave.bind(this);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do make the assumption that the user can't drag two things at once, but that seems like a pretty sound assumption to me


export const dropzoneRegistry = new Map<HTMLElement, Dropzone>();

export function dropzone(node: HTMLElement, opts: DropzoneConfiguration) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now only consumed by the Dropzone, so its not relevant to support a partial configuration that contains defaults

}

// Private classes used to calculate distances between commtis
class Indexer {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to move the indexing and distance calculations into their own classes, because its now on longer required to be publicly exported (like it was when we used the old ReorderDropzone.svelte component)

@Caleb-T-Owens Caleb-T-Owens marked this pull request as ready for review June 19, 2024 10:03
@Caleb-T-Owens Caleb-T-Owens force-pushed the update-modal-component-branch branch 2 times, most recently from 4728b8e to 976e0a1 Compare June 19, 2024 10:41
Copy link
Contributor

@ndom91 ndom91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM functionality-wise!

I have a few small niggles design-wise, but you mentioned you still need to talk to Pavel so I'll just hold off 😊

@Caleb-T-Owens
Copy link
Contributor Author

Waiting on sveltejs/svelte-eslint-parser#540 in order for our linting to support nested snippets.

@Caleb-T-Owens Caleb-T-Owens force-pushed the update-modal-component-branch branch from f755df4 to 95e6b14 Compare June 21, 2024 07:51
@Caleb-T-Owens Caleb-T-Owens merged commit ffaffe6 into master Jun 21, 2024
16 checks passed
@Caleb-T-Owens Caleb-T-Owens deleted the update-modal-component-branch branch June 21, 2024 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants