Skip to content

Commit f50e2d8

Browse files
committed
fix: Lock stuff when you can’t manage the instance
1 parent 876ccb8 commit f50e2d8

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

src/features/instance/applications/components/ApplicationsSidebar/index.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,17 @@ export function ApplicationsSidebar() {
3939
}, [openedEntry, focusedItem, items]);
4040

4141
// TODO: consistently drive file and folder selection through context (particularly during creation and deletion)
42-
// TODO: Split all this logic up into smaller files, right?
4342
// TODO: onRenameItem f2 handling
4443
// TODO: on drag item from one folder to another
44+
// TODO: Split all this logic up into smaller files, right?
4545

46-
// TODO: stick packages under a different top level node
46+
// TODO: keyboard shortcuts when the editor isn't focused (creating files and folders, deleting, can we
47+
// copy-cut-paste selections?)
48+
// TODO: keyboard shortcut for deleting a file?
49+
// TODO: stick packages under a different top level node // package-locked-icon fas fa-lock ml-2
4750
// TODO: icon showing package is read-only
51+
// TODO: new application
52+
// TODO: import application
4853

4954
// TODO: context menu when right click on tree
5055
// TODO: on drop file or folder from outside the editor to upload stuff rapidly

src/features/instance/applications/components/TextEditorView/index.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { DeleteDirectoryOrFileModal } from '@/features/instance/applications/mod
99
import { RedeployApplicationModal } from '@/features/instance/applications/modals/RedeployApplicationModal';
1010
import { useDeployComponentMutation } from '@/features/instance/operations/mutations/deployComponent';
1111
import { useEffectedState } from '@/hooks/useEffectedState';
12+
import { useInstanceBrowseManagePermission } from '@/hooks/usePermissions';
1213
import { useToggler } from '@/hooks/useToggler';
1314
import { parseFileExtension } from '@/lib/string/parseFileExtension';
1415
import { Editor, EditorProps, OnMount } from '@monaco-editor/react';
@@ -46,6 +47,7 @@ export function TextEditorView() {
4647
[openedEntryContents],
4748
);
4849
const targetNoun = instanceId || isLocalStudio ? 'Instance' : 'Cluster';
50+
const canManageBrowseInstance = useInstanceBrowseManagePermission();
4951

5052
const mountedRef = useRef<Parameters<OnMount> | null>(null);
5153

@@ -148,7 +150,7 @@ export function TextEditorView() {
148150
}, [openedEntry?.package]);
149151

150152
useEffect(() => {
151-
if (!mountedRef.current) {
153+
if (!mountedRef.current || !canManageBrowseInstance) {
152154
return;
153155
}
154156
const [editor, monaco] = mountedRef.current;
@@ -187,7 +189,7 @@ export function TextEditorView() {
187189
disposable?.dispose();
188190
}
189191
};
190-
}, [mountedRef, onSaveClick, onRevertChangesClicked]);
192+
}, [mountedRef, canManageBrowseInstance, onAddFileClicked, onAddDirectoryClicked, onSaveClick, onRevertChangesClicked, onDeleteClick]);
191193

192194
if (!openedEntry) {
193195
return null;
@@ -207,7 +209,7 @@ export function TextEditorView() {
207209
options={{
208210
automaticLayout: true,
209211
minimap: { enabled: false },
210-
readOnly: !!openedEntry.package,
212+
readOnly: !!openedEntry.package || !canManageBrowseInstance,
211213
padding: { top: 50 },
212214
}}
213215
/>
@@ -221,7 +223,7 @@ export function TextEditorView() {
221223

222224
<div className="absolute top-0 right-0 left-0 backdrop-blur-sm bg-black-10 shadow-xl flex pr-12 -mr-1">
223225

224-
{!isDirectory(openedEntry) && !openedEntry.package && <Button
226+
{!isDirectory(openedEntry) && !openedEntry.package && canManageBrowseInstance && <Button
225227
variant="default"
226228
className="rounded-none"
227229
onClick={onSaveClick}
@@ -235,7 +237,7 @@ export function TextEditorView() {
235237
<span className="hidden lg:inline-block"><u>S</u>ave</span>
236238
</Button>}
237239

238-
{!openedEntry.package && <Button
240+
{!openedEntry.package && canManageBrowseInstance && <Button
239241
variant="ghost"
240242
className="rounded-none"
241243
// onClick={onRenameClick}
@@ -249,7 +251,7 @@ export function TextEditorView() {
249251
<span className="hidden lg:inline-block"><u>R</u>ename</span>
250252
</Button>}
251253

252-
{!openedEntry.package && <Button
254+
{!openedEntry.package && canManageBrowseInstance && <Button
253255
variant="ghost"
254256
className="rounded-none"
255257
onClick={onAddFileClicked}
@@ -258,7 +260,7 @@ export function TextEditorView() {
258260
<span className="hidden lg:inline-block"><u>N</u>ew File</span>
259261
</Button>}
260262

261-
{!openedEntry.package && <Button
263+
{!openedEntry.package && canManageBrowseInstance && <Button
262264
variant="ghost"
263265
className="rounded-none"
264266
onClick={onAddDirectoryClicked}
@@ -267,7 +269,7 @@ export function TextEditorView() {
267269
<span className="hidden lg:inline-block"><u>A</u>dd Directory</span>
268270
</Button>}
269271

270-
{!!openedEntry.package && !restrictPackageModification && <Button
272+
{!!openedEntry.package && canManageBrowseInstance && !restrictPackageModification && <Button
271273
variant="ghost"
272274
className="rounded-none"
273275
onClick={onRedeployClicked}
@@ -276,17 +278,17 @@ export function TextEditorView() {
276278
<span>Redeploy <u>P</u>ackage</span>
277279
</Button>}
278280

279-
<RestartButton
281+
{canManageBrowseInstance && <RestartButton
280282
targetNoun={targetNoun}
281283
instanceClient={instanceParams.instanceClient}
282284
operation="restart_service"
283285
variant="ghost"
284286
className="rounded-none"
285-
/>
287+
/>}
286288

287289
<div className="grow"></div>
288290

289-
{!restrictPackageModification && <Button
291+
{!restrictPackageModification && canManageBrowseInstance && <Button
290292
variant="destructiveGhost"
291293
className="rounded-none"
292294
onClick={onDeleteClick}
@@ -295,7 +297,7 @@ export function TextEditorView() {
295297
<span className="hidden xl:inline-block"><u>D</u>elete</span>
296298
</Button>}
297299

298-
{!isDirectory(openedEntry) && !openedEntry.package && <Button
300+
{!isDirectory(openedEntry) && !openedEntry.package && canManageBrowseInstance && <Button
299301
variant="ghost"
300302
className="rounded-none"
301303
onClick={onRevertChangesClicked}

src/features/instance/applications/components/oldStuff/PackageLockedIcon.tsx

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)