Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(gfs): streamline manage folder actions

Miguelon Peluchon49c62aadc33e
diff --git a/control-ui/app/globals.css b/control-ui/app/globals.css
index 084310ddb..58450684b 100644
--- a/control-ui/app/globals.css
+++ b/control-ui/app/globals.css
@@ -11924,7 +11924,7 @@ button.cu-gfs-tree__button:focus-visible,
}
.cu-gfs-manage-dialog__icon--folder {
- color: var(--cu-warning);
+ color: var(--cu-text-muted);
}
.cu-gfs-manage-dialog__icon svg {
@@ -12294,6 +12294,7 @@ button.cu-gfs-tree__button:focus-visible,
display: flex;
flex-wrap: wrap;
gap: var(--cu-space-2);
+ justify-content: flex-end;
}
.cu-gfs-existing-access {
diff --git a/control-ui/components/GfsBrowser.tsx b/control-ui/components/GfsBrowser.tsx
index 21f285151..2d3264958 100644
--- a/control-ui/components/GfsBrowser.tsx
+++ b/control-ui/components/GfsBrowser.tsx
@@ -24,6 +24,7 @@ import { normalizeGfsResourceName } from '@lib/gfsResourceName'
import { isGfsVideoFile } from '@lib/gfsVideoFile'
import { gfsVideoPreviewMimeType } from '@lib/gfsVideoPreview'
import { GfsGrantPanel } from './GfsGrantPanel'
+import type { GfsCreateShareActionChange } from './GfsGrantPanel.types'
import { GfsResourceMenu } from './GfsResourceMenu'
import { NewFolderModal } from './NewFolderModal'
import { TablePanelHeader } from './TablePanelHeader'
@@ -127,7 +128,15 @@ export function GfsBrowser(): React.JSX.Element {
const [renameOpen, setRenameOpen] = useState(false)
const [renameName, setRenameName] = useState('')
const [deleteOpen, setDeleteOpen] = useState(false)
- const manageUploadInputRef = useRef<HTMLInputElement | null>(null)
+ const createShareActionRef = useRef<(() => void) | null>(null)
+ const [createShareDisabled, setCreateShareDisabled] = useState(true)
+ const handleCreateShareActionChange = useCallback<GfsCreateShareActionChange>(
+ (action, disabled) => {
+ createShareActionRef.current = action
+ setCreateShareDisabled(disabled)
+ },
+ []
+ )
// New-folder dialog (replaces the native window.prompt flow).
const [newFolderOpen, setNewFolderOpen] = useState(false)
const [creatingFolder, setCreatingFolder] = useState(false)
@@ -494,32 +503,6 @@ export function GfsBrowser(): React.JSX.Element {
}
}
- async function uploadFileToFolder(
- folder: GfsChild,
- file: File | null | undefined
- ): Promise<void> {
- if (!file || folder.kind !== 'directory') return
- try {
- const name = await normalizeGfsResourceName(file.name)
- await apiSend(
- 'POST',
- `/api/v1/gfs/proxy/v1/resources/${encodeURIComponent(folder.rid)}/children`,
- {
- name,
- kind: 'file',
- contentBase64: await fileToEncodedData(file),
- },
- {},
- {},
- { timeoutMs: GFS_UPLOAD_TIMEOUT_MS }
- )
- showToast('File uploaded.', { tone: 'success' })
- await refreshCurrent()
- } catch (err) {
- showToast(err instanceof Error ? err.message : 'Could not upload file.', { tone: 'error' })
- }
- }
-
async function downloadFile(child: GfsChild): Promise<void> {
if (downloadingIds.has(child.resourceId)) return
setDownloadingIds(prev => new Set(prev).add(child.resourceId))
@@ -859,6 +842,7 @@ export function GfsBrowser(): React.JSX.Element {
<span className="cu-gfs-manage-dialog__title-row">
<h3>{selected.name}</h3>
<GfsResourceMenu
+ createShareDisabled={createShareDisabled}
resourceName={selected.name}
resourceUri={selected.gfsUri}
downloading={downloadingIds.has(selected.resourceId)}
@@ -873,6 +857,7 @@ export function GfsBrowser(): React.JSX.Element {
: undefined
}
onCopyLink={() => void copyGfsUri(selected.gfsUri)}
+ onCreateShare={() => createShareActionRef.current?.()}
onRename={() => {
setRenameName(selected.name)
setRenameOpen(true)
@@ -892,11 +877,6 @@ export function GfsBrowser(): React.JSX.Element {
)}
</span>
<span className="cu-gfs-manage-dialog__top-actions">
- {selected.kind === 'directory' ? (
- <Button size="sm" onClick={() => manageUploadInputRef.current?.click()}>
- Upload file
- </Button>
- ) : null}
<Button
autoFocus
className="cu-gfs-manage-dialog__close"
@@ -909,20 +889,6 @@ export function GfsBrowser(): React.JSX.Element {
</span>
</header>
- {selected.kind === 'directory' ? (
- <input
- aria-label="Upload file"
- className="sr-only"
- ref={manageUploadInputRef}
- type="file"
- onChange={event => {
- const file = event.currentTarget.files?.[0]
- event.currentTarget.value = ''
- void uploadFileToFolder(selected, file)
- }}
- />
- ) : null}
-
<div className="cu-gfs-manage-dialog__body">
<section className="cu-gfs-manage-section cu-gfs-manage-section--access">
<div className="cu-gfs-manage-section__header">
@@ -936,6 +902,7 @@ export function GfsBrowser(): React.JSX.Element {
gfsUri: selected.gfsUri,
kind: selected.kind,
}}
+ onCreateShareActionChange={handleCreateShareActionChange}
/>
</section>
</div>
diff --git a/control-ui/components/GfsGrantPanel.tsx b/control-ui/components/GfsGrantPanel.tsx
index ab2e24eab..0b75b0a52 100644
--- a/control-ui/components/GfsGrantPanel.tsx
+++ b/control-ui/components/GfsGrantPanel.tsx
@@ -51,7 +51,10 @@ const OPERATOR_OPTION: SelectionDropdownOption = {
badge: 'Operator',
}
-export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Element {
+export function GfsGrantPanel({
+ resource,
+ onCreateShareActionChange,
+}: GfsGrantPanelProps): React.JSX.Element {
const { showToast } = useToast()
const { confirm, confirmDialog } = useConfirmDialog()
const [users, setUsers] = useState<AdminUser[]>([])
@@ -72,6 +75,7 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Eleme
const [existingAccessError, setExistingAccessError] = useState('')
const existingAccessRequest = useRef(0)
const existingAccessController = useRef<AbortController | null>(null)
+ const submitShareRef = useRef<() => void>(() => undefined)
const canIncludeDescendants = resource.kind === 'directory'
const loadExistingAccess = useCallback(async () => {
@@ -300,6 +304,16 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Eleme
}
}
+ submitShareRef.current = () => {
+ void submit('share')
+ }
+
+ useEffect(() => {
+ if (!onCreateShareActionChange) return
+ onCreateShareActionChange(() => submitShareRef.current(), !canSubmit || !canCreateShare)
+ return () => onCreateShareActionChange(null, true)
+ }, [canCreateShare, canSubmit, onCreateShareActionChange])
+
function subjectLabel(item: GfsExistingAccessItem): string {
if (item.subject.type === 'operator') return 'Operator'
const option = bulkSubjectOptions.find(
@@ -392,9 +406,6 @@ export function GfsGrantPanel({ resource }: GfsGrantPanelProps): React.JSX.Eleme
<Button variant="primary" disabled={!canSubmit} onClick={() => submit('grant')}>
Grant access
</Button>
- <Button disabled={!canSubmit || !canCreateShare} onClick={() => submit('share')}>
- Create share
- </Button>
</div>
{error ? (
<p role="alert" className="cu-field__error">
diff --git a/control-ui/components/GfsGrantPanel.types.ts b/control-ui/components/GfsGrantPanel.types.ts
index 1e5a69b00..9291f8b48 100644
--- a/control-ui/components/GfsGrantPanel.types.ts
+++ b/control-ui/components/GfsGrantPanel.types.ts
@@ -27,8 +27,11 @@ export type GfsGrantResource = {
kind?: string
}
+export type GfsCreateShareActionChange = (action: (() => void) | null, disabled: boolean) => void
+
export interface GfsGrantPanelProps {
resource: GfsGrantResource
+ onCreateShareActionChange?: GfsCreateShareActionChange
}
export type GfsExistingAccessItem =
diff --git a/control-ui/components/GfsResourceMenu/index.tsx b/control-ui/components/GfsResourceMenu/index.tsx
index add97230c..d138ca2ad 100644
--- a/control-ui/components/GfsResourceMenu/index.tsx
+++ b/control-ui/components/GfsResourceMenu/index.tsx
@@ -6,8 +6,10 @@ import { IconMoreHorizontal } from '@components/icons'
import type { GfsResourceMenuProps } from './types'
export function GfsResourceMenu({
+ createShareDisabled = false,
downloading = false,
onCopyLink,
+ onCreateShare,
onDelete,
onDownload,
onManage,
@@ -88,6 +90,17 @@ export function GfsResourceMenu({
Manage access
</button>
) : null}
+ {onCreateShare ? (
+ <button
+ type="button"
+ role="menuitem"
+ className="cu-kebab__item"
+ disabled={createShareDisabled}
+ onClick={() => run(onCreateShare)}
+ >
+ Create share
+ </button>
+ ) : null}
{onPreview ? (
<button
type="button"
diff --git a/control-ui/components/GfsResourceMenu/types.ts b/control-ui/components/GfsResourceMenu/types.ts
index b8928d646..b443c9ee5 100644
--- a/control-ui/components/GfsResourceMenu/types.ts
+++ b/control-ui/components/GfsResourceMenu/types.ts
@@ -1,6 +1,8 @@
export interface GfsResourceMenuProps {
+ createShareDisabled?: boolean
downloading?: boolean
onCopyLink: () => void
+ onCreateShare?: () => void
onDelete: () => void
onDownload?: () => void
onManage?: () => void
diff --git a/control-ui/components/__tests__/GfsBrowser.test.tsx b/control-ui/components/__tests__/GfsBrowser.test.tsx
index 44c2a5481..fd0ac7443 100644
--- a/control-ui/components/__tests__/GfsBrowser.test.tsx
+++ b/control-ui/components/__tests__/GfsBrowser.test.tsx
@@ -14,6 +14,7 @@ import {
getRecipes,
gfsDownload,
gfsFetchFileBlob,
+ postGfsShare,
putGfsGrant,
} from '@lib/api'
import { normalizeGfsResourceName } from '@lib/gfsResourceName'
@@ -33,6 +34,7 @@ vi.mock('@lib/api', () => ({
gfsDownload: vi.fn(),
gfsFetchFileBlob: vi.fn(),
isSilentApiError: () => false,
+ postGfsShare: vi.fn(),
putGfsGrant: vi.fn(),
}))
@@ -47,6 +49,7 @@ const mockGetRecipes = vi.mocked(getRecipes)
const mockPutGfsGrant = putGfsGrant as unknown as ReturnType<typeof vi.fn>
const mockGfsDownload = gfsDownload as unknown as ReturnType<typeof vi.fn>
const mockGfsFetchFileBlob = gfsFetchFileBlob as unknown as ReturnType<typeof vi.fn>
+const mockPostGfsShare = vi.mocked(postGfsShare)
const mockCreateObjectUrl = vi.fn((_blob: Blob) => 'blob:gfs-image-preview')
const mockRevokeObjectUrl = vi.fn()
@@ -111,6 +114,7 @@ describe('GfsBrowser', () => {
mockPutGfsGrant.mockReset()
mockGfsDownload.mockReset()
mockGfsFetchFileBlob.mockReset()
+ mockPostGfsShare.mockReset()
mockCreateObjectUrl.mockReset()
mockCreateObjectUrl.mockReturnValue('blob:gfs-image-preview')
mockRevokeObjectUrl.mockReset()
@@ -965,12 +969,11 @@ describe('GfsBrowser', () => {
expect(screen.getByRole('button', { name: 'Grant access' })).not.toBeDisabled()
})
- it('includes descendants for directory grants and exposes share creation', async () => {
+ it('includes descendants for directory shares from the resource menu', async () => {
mockApiGet.mockResolvedValueOnce({
items: [child('team-folder', 'directory', 2)],
nextCursor: null,
})
- mockPutGfsGrant.mockResolvedValueOnce({ ok: true })
renderBrowser()
await openManage('team-folder')
@@ -979,18 +982,31 @@ describe('GfsBrowser', () => {
expect(
await screen.findByRole('checkbox', { name: /Include contents of this folder/ })
).toBeChecked()
- expect(screen.getByRole('button', { name: 'Create share' })).toBeDisabled()
+ const manageDialog = screen.getByRole('dialog', { name: 'Manage folder team-folder' })
+ const manageMenuTrigger = within(manageDialog).getByRole('button', {
+ name: 'Actions for team-folder',
+ })
+ expect(within(manageDialog).queryByRole('button', { name: 'Upload file' })).toBeNull()
+ fireEvent.click(manageMenuTrigger)
+ expect(within(manageDialog).getByRole('menuitem', { name: 'Create share' })).toBeDisabled()
+ fireEvent.click(manageMenuTrigger)
await openSubjectPicker()
fireEvent.click(await screen.findByRole('option', { name: 'Ada Lovelace' }))
selectPermission('Read')
- fireEvent.click(screen.getByRole('button', { name: 'Grant access' }))
- await confirmGrantAccess()
+ fireEvent.click(manageMenuTrigger)
+ const createShareItem = within(manageDialog).getByRole('menuitem', { name: 'Create share' })
+ expect(createShareItem).toBeEnabled()
+ fireEvent.click(createShareItem)
+ const shareDialog = await screen.findByRole('alertdialog', { name: 'Create share?' })
+ fireEvent.click(within(shareDialog).getByRole('button', { name: 'Create share' }))
await waitFor(() =>
- expect(mockPutGfsGrant).toHaveBeenCalledWith(
+ expect(mockPostGfsShare).toHaveBeenCalledWith(
expect.objectContaining({
resourceId: 'id-2',
- inherit: true,
+ subjects: [{ type: 'user', id: '11111111-1111-1111-1111-111111111111' }],
+ permissions: ['read'],
+ includeDescendants: true,
})
)
)
diff --git a/control-ui/components/__tests__/GfsGrantPanel.bulk.test.tsx b/control-ui/components/__tests__/GfsGrantPanel.bulk.test.tsx
index 27ae7707d..a033c0949 100644
--- a/control-ui/components/__tests__/GfsGrantPanel.bulk.test.tsx
+++ b/control-ui/components/__tests__/GfsGrantPanel.bulk.test.tsx
@@ -58,6 +58,9 @@ const workflowHostSubject = {
} as const
const operatorSubject = { type: 'operator' } as const
+let createShareAction: (() => void) | null = null
+let createShareDisabled = true
+
function successfulMutation(...updated: GfsSubjectInput[]): GfsMutationResponse {
return { ok: true, resourceId: resource.resourceId, updated, count: updated.length }
}
@@ -65,7 +68,13 @@ function successfulMutation(...updated: GfsSubjectInput[]): GfsMutationResponse
function renderPanel(target = resource) {
return render(
<ToastProvider>
- <GfsGrantPanel resource={target} />
+ <GfsGrantPanel
+ resource={target}
+ onCreateShareActionChange={(action, disabled) => {
+ createShareAction = action
+ createShareDisabled = disabled
+ }}
+ />
</ToastProvider>
)
}
@@ -102,7 +111,15 @@ function selectPermission(name: string) {
}
async function submit(action: 'Grant access' | 'Create share') {
- fireEvent.click(screen.getByRole('button', { name: action }))
+ if (action === 'Create share') {
+ await waitFor(() => {
+ expect(createShareAction).not.toBeNull()
+ expect(createShareDisabled).toBe(false)
+ })
+ createShareAction?.()
+ } else {
+ fireEvent.click(screen.getByRole('button', { name: action }))
+ }
const dialog = await screen.findByRole('alertdialog')
fireEvent.click(within(dialog).getByRole('button', { name: action }))
}
@@ -110,6 +127,8 @@ async function submit(action: 'Grant access' | 'Create share') {
describe('GfsGrantPanel bulk access', () => {
beforeEach(() => {
vi.clearAllMocks()
+ createShareAction = null
+ createShareDisabled = true
mockGetAdminUsers.mockResolvedValue({
items: [
{
@@ -335,7 +354,7 @@ describe('GfsGrantPanel bulk access', () => {
expect(within(permissions).getByRole('menuitemcheckbox', { name: 'Write' })).not.toBeChecked()
expect(within(permissions).queryByRole('menuitemcheckbox', { name: 'Delete' })).toBeNull()
expect(within(permissions).queryByRole('menuitemcheckbox', { name: 'Share' })).toBeNull()
- expect(screen.getByRole('button', { name: 'Create share' })).toBeDisabled()
+ expect(createShareDisabled).toBe(true)
await submit('Grant access')
@@ -391,7 +410,7 @@ describe('GfsGrantPanel bulk access', () => {
expect(dialog).toHaveTextContent('"reports"')
expect(dialog).toHaveTextContent('Permissions: read, write')
expect(dialog).toHaveTextContent('Scope: this resource and all descendants')
- expect(screen.getByRole('button', { name: 'Create share' })).toBeDisabled()
+ expect(createShareDisabled).toBe(true)
fireEvent.click(within(dialog).getByRole('button', { name: 'Cancel' }))
await waitFor(() => expect(screen.queryByRole('alertdialog')).toBeNull())
@@ -483,7 +502,7 @@ describe('GfsGrantPanel bulk access', () => {
within(openPermissionMenu()).getByRole('menuitemcheckbox', { name: 'Delete' })
).not.toBeChecked()
selectPermission('Read')
- expect(screen.getByRole('button', { name: 'Create share' })).toBeEnabled()
+ await waitFor(() => expect(createShareDisabled).toBe(false))
})
it('caps the UI selection at 100 subjects', async () => {
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index accdf57c0..2c6910463 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.451",
+ "version": "0.1.452",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.451",
+ "version": "0.1.452",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/llm-providers": "file:../packages/llm-providers",
diff --git a/control-ui/package.json b/control-ui/package.json
index 1efd79c00..24b4ddf96 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.451",
+ "version": "0.1.452",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",
diff --git a/desktop-app/ui/src/pages/FilesPage.tsx b/desktop-app/ui/src/pages/FilesPage.tsx
index f1e22f705..2e9164f1d 100644
--- a/desktop-app/ui/src/pages/FilesPage.tsx
+++ b/desktop-app/ui/src/pages/FilesPage.tsx
@@ -148,7 +148,6 @@ export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }:
const [filePreview, setFilePreview] = useState<GfsPreviewResource | null>(null)
const [dragActive, setDragActive] = useState(false)
const [droppedUploadCount, setDroppedUploadCount] = useState(0)
- const uploadInputRef = useRef<HTMLInputElement | null>(null)
const replaceInputRef = useRef<HTMLInputElement | null>(null)
const queryClient = useQueryClient()
const ctrl = useGfsBrowserController({ grantsListEnabled: manageOpen })
@@ -1047,16 +1046,6 @@ export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }:
)}
</span>
<span className="da-gfs-manage-dialog__top-actions">
- {currentIsFolder && canWriteCurrent ? (
- <Button
- loading={ctrl.mutating}
- onClick={() => uploadInputRef.current?.click()}
- size="sm"
- variant="outline"
- >
- Upload file
- </Button>
- ) : null}
{currentIsFile && canWriteCurrent ? (
<Button
loading={ctrl.mutating}
@@ -1079,19 +1068,6 @@ export function FilesPage({ pushToast, pendingGfsUri, onPendingGfsUriHandled }:
</span>
</header>
- {currentIsFolder && canWriteCurrent ? (
- <input
- aria-label="Upload file"
- className="visually-hidden"
- ref={uploadInputRef}
- type="file"
- onChange={event => {
- const file = event.currentTarget.files?.[0]
- event.currentTarget.value = ''
- void handleUploadFile(file)
- }}
- />
- ) : null}
{currentIsFile && canWriteCurrent ? (
<input
aria-label="Replace file"
diff --git a/desktop-app/ui/src/styles.css b/desktop-app/ui/src/styles.css
index 829e314f6..516d8a6d1 100644
--- a/desktop-app/ui/src/styles.css
+++ b/desktop-app/ui/src/styles.css
@@ -14398,7 +14398,7 @@ pre {
}
.da-gfs-manage-dialog__icon--folder {
- color: var(--warning);
+ color: var(--text-muted);
}
.da-gfs-manage-dialog__icon svg {