Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 26 additions & 23 deletions apps/desktop/src/components/codegen/AttachmentList.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
}

function getTooltipText(attachment: PromptAttachment): string {
if (attachment.type === 'commit') {
return `${attachment.commitId}`;
} else if (attachment.type === 'file') {
const commitInfo = attachment.commitId ? ` (from commit ${attachment.commitId})` : '';
return `${attachment.path}${commitInfo}`;
} else if (attachment.type === 'lines') {
const commitInfo = attachment.commitId ? ` (from commit ${attachment.commitId})` : '';
return `Lines ${attachment.start}-${attachment.end}${attachment.path}${commitInfo}`;
if (`commit` in attachment) {
return `${attachment.commit.commitId}`;
} else if ('file' in attachment) {
const { commitId, path } = attachment.file;
const commitInfo = commitId ? ` (from commit ${commitId})` : '';
return `${path}${commitInfo}`;
} else if ('lines' in attachment) {
const { commitId, path, start, end } = attachment.lines;
const commitInfo = commitId ? ` (from commit ${commitId})` : '';
return `Lines ${start}-${end}${path}${commitInfo}`;
}
return '';
}
Expand All @@ -36,48 +38,49 @@
<Tooltip text={getTooltipText(attachment)}>
<div class="attachment-content text-12 text-semibold">
<!-- COMMIT -->
{#if attachment.type === 'commit'}
{#if 'commit' in attachment}
<Icon name="commit" color="var(--clr-text-2)" />
<span class="path">
#{attachment.commitId.slice(0, 6)}
#{attachment.commit.commitId.slice(0, 7)}
</span>
{/if}
<!-- FILE -->
{#if attachment.type === 'file'}
<FileIcon fileName={attachment.path} />
{#if `file` in attachment}
{@const { path, commitId } = attachment.file}
<FileIcon fileName={path} />

<span class="path">
{splitFilePath(attachment.path).filename}
{splitFilePath(path).filename}
</span>

{#if attachment.commitId}
{#if commitId}
<Icon name="commit" color="var(--clr-text-3)" />
<Tooltip text={attachment.commitId}>
<Tooltip text={commitId}>
<span class="commit-badge">
#{attachment.commitId.slice(0, 6)}
#{commitId.slice(0, 7)}
</span>
</Tooltip>
{/if}
{/if}
<!-- LINES -->
{#if attachment.type === 'lines'}
{@const { start, end } = attachment}
<FileIcon fileName={attachment.path} />
{#if `lines` in attachment}
{@const { commitId, path, start, end } = attachment.lines}
<FileIcon fileName={path} />

<span class="path">
{splitFilePath(attachment.path).filename}
{splitFilePath(path).filename}
</span>

<Icon name="text" color="var(--clr-text-3)" />
<span>
{start}:{end}
</span>

{#if attachment.commitId}
{#if commitId}
<Icon name="commit" color="var(--clr-text-3)" />
<Tooltip text={attachment.commitId}>
<Tooltip text={commitId}>
<span class="commit-badge">
#{attachment.commitId.slice(0, 6)}
#{commitId.slice(0, 7)}
</span>
</Tooltip>
{/if}
Expand Down
7 changes: 3 additions & 4 deletions apps/desktop/src/lib/codegen/attachmentService.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ export class AttachmentService {
}
}

export const promptAttachmentAdapter = createEntityAdapter<
{ branchName: string; attachments: PromptAttachment[] },
string
>({
export type PromptAttachmentRecord = { branchName: string; attachments: PromptAttachment[] };

export const promptAttachmentAdapter = createEntityAdapter<PromptAttachmentRecord, string>({
selectId: (a) => a.branchName
});

Expand Down
21 changes: 11 additions & 10 deletions apps/desktop/src/lib/codegen/dropzone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class CodegenCommitDropHandler implements DropzoneHandler {
}

ondrop(data: CommitDropData): void {
this.add([{ type: 'commit', branchName: this.branchName, commitId: data.commit.id }]);
this.add([{ commit: { commitId: data.commit.id } }]);
}
}

Expand All @@ -79,10 +79,11 @@ export class CodegenFileDropHandler implements DropzoneHandler {
const changes = await data.treeChanges();
const commitId = data.selectionId.type === 'commit' ? data.selectionId.commitId : undefined;
const attachments: PromptAttachment[] = changes.map((change) => ({
type: 'file',
branchName: this.branchName,
path: change.path,
commitId
file: {
path: change.path,
commitId
}
}));
this.add(attachments);
}
Expand All @@ -105,12 +106,12 @@ export class CodegenHunkDropHandler implements DropzoneHandler {
ondrop(data: HunkDropDataV3): void {
this.add([
{
type: 'lines',
branchName: this.branchName,
path: data.change.path,
start: data.hunk.newStart,
end: data.hunk.newStart + data.hunk.newLines - 1,
commitId: data.commitId
lines: {
path: data.change.path,
start: data.hunk.newStart,
end: data.hunk.newStart + data.hunk.newLines - 1,
commitId: data.commitId
}
}
]);
}
Expand Down
Loading
Loading