Skip to content

Commit 75e336d

Browse files
committed
fix: Split into two actions to display lock state and to toggle lock/unlock
Signed-off-by: Julius Knorr <[email protected]>
1 parent 9fa9ae6 commit 75e336d

File tree

2 files changed

+69
-22
lines changed

2 files changed

+69
-22
lines changed

playwright/e2e/viewer.spec.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,31 @@ test('can manually lock a file', async ({ page, user }) => {
1717
const lockIndicator = page.getByRole('button', { name: 'Manually locked by ' + user.userId })
1818
await expect(lockIndicator).toBeVisible()
1919
await page.getByRole('button', { name: 'Actions' }).click()
20-
await page.getByRole('menuitem', { name: 'Manually locked by ' + user.userId }).click()
20+
const lockInfo = page.getByRole('menuitem', { name: 'Manually locked by ' + user.userId })
21+
await expect(lockInfo).toBeVisible()
22+
await page.getByRole('menuitem', { name: 'Unlock' }).click()
2123
await expect(lockIndicator).not.toBeVisible()
22-
})
24+
})
25+
26+
test('it shows the lock menu entry in grid view', async ({ page, user }) => {
27+
await page.getByRole('button', { name: 'Switch to grid view' }).click()
28+
await page.getByRole('button', { name: 'Actions' }).click()
29+
const lockButton = page.getByRole('menuitem', { name: 'Lock file' })
30+
await expect(lockButton).toBeVisible()
31+
await lockButton.click()
32+
await expect(lockButton).not.toBeVisible()
33+
34+
await page.getByRole('button', { name: 'Actions' }).click()
35+
36+
const lockIndicator = page.getByRole('menuitem', { name: 'Manually locked by ' + user.userId })
37+
await expect(lockIndicator).toBeVisible()
38+
39+
// Ensure that the inline lock indicator is not visible
40+
const inlineLockIndicator = page.locator('.files-list__row-action-lock_inline')
41+
await expect(inlineLockIndicator).not.toBeVisible()
42+
43+
const unlockButton = page.getByRole('menuitem', { name: 'Unlock' })
44+
await expect(unlockButton).toBeVisible()
45+
await unlockButton.click()
46+
await expect(unlockButton).not.toBeVisible()
47+
})

src/main.ts

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,28 @@ const switchLock = async (node: Node) => {
5858
}
5959
}
6060

61+
const getLockStateIcon = (node: Node) => {
62+
const state = getLockStateFromAttributes(node)
63+
64+
if (!state.isLocked) {
65+
return ''
66+
}
67+
68+
if (state.lockOwnerType === LockType.Token) {
69+
return LockMonitorSvg
70+
}
71+
72+
if (state.lockOwnerType === LockType.App) {
73+
return LockEditSvg
74+
}
75+
76+
if (state.lockOwner !== getCurrentUser()?.uid) {
77+
return LockAccountSvg
78+
}
79+
80+
return LockSvg
81+
}
82+
6183
const inlineAction = new FileAction({
6284
id: 'lock_inline',
6385
title: (nodes: Node[]) => nodes.length === 1 ? getInfoLabel(nodes[0]) : '',
@@ -68,44 +90,43 @@ const inlineAction = new FileAction({
6890

6991
iconSvgInline(nodes: Node[]) {
7092
const node = nodes[0]
93+
return getLockStateIcon(node)
94+
},
7195

72-
const state = getLockStateFromAttributes(node)
73-
74-
if (!state.isLocked) {
75-
return ''
76-
}
77-
78-
if (state.lockOwnerType === LockType.Token) {
79-
return LockMonitorSvg
80-
}
81-
82-
if (state.lockOwnerType === LockType.App) {
83-
return LockEditSvg
96+
enabled(nodes: Node[]) {
97+
// Only works on single node
98+
if (nodes.length !== 1) {
99+
return false
84100
}
85101

86-
if (state.lockOwner !== getCurrentUser()?.uid) {
87-
return LockAccountSvg
88-
}
102+
const node = nodes[0]
103+
const state = getLockStateFromAttributes(node)
89104

90-
return LockSvg
105+
return state.isLocked
91106
},
107+
})
92108

109+
const menuInfo = new FileAction({
110+
id: 'lock_info',
111+
order: 25,
112+
displayName: (nodes: Node[]) => getInfoLabel(nodes[0]),
113+
iconSvgInline: (nodes: Node[]) => {
114+
const node = nodes[0]
115+
return getLockStateIcon(node)
116+
},
93117
enabled(nodes: Node[]) {
94118
// Only works on single node
95119
if (nodes.length !== 1) {
96120
return false
97121
}
98-
99122
const node = nodes[0]
100123
const state = getLockStateFromAttributes(node)
101-
102124
return state.isLocked
103125
},
126+
async exec() {},
104127
})
105-
106128
const menuAction = new FileAction({
107129
id: 'lock',
108-
title: (nodes: Node[]) => getInfoLabel(nodes[0]),
109130
order: 25,
110131

111132
iconSvgInline(nodes: Node[]) {
@@ -166,4 +187,5 @@ const menuAction = new FileAction({
166187
})
167188

168189
registerFileAction(inlineAction)
190+
registerFileAction(menuInfo)
169191
registerFileAction(menuAction)

0 commit comments

Comments
 (0)