Skip to content
Merged
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
68 changes: 67 additions & 1 deletion src/background/bulk-state.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// bulk state-change handlers: close, open, delete, lock, pin, unpin.
// bulk state-change handlers: close, open, delete, lock, unlock, pin, unpin.

import { onMessage } from '@/lib/messages'
import { gql } from '@/lib/graphql-client'
import {
CLOSE_ISSUE,
REOPEN_ISSUE,
LOCK_ISSUE,
UNLOCK_ISSUE,
PIN_ISSUE,
UNPIN_ISSUE,
DELETE_PROJECT_ITEM,
Expand Down Expand Up @@ -323,6 +324,71 @@ export function registerBulkStateHandlers(): void {
}
})

onMessage('bulkUnlock', async ({ data, sender }) => {
logger.log('[rgp:bg] bulkUnlock received', { itemCount: data.itemIds.length })
if (isBulkFull()) {
console.warn('[rgp:bg] max concurrent bulk reached, rejecting bulkUnlock')
return
}
acquireBulk()
const processId = `unlock-${Date.now()}-${Math.random().toString(36).slice(2, 7)}`
const label = `Unlock · ${data.itemIds.length} item${data.itemIds.length !== 1 ? 's' : ''}`
const tabId = sender.tab?.id
try {
await broadcastQueue(
{
total: data.itemIds.length,
completed: 0,
paused: false,
status: 'Resolving items...',
processId,
label,
},
tabId,
)
const resolvedItems = await resolveProjectItemIds(data.itemIds, data.projectId, tabId)
if (resolvedItems.length === 0) {
console.error('[rgp:bg] no valid items resolved for bulkUnlock, aborting')
return
}
const tasks: QueueTask[] = resolvedItems.map(({ domId, issueNodeId }) => ({
id: `unlock-${domId}`,
run: async () => {
await gql(UNLOCK_ISSUE, { lockableId: issueNodeId })
await sleep(1000)
},
}))
await processQueue(
tasks,
async (state) => {
await broadcastQueue(
{
total: state.total,
completed: state.completed,
paused: state.paused,
retryAfter: state.retryAfter,
status:
state.completed < resolvedItems.length
? `Unlocking item ${state.completed + 1} of ${resolvedItems.length}…`
: `Unlocking ${resolvedItems.length} item${resolvedItems.length !== 1 ? 's' : ''}…`,
processId,
label,
failedItems: state.failedItems,
},
tabId,
)
},
processId,
)
await broadcastQueue(
{ total: 0, completed: 0, paused: false, status: 'Done!', processId, label },
tabId,
)
} finally {
releaseBulk()
}
})

onMessage('bulkPin', async ({ data, sender }) => {
logger.log('[rgp:bg] bulkPin received', { itemCount: data.itemIds.length })
if (isBulkFull()) {
Expand Down
2 changes: 1 addition & 1 deletion src/features/bulk-actions-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ export function BulkActionsBar({ projectId, owner, isOrg, number, getFields }: P
selectionStore.clear()
return
case 'unlock':
sendMessage('bulkLock', { itemIds, projectId: resolvedProjectId, lockReason: null })
sendMessage('bulkUnlock', { itemIds, projectId: resolvedProjectId })
return
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/lib/graphql-mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ export const LOCK_ISSUE = `
}
`

export const UNLOCK_ISSUE = `
mutation UnlockIssue($lockableId: ID!) {
unlockLockable(input: { lockableId: $lockableId }) {
unlockedRecord {
... on Issue { id locked }
}
}
}
`

export const PIN_ISSUE = `
mutation PinIssue($issueId: ID!) {
pinIssue(input: { issueId: $issueId }) {
Expand Down
1 change: 1 addition & 0 deletions src/lib/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ interface ProtocolMap {
projectId: string
lockReason: 'OFF_TOPIC' | 'TOO_HEATED' | 'RESOLVED' | 'SPAM' | null
}): void
bulkUnlock(data: { itemIds: string[]; projectId: string }): void
bulkPin(data: { itemIds: string[]; projectId: string }): void
bulkUnpin(data: { itemIds: string[]; projectId: string }): void
bulkDelete(data: { itemIds: string[]; projectId: string }): void
Expand Down
7 changes: 7 additions & 0 deletions src/lib/schemas-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,13 @@ export const Messages = {
}),
output: Schema.Void,
},
bulkUnlock: {
input: Schema.Struct({
itemIds: Schema.Array(Schema.String),
projectId: Schema.String,
}),
output: Schema.Void,
},
bulkPin: {
input: Schema.Struct({
itemIds: Schema.Array(Schema.String),
Expand Down
Loading