Skip to content

Commit 8d6f55e

Browse files
committed
Updates delete cloud patch for my drafts only
1 parent 10326b4 commit 8d6f55e

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12240,7 +12240,7 @@
1224012240
},
1224112241
{
1224212242
"command": "gitlens.views.drafts.delete",
12243-
"when": "viewItem =~ /gitlens:draft\\b/ && gitlens:plus",
12243+
"when": "viewItem =~ /gitlens:draft\\b(?=.*?\\b\\+mine\\b)/ && gitlens:plus",
1224412244
"group": "6_gitlens_actions@1"
1224512245
},
1224612246
{

src/gk/models/drafts.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export interface Draft {
2323
email: string | undefined;
2424
avatar?: string;
2525
};
26+
readonly isMine: boolean;
2627
readonly organizationId?: string;
2728
readonly role: 'owner' | 'admin' | 'editor' | 'viewer';
2829
readonly isPublished: boolean;

src/plus/drafts/draftsService.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export class DraftService implements Disposable {
179179
createdAt: new Date(draft.createdAt),
180180
updatedAt: new Date(draft.updatedAt ?? draft.createdAt),
181181
author: author,
182+
isMine: true,
182183
organizationId: draft.organizationId || undefined,
183184
role: draft.role,
184185
isPublished: draft.isPublished,
@@ -351,10 +352,12 @@ export class DraftService implements Disposable {
351352
email: undefined,
352353
};
353354

355+
let isMine = false;
354356
const { account } = await this.container.subscription.getSubscription();
355357
if (draft.createdBy === account?.id) {
356358
author.name = `${account.name} (you)`;
357359
author.email = account.email;
360+
isMine = true;
358361
}
359362

360363
return {
@@ -364,6 +367,7 @@ export class DraftService implements Disposable {
364367
createdAt: new Date(draft.createdAt),
365368
updatedAt: new Date(draft.updatedAt ?? draft.createdAt),
366369
author: author,
370+
isMine: isMine,
367371
organizationId: draft.organizationId || undefined,
368372
role: draft.role,
369373
isPublished: draft.isPublished,
@@ -388,15 +392,16 @@ export class DraftService implements Disposable {
388392
const draft = ((await rsp.json()) as Result).data;
389393
const { account } = await this.container.subscription.getSubscription();
390394

391-
return draft.map(
392-
(d): Draft => ({
395+
return draft.map((d): Draft => {
396+
const isMine = d.createdBy === account?.id;
397+
return {
393398
draftType: 'cloud',
394399
type: d.type,
395400
id: d.id,
396-
author:
397-
d.createdBy === account?.id
398-
? { id: d.createdBy, name: `${account.name} (you)`, email: account.email }
399-
: { id: d.createdBy, name: 'Unknown', email: undefined },
401+
author: isMine
402+
? { id: d.createdBy, name: `${account.name} (you)`, email: account.email }
403+
: { id: d.createdBy, name: 'Unknown', email: undefined },
404+
isMine: isMine,
400405
organizationId: d.organizationId || undefined,
401406
role: d.role,
402407
isPublished: d.isPublished,

src/views/draftsView.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,12 @@ export class DraftsViewNode extends CacheableChildrenViewNode<'drafts', DraftsVi
2727
const children: (GroupingNode | DraftNode)[] = [];
2828

2929
try {
30-
const { account } = await this.view.container.subscription.getSubscription(true);
31-
if (account == null) throw new AuthenticationRequiredError();
32-
3330
const drafts = await this.view.container.drafts.getDrafts();
3431
drafts.sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime());
3532

36-
const userId = account.id;
3733
const groups = groupByFilterMap(
3834
drafts,
39-
d => (d.author.id === userId ? 'mine' : 'shared'),
35+
d => (d.isMine ? 'mine' : 'shared'),
4036
d => new DraftNode(this.uri, this.view, this, d),
4137
);
4238

src/views/nodes/draftNode.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ export class DraftNode extends ViewNode<'draft', DraftsView> {
4040
const showUpdated = this.draft.updatedAt.getTime() - this.draft.createdAt.getTime() >= 1000;
4141

4242
item.id = this.id;
43-
item.contextValue = ContextValues.Draft;
43+
let contextValue = `${ContextValues.Draft}`;
44+
if (this.draft.isMine) {
45+
contextValue += '+mine';
46+
}
47+
item.contextValue = contextValue;
4448
item.iconPath = new ThemeIcon('cloud');
4549
item.tooltip = new MarkdownString(
4650
`${label}${this.draft.description ? `\\\n${this.draft.description}` : ''}\n\nCreated ${fromNow(

0 commit comments

Comments
 (0)