@ossy/storage 3.18.0 → 3.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/src/ResourceGraphWidget.jsx +236 -0
- package/src/ResourcesPage.jsx +118 -6
- package/src/TaskRunDialog.jsx +139 -0
- package/src/en.translations.json +13 -1
- package/src/graph.helpers.js +79 -0
- package/src/sv.translations.json +13 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/storage",
|
|
3
3
|
"description": "Analytics module — workspace analytics for website traffic",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.20.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
|
7
7
|
"module": "./src/index.js",
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
],
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"@ossy/app": "*",
|
|
26
|
+
"@ossy/automation": "*",
|
|
26
27
|
"@ossy/design-system": "*",
|
|
27
28
|
"@ossy/resources": "*",
|
|
28
29
|
"@ossy/router-react": "*",
|
|
@@ -30,5 +31,5 @@
|
|
|
30
31
|
"ramda": "*",
|
|
31
32
|
"react": "*"
|
|
32
33
|
},
|
|
33
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "3e8bb118b3ef163792a004663ccb803ab51a8601"
|
|
34
35
|
}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ResourceGraphWidget — SVG force-directed knowledge graph.
|
|
3
|
+
*
|
|
4
|
+
* Zero external dependencies.
|
|
5
|
+
* Mirrors the automation page (TaskCatalogGraph.jsx) pattern:
|
|
6
|
+
* - SVG <circle> + <line> elements for nodes and edges
|
|
7
|
+
* - CSS transform translate+scale on a <g> for pan/zoom
|
|
8
|
+
* - requestAnimationFrame force simulation updating React state
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react'
|
|
12
|
+
import { NODE_R, GRAPH_COLORS, initPositions, simStep } from './graph.helpers.js'
|
|
13
|
+
|
|
14
|
+
const GRAPH_API = '/api/v0/resources/graph'
|
|
15
|
+
|
|
16
|
+
async function fetchGraph (threshold = 0.5) {
|
|
17
|
+
const res = await fetch(
|
|
18
|
+
`${GRAPH_API}?threshold=${threshold}&maxEdges=800`,
|
|
19
|
+
{ credentials: 'include' },
|
|
20
|
+
)
|
|
21
|
+
if (!res.ok) throw new Error(`Graph API ${res.status}`)
|
|
22
|
+
return res.json()
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const MIN_ZOOM = 0.3
|
|
26
|
+
const MAX_ZOOM = 3
|
|
27
|
+
|
|
28
|
+
export function ResourceGraphWidget ({ workspaceId, threshold = 0.5, onNodeClick }) {
|
|
29
|
+
const svgRef = useRef(null)
|
|
30
|
+
const nodesRef = useRef([])
|
|
31
|
+
const edgesRef = useRef([])
|
|
32
|
+
const alphaRef = useRef(0)
|
|
33
|
+
const rafRef = useRef(null)
|
|
34
|
+
const dragRef = useRef(null)
|
|
35
|
+
|
|
36
|
+
const [status, setStatus] = useState('loading')
|
|
37
|
+
const [errorMsg, setErrorMsg] = useState(null)
|
|
38
|
+
const [tick, setTick] = useState(0) // incremented each sim frame
|
|
39
|
+
const [pan, setPan] = useState({ x: 0, y: 0 })
|
|
40
|
+
const [zoom, setZoom] = useState(0.9)
|
|
41
|
+
|
|
42
|
+
// ── Fetch graph data ───────────────────────────────────────────────────────
|
|
43
|
+
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (!workspaceId) return
|
|
46
|
+
let cancelled = false
|
|
47
|
+
setStatus('loading')
|
|
48
|
+
|
|
49
|
+
fetchGraph(threshold)
|
|
50
|
+
.then((data) => {
|
|
51
|
+
if (cancelled) return
|
|
52
|
+
if (!data.nodes?.length) { setStatus('empty'); return }
|
|
53
|
+
|
|
54
|
+
// Build simulation nodes
|
|
55
|
+
const nodes = data.nodes.map((n, i) => ({
|
|
56
|
+
_idx: i,
|
|
57
|
+
id: n.resourceId,
|
|
58
|
+
cluster: n.cluster ?? 0,
|
|
59
|
+
x: 0, y: 0, vx: 0, vy: 0,
|
|
60
|
+
}))
|
|
61
|
+
initPositions(nodes)
|
|
62
|
+
|
|
63
|
+
nodesRef.current = nodes
|
|
64
|
+
edgesRef.current = data.edges ?? []
|
|
65
|
+
alphaRef.current = 1
|
|
66
|
+
|
|
67
|
+
setStatus('ready')
|
|
68
|
+
})
|
|
69
|
+
.catch((err) => {
|
|
70
|
+
if (cancelled) return
|
|
71
|
+
setErrorMsg(err.message)
|
|
72
|
+
setStatus('error')
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
return () => { cancelled = true }
|
|
76
|
+
}, [workspaceId, threshold])
|
|
77
|
+
|
|
78
|
+
// ── Force simulation loop ──────────────────────────────────────────────────
|
|
79
|
+
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (status !== 'ready') return
|
|
82
|
+
|
|
83
|
+
function loop () {
|
|
84
|
+
if (alphaRef.current < 0.004) return
|
|
85
|
+
simStep(nodesRef.current, edgesRef.current, alphaRef.current)
|
|
86
|
+
alphaRef.current *= 0.98
|
|
87
|
+
setTick(t => t + 1)
|
|
88
|
+
rafRef.current = requestAnimationFrame(loop)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
rafRef.current = requestAnimationFrame(loop)
|
|
92
|
+
return () => { if (rafRef.current) cancelAnimationFrame(rafRef.current) }
|
|
93
|
+
}, [status])
|
|
94
|
+
|
|
95
|
+
// ── Centre on first render after data loads ────────────────────────────────
|
|
96
|
+
|
|
97
|
+
useLayoutEffect(() => {
|
|
98
|
+
if (status !== 'ready') return
|
|
99
|
+
const el = svgRef.current
|
|
100
|
+
if (!el) return
|
|
101
|
+
setPan({ x: el.clientWidth / 2, y: el.clientHeight / 2 })
|
|
102
|
+
}, [status])
|
|
103
|
+
|
|
104
|
+
// ── Pan ────────────────────────────────────────────────────────────────────
|
|
105
|
+
|
|
106
|
+
const onPointerDown = useCallback((e) => {
|
|
107
|
+
if (e.button !== 0) return
|
|
108
|
+
if (e.target.closest('[data-graph-node]')) return
|
|
109
|
+
dragRef.current = {
|
|
110
|
+
pointerId: e.pointerId,
|
|
111
|
+
startX: e.clientX,
|
|
112
|
+
startY: e.clientY,
|
|
113
|
+
origX: pan.x,
|
|
114
|
+
origY: pan.y,
|
|
115
|
+
}
|
|
116
|
+
e.currentTarget.setPointerCapture?.(e.pointerId)
|
|
117
|
+
}, [pan])
|
|
118
|
+
|
|
119
|
+
const onPointerMove = useCallback((e) => {
|
|
120
|
+
const d = dragRef.current
|
|
121
|
+
if (!d || d.pointerId !== e.pointerId) return
|
|
122
|
+
setPan({
|
|
123
|
+
x: d.origX + (e.clientX - d.startX),
|
|
124
|
+
y: d.origY + (e.clientY - d.startY),
|
|
125
|
+
})
|
|
126
|
+
}, [])
|
|
127
|
+
|
|
128
|
+
const onPointerUp = useCallback((e) => {
|
|
129
|
+
if (dragRef.current?.pointerId === e.pointerId) dragRef.current = null
|
|
130
|
+
}, [])
|
|
131
|
+
|
|
132
|
+
// ── Zoom ───────────────────────────────────────────────────────────────────
|
|
133
|
+
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
const el = svgRef.current
|
|
136
|
+
if (!el) return
|
|
137
|
+
const handler = (e) => {
|
|
138
|
+
e.preventDefault()
|
|
139
|
+
const rect = el.getBoundingClientRect()
|
|
140
|
+
const mx = e.clientX - rect.left
|
|
141
|
+
const my = e.clientY - rect.top
|
|
142
|
+
const factor = e.deltaY > 0 ? 0.92 : 1.08
|
|
143
|
+
setZoom(z => {
|
|
144
|
+
const next = Math.min(MAX_ZOOM, Math.max(MIN_ZOOM, z * factor))
|
|
145
|
+
// Keep pointer position stable while zooming
|
|
146
|
+
setPan(p => ({
|
|
147
|
+
x: mx - (mx - p.x) * (next / z),
|
|
148
|
+
y: my - (my - p.y) * (next / z),
|
|
149
|
+
}))
|
|
150
|
+
return next
|
|
151
|
+
})
|
|
152
|
+
}
|
|
153
|
+
el.addEventListener('wheel', handler, { passive: false })
|
|
154
|
+
return () => el.removeEventListener('wheel', handler)
|
|
155
|
+
}, [status]) // re-run when SVG mounts (status → 'ready')
|
|
156
|
+
|
|
157
|
+
// ── Render ─────────────────────────────────────────────────────────────────
|
|
158
|
+
|
|
159
|
+
const base = {
|
|
160
|
+
width: '100%', height: '100%', minHeight: '480px',
|
|
161
|
+
position: 'relative',
|
|
162
|
+
background: 'var(--surface-secondary, transparent)',
|
|
163
|
+
border: '1px solid var(--separator)',
|
|
164
|
+
borderRadius: 'var(--roundness-m, 8px)',
|
|
165
|
+
overflow: 'hidden',
|
|
166
|
+
}
|
|
167
|
+
const center = { ...base, display: 'flex', alignItems: 'center', justifyContent: 'center' }
|
|
168
|
+
const msgStyle = { color: 'var(--foreground-secondary)', fontSize: 13 }
|
|
169
|
+
|
|
170
|
+
if (status === 'loading') return <div style={center}><span style={msgStyle}>Loading graph…</span></div>
|
|
171
|
+
if (status === 'error') return <div style={center}><span style={msgStyle}>{errorMsg || 'Could not load graph data.'}</span></div>
|
|
172
|
+
if (status === 'empty') return <div style={center}><span style={msgStyle}>No embedded resources yet — run the Embed resource task on some files first.</span></div>
|
|
173
|
+
|
|
174
|
+
const nodes = nodesRef.current
|
|
175
|
+
const edges = edgesRef.current
|
|
176
|
+
|
|
177
|
+
return (
|
|
178
|
+
<div style={base}>
|
|
179
|
+
<svg
|
|
180
|
+
ref={svgRef}
|
|
181
|
+
style={{
|
|
182
|
+
display: 'block',
|
|
183
|
+
position: 'absolute', top: 0, left: 0,
|
|
184
|
+
width: '100%', height: '100%',
|
|
185
|
+
cursor: 'grab', userSelect: 'none', overflow: 'visible',
|
|
186
|
+
}}
|
|
187
|
+
onPointerDown={onPointerDown}
|
|
188
|
+
onPointerMove={onPointerMove}
|
|
189
|
+
onPointerUp={onPointerUp}
|
|
190
|
+
onPointerCancel={onPointerUp}
|
|
191
|
+
>
|
|
192
|
+
{/* Transparent full-coverage rect so pointer events fire over empty space */}
|
|
193
|
+
<rect width="100%" height="100%" fill="transparent" style={{ cursor: 'grab' }} />
|
|
194
|
+
|
|
195
|
+
<g transform={`translate(${pan.x},${pan.y}) scale(${zoom})`}>
|
|
196
|
+
|
|
197
|
+
{/* Edges */}
|
|
198
|
+
{edges.map((e, i) => {
|
|
199
|
+
const a = nodes[e.source], b = nodes[e.target]
|
|
200
|
+
if (!a || !b) return null
|
|
201
|
+
return (
|
|
202
|
+
<line
|
|
203
|
+
key={i}
|
|
204
|
+
x1={a.x} y1={a.y}
|
|
205
|
+
x2={b.x} y2={b.y}
|
|
206
|
+
style={{ stroke: 'color-mix(in srgb, var(--foreground) 20%, transparent)' }}
|
|
207
|
+
strokeWidth={Math.max(0.5, (e.weight ?? 0.5) * 2)}
|
|
208
|
+
strokeLinecap="round"
|
|
209
|
+
/>
|
|
210
|
+
)
|
|
211
|
+
})}
|
|
212
|
+
|
|
213
|
+
{/* Nodes */}
|
|
214
|
+
{nodes.map((n) => {
|
|
215
|
+
const color = GRAPH_COLORS[(n.cluster ?? 0) % GRAPH_COLORS.length]
|
|
216
|
+
return (
|
|
217
|
+
<g
|
|
218
|
+
key={n.id}
|
|
219
|
+
data-graph-node={n.id}
|
|
220
|
+
transform={`translate(${n.x},${n.y})`}
|
|
221
|
+
style={{ cursor: 'pointer' }}
|
|
222
|
+
onClick={() => onNodeClick?.({ resourceId: n.id })}
|
|
223
|
+
>
|
|
224
|
+
{/* Glow — use style prop so CSS vars resolve */}
|
|
225
|
+
<circle r={NODE_R + 4} style={{ fill: color, opacity: 0.18 }} />
|
|
226
|
+
{/* Node */}
|
|
227
|
+
<circle r={NODE_R} style={{ fill: color }} />
|
|
228
|
+
</g>
|
|
229
|
+
)
|
|
230
|
+
})}
|
|
231
|
+
|
|
232
|
+
</g>
|
|
233
|
+
</svg>
|
|
234
|
+
</div>
|
|
235
|
+
)
|
|
236
|
+
}
|
package/src/ResourcesPage.jsx
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React, { useState, useEffect, useCallback, useMemo, useRef } from 'react'
|
|
2
|
+
import { ResourceGraphWidget } from './ResourceGraphWidget.jsx'
|
|
2
3
|
import {
|
|
3
4
|
applyResourceSelectionGesture,
|
|
4
5
|
createDirectory,
|
|
@@ -42,9 +43,19 @@ import {
|
|
|
42
43
|
ResourceShareDialog,
|
|
43
44
|
useSelectedResourceId,
|
|
44
45
|
syncSelectedResources,
|
|
46
|
+
GetResource,
|
|
45
47
|
} from '@ossy/resources'
|
|
46
48
|
import { GetWorkspace } from '@ossy/workspaces'
|
|
47
|
-
import {
|
|
49
|
+
import { isServiceEntitled } from '@ossy/workspaces/entitlements'
|
|
50
|
+
import { AsyncStatus, useSdk, cacheKey } from '@ossy/sdk-react'
|
|
51
|
+
import { useApp } from '@ossy/app/shell'
|
|
52
|
+
import {
|
|
53
|
+
taskIconForId,
|
|
54
|
+
taskIntentFromId,
|
|
55
|
+
taskPayloadInputs,
|
|
56
|
+
tasksForResource,
|
|
57
|
+
translationKeysForTask,
|
|
58
|
+
} from '@ossy/automation'
|
|
48
59
|
import {
|
|
49
60
|
pipe,
|
|
50
61
|
split,
|
|
@@ -52,7 +63,8 @@ import {
|
|
|
52
63
|
identity,
|
|
53
64
|
last,
|
|
54
65
|
} from 'ramda'
|
|
55
|
-
import { Text, Overlay, Switch, DropZone, Breadcrumbs, Guide, DelayedRender, useDocumentTitle, View, Button, ContextMenu, Dropdown, Page, Tags, useLocale, preloadStorageIcons } from '@ossy/design-system'
|
|
66
|
+
import { Text, Overlay, Switch, DropZone, Breadcrumbs, Guide, DelayedRender, useDocumentTitle, View, Button, ContextMenu, Dropdown, Page, Tags, Alert, useLocale, hasTranslation, preloadStorageIcons } from '@ossy/design-system'
|
|
67
|
+
import { TaskRunDialog } from './TaskRunDialog.jsx'
|
|
56
68
|
import { useRouter, useSearchParams } from '@ossy/router-react'
|
|
57
69
|
|
|
58
70
|
const Path = ({ path, ...props }) => (
|
|
@@ -80,6 +92,7 @@ const Overlays = {
|
|
|
80
92
|
const ViewMode = {
|
|
81
93
|
List: 'list',
|
|
82
94
|
Grid: 'grid',
|
|
95
|
+
Graph: 'graph',
|
|
83
96
|
}
|
|
84
97
|
|
|
85
98
|
const SortBy = {
|
|
@@ -98,8 +111,9 @@ const SortOrder = {
|
|
|
98
111
|
export const ResourcesPage = () => {
|
|
99
112
|
const router = useRouter()
|
|
100
113
|
const searchParams = useSearchParams()
|
|
101
|
-
const { t } = useLocale()
|
|
114
|
+
const { t, messages } = useLocale()
|
|
102
115
|
const sdk = useSdk()
|
|
116
|
+
const app = useApp()
|
|
103
117
|
const { data: workspace = {} } = sdk.read(GetWorkspace)
|
|
104
118
|
const [overlay, setOverlay] = useState(Overlays.None)
|
|
105
119
|
const [viewMode, setViewMode] = useState(ViewMode.List)
|
|
@@ -110,10 +124,46 @@ export const ResourcesPage = () => {
|
|
|
110
124
|
const [selectionAnchorId, setSelectionAnchorId] = useState(null)
|
|
111
125
|
const [selectionMode, setSelectionMode] = useState(false)
|
|
112
126
|
const [pendingDirectoryDeleteId, setPendingDirectoryDeleteId] = useState(null)
|
|
127
|
+
const [taskFeedback, setTaskFeedback] = useState(null)
|
|
128
|
+
const [pendingTaskRun, setPendingTaskRun] = useState(null) // { task, resource }
|
|
113
129
|
const { selectedResourceId, setSelectedResourceId, clearSelectedResourceId } = useSelectedResourceId()
|
|
114
130
|
const activePath = useActivePath()
|
|
115
131
|
const lastSuccessfulResourcesRef = useRef([])
|
|
116
132
|
const lastSuccessfulTotalRef = useRef(0)
|
|
133
|
+
const taskCatalog = app?.taskCatalog
|
|
134
|
+
|
|
135
|
+
const runResourceTask = useCallback(async (task, resource, extraInputs = {}) => {
|
|
136
|
+
const actionId = task?.primaryActionId
|
|
137
|
+
if (!actionId || !resource?.id) return
|
|
138
|
+
const keys = translationKeysForTask(task.id)
|
|
139
|
+
const title = hasTranslation(messages, keys.title) ? t(keys.title) : taskIntentFromId(task.id)
|
|
140
|
+
setTaskFeedback({ variant: 'info', title: t('storage.resources.taskRunning'), body: title })
|
|
141
|
+
try {
|
|
142
|
+
const result = await sdk.invoke({ id: actionId }, { resourceId: resource.id, workspaceId: app?.workspaceId, ...extraInputs })
|
|
143
|
+
sdk.invalidate(cacheKey(GetResource, { resourceId: resource.id }))
|
|
144
|
+
if (result?.skipped) {
|
|
145
|
+
setTaskFeedback({ variant: 'warning', title: t('storage.resources.taskSkipped'), body: result.reason ?? title })
|
|
146
|
+
} else {
|
|
147
|
+
setTaskFeedback({ variant: 'success', title: t('storage.resources.taskFinished'), body: title })
|
|
148
|
+
// Open the resource panel so the user can see the artifacts.
|
|
149
|
+
setSelectedResourceId(resource.id)
|
|
150
|
+
}
|
|
151
|
+
} catch (err) {
|
|
152
|
+
setTaskFeedback({
|
|
153
|
+
variant: 'danger',
|
|
154
|
+
title: t('storage.resources.taskFailedTitle'),
|
|
155
|
+
body: err?.message || String(err),
|
|
156
|
+
})
|
|
157
|
+
}
|
|
158
|
+
}, [sdk, t, messages, app, setSelectedResourceId])
|
|
159
|
+
|
|
160
|
+
const onClickResourceTask = useCallback((task, resource) => {
|
|
161
|
+
if (taskPayloadInputs(task).length > 0) {
|
|
162
|
+
setPendingTaskRun({ task, resource })
|
|
163
|
+
} else {
|
|
164
|
+
runResourceTask(task, resource)
|
|
165
|
+
}
|
|
166
|
+
}, [runResourceTask])
|
|
117
167
|
|
|
118
168
|
useEffect(() => {
|
|
119
169
|
preloadStorageIcons()
|
|
@@ -439,6 +489,29 @@ export const ResourcesPage = () => {
|
|
|
439
489
|
>
|
|
440
490
|
{t('storage.resources.move')}
|
|
441
491
|
</ContextMenu.Item>,
|
|
492
|
+
...(() => {
|
|
493
|
+
const matchingTasks = tasksForResource(taskCatalog, resource)
|
|
494
|
+
.filter(task => !task.package || isServiceEntitled(workspace?.services, task.package))
|
|
495
|
+
if (!matchingTasks.length) return []
|
|
496
|
+
return [
|
|
497
|
+
<ContextMenu.Group key="tasks" label={t('storage.resources.tasks')}>
|
|
498
|
+
{matchingTasks.map((task) => {
|
|
499
|
+
const keys = translationKeysForTask(task.id)
|
|
500
|
+
const label = hasTranslation(messages, keys.title) ? t(keys.title) : taskIntentFromId(task.id)
|
|
501
|
+
return (
|
|
502
|
+
<ContextMenu.Item
|
|
503
|
+
key={task.id}
|
|
504
|
+
prefix={taskIconForId(task.id)}
|
|
505
|
+
disabled={!task.primaryActionId}
|
|
506
|
+
onClick={() => onClickResourceTask(task, resource)}
|
|
507
|
+
>
|
|
508
|
+
{label}
|
|
509
|
+
</ContextMenu.Item>
|
|
510
|
+
)
|
|
511
|
+
})}
|
|
512
|
+
</ContextMenu.Group>,
|
|
513
|
+
]
|
|
514
|
+
})(),
|
|
442
515
|
<ContextMenu.Separator key="separator"></ContextMenu.Separator>,
|
|
443
516
|
<ContextMenu.Item
|
|
444
517
|
key="remove"
|
|
@@ -450,7 +523,7 @@ export const ResourcesPage = () => {
|
|
|
450
523
|
]
|
|
451
524
|
}
|
|
452
525
|
|
|
453
|
-
}), [displayResources, activePath, storageHomeHref, openLocation, onMoveResource, onUploadFiles, onRemoveResource, setSelectedResourceId, t])
|
|
526
|
+
}), [displayResources, activePath, storageHomeHref, openLocation, onMoveResource, onUploadFiles, onRemoveResource, setSelectedResourceId, t, messages, taskCatalog, runResourceTask])
|
|
454
527
|
|
|
455
528
|
// Server already sorted + paginated.
|
|
456
529
|
const visibleResources = filterResources
|
|
@@ -620,6 +693,18 @@ export const ResourcesPage = () => {
|
|
|
620
693
|
>
|
|
621
694
|
<View stack bordered style={{ height: '100%', minHeight: 0 }}>
|
|
622
695
|
|
|
696
|
+
{taskFeedback && (
|
|
697
|
+
<View inset="s" style={{ flexShrink: 0 }}>
|
|
698
|
+
<Alert
|
|
699
|
+
variant={taskFeedback.variant}
|
|
700
|
+
title={taskFeedback.title}
|
|
701
|
+
onDismiss={() => setTaskFeedback(null)}
|
|
702
|
+
>
|
|
703
|
+
{taskFeedback.body}
|
|
704
|
+
</Alert>
|
|
705
|
+
</View>
|
|
706
|
+
)}
|
|
707
|
+
|
|
623
708
|
<View.Item
|
|
624
709
|
data-surface="primary"
|
|
625
710
|
layout="row"
|
|
@@ -744,7 +829,7 @@ export const ResourcesPage = () => {
|
|
|
744
829
|
trigger={(
|
|
745
830
|
<Button
|
|
746
831
|
{...OpenView}
|
|
747
|
-
prefix={viewMode === ViewMode.Grid ? 'layout-grid' : 'layout-list'}
|
|
832
|
+
prefix={viewMode === ViewMode.Graph ? 'asterisk' : viewMode === ViewMode.Grid ? 'layout-grid' : 'layout-list'}
|
|
748
833
|
variant="command"
|
|
749
834
|
aria-label={t('storage.resources.layout')}
|
|
750
835
|
style={{ height: '32px' }}
|
|
@@ -769,6 +854,13 @@ export const ResourcesPage = () => {
|
|
|
769
854
|
>
|
|
770
855
|
{t('storage.resources.viewGrid')}
|
|
771
856
|
</ContextMenu.Item>
|
|
857
|
+
<ContextMenu.Item
|
|
858
|
+
prefix="asterisk"
|
|
859
|
+
suffix={viewMode === ViewMode.Graph ? 'check' : undefined}
|
|
860
|
+
onClick={() => setViewMode(ViewMode.Graph)}
|
|
861
|
+
>
|
|
862
|
+
{t('storage.resources.viewGraph')}
|
|
863
|
+
</ContextMenu.Item>
|
|
772
864
|
</ContextMenu>
|
|
773
865
|
</View>
|
|
774
866
|
</Dropdown>
|
|
@@ -936,7 +1028,15 @@ export const ResourcesPage = () => {
|
|
|
936
1028
|
</Switch.Case>
|
|
937
1029
|
|
|
938
1030
|
<Switch.Case match={[ResourcesListStatus.Success]}>
|
|
939
|
-
{viewMode === ViewMode.
|
|
1031
|
+
{viewMode === ViewMode.Graph
|
|
1032
|
+
? (
|
|
1033
|
+
<ResourceGraphWidget
|
|
1034
|
+
workspaceId={workspace?.id}
|
|
1035
|
+
threshold={0.5}
|
|
1036
|
+
onNodeClick={({ resourceId }) => setSelectedResourceId(resourceId)}
|
|
1037
|
+
/>
|
|
1038
|
+
)
|
|
1039
|
+
: viewMode === ViewMode.Grid
|
|
940
1040
|
? (
|
|
941
1041
|
<ResourceGrid
|
|
942
1042
|
resources={visibleResources}
|
|
@@ -1108,6 +1208,18 @@ export const ResourcesPage = () => {
|
|
|
1108
1208
|
onClose={() => setOverlay(Overlays.None)}
|
|
1109
1209
|
/>
|
|
1110
1210
|
|
|
1211
|
+
<TaskRunDialog
|
|
1212
|
+
task={pendingTaskRun?.task}
|
|
1213
|
+
resource={pendingTaskRun?.resource}
|
|
1214
|
+
isVisible={Boolean(pendingTaskRun)}
|
|
1215
|
+
onConfirm={(inputs) => {
|
|
1216
|
+
const { task, resource } = pendingTaskRun
|
|
1217
|
+
setPendingTaskRun(null)
|
|
1218
|
+
runResourceTask(task, resource, inputs)
|
|
1219
|
+
}}
|
|
1220
|
+
onClose={() => setPendingTaskRun(null)}
|
|
1221
|
+
/>
|
|
1222
|
+
|
|
1111
1223
|
</Page>
|
|
1112
1224
|
</>
|
|
1113
1225
|
)
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import React, { useState, useEffect } from 'react'
|
|
3
|
+
import { Overlay, View, Text, Button, Input, Select, useLocale } from '@ossy/design-system'
|
|
4
|
+
import { taskPayloadInputs, translationKeysForTask, taskIntentFromId } from '@ossy/automation'
|
|
5
|
+
import { hasTranslation } from '@ossy/design-system'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Build initial form values from task input defaults.
|
|
9
|
+
*
|
|
10
|
+
* @param {object[]} inputs
|
|
11
|
+
* @returns {Record<string, string>}
|
|
12
|
+
*/
|
|
13
|
+
function initialValues (inputs) {
|
|
14
|
+
const values = {}
|
|
15
|
+
for (const input of inputs) {
|
|
16
|
+
values[input.name] = input.default !== undefined && input.default !== null
|
|
17
|
+
? String(input.default)
|
|
18
|
+
: ''
|
|
19
|
+
}
|
|
20
|
+
return values
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Generic dialog that collects payload inputs before running a task.
|
|
25
|
+
* Only shown for tasks that expose inputs with `sources: ['payload', …]`.
|
|
26
|
+
*
|
|
27
|
+
* @param {{
|
|
28
|
+
* task: object | null,
|
|
29
|
+
* resource: object | null,
|
|
30
|
+
* isVisible: boolean,
|
|
31
|
+
* onConfirm: (inputs: Record<string, unknown>) => void,
|
|
32
|
+
* onClose: () => void,
|
|
33
|
+
* }} props
|
|
34
|
+
*/
|
|
35
|
+
export function TaskRunDialog ({ task, resource, isVisible, onConfirm, onClose }) {
|
|
36
|
+
const { t, messages } = useLocale()
|
|
37
|
+
const inputs = taskPayloadInputs(task)
|
|
38
|
+
|
|
39
|
+
const [values, setValues] = useState(() => initialValues(inputs))
|
|
40
|
+
|
|
41
|
+
// Reset form whenever the task changes or the dialog (re-)opens.
|
|
42
|
+
useEffect(() => {
|
|
43
|
+
if (isVisible) setValues(initialValues(taskPayloadInputs(task)))
|
|
44
|
+
}, [task, isVisible])
|
|
45
|
+
|
|
46
|
+
if (!isVisible || !task) return null
|
|
47
|
+
|
|
48
|
+
const keys = translationKeysForTask(task.id)
|
|
49
|
+
const title = hasTranslation(messages, keys.title) ? t(keys.title) : taskIntentFromId(task.id)
|
|
50
|
+
const resourceName = resource?.name || resource?.id || ''
|
|
51
|
+
|
|
52
|
+
const set = (name, value) => setValues(prev => ({ ...prev, [name]: value }))
|
|
53
|
+
|
|
54
|
+
const handleConfirm = () => {
|
|
55
|
+
// Coerce number inputs back to numbers.
|
|
56
|
+
const coerced = {}
|
|
57
|
+
for (const input of inputs) {
|
|
58
|
+
const raw = values[input.name]
|
|
59
|
+
if (input.type === 'number') {
|
|
60
|
+
const n = Number(raw)
|
|
61
|
+
coerced[input.name] = Number.isFinite(n) ? n : input.default
|
|
62
|
+
} else {
|
|
63
|
+
coerced[input.name] = raw !== '' ? raw : undefined
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
onConfirm(coerced)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<Overlay isVisible={true} onClose={onClose}>
|
|
71
|
+
<View layout="off-center-s" style={{ height: '100%' }}>
|
|
72
|
+
<View
|
|
73
|
+
data-region="content"
|
|
74
|
+
style={{ width: 'min(400px, 92vw)' }}
|
|
75
|
+
>
|
|
76
|
+
<View surface="primary" roundness="s">
|
|
77
|
+
<View surface="primary" inset="l" roundness="s" gap="m">
|
|
78
|
+
<View gap="xs">
|
|
79
|
+
<Text variant="title-s">{title}</Text>
|
|
80
|
+
{resourceName && (
|
|
81
|
+
<Text variant="small" style={{ color: 'var(--foreground-secondary)' }}>
|
|
82
|
+
{resourceName}
|
|
83
|
+
</Text>
|
|
84
|
+
)}
|
|
85
|
+
</View>
|
|
86
|
+
|
|
87
|
+
{inputs.map(input => {
|
|
88
|
+
const label = input.description || input.name
|
|
89
|
+
const value = values[input.name] ?? ''
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<View key={input.name} gap="xs">
|
|
93
|
+
<Text variant="small" style={{ fontWeight: 600 }}>
|
|
94
|
+
{label}
|
|
95
|
+
{input.required && (
|
|
96
|
+
<Text as="span" variant="small" style={{ color: 'var(--palette-danger)' }}> *</Text>
|
|
97
|
+
)}
|
|
98
|
+
</Text>
|
|
99
|
+
|
|
100
|
+
{Array.isArray(input.options) ? (
|
|
101
|
+
<Select
|
|
102
|
+
value={value}
|
|
103
|
+
onChange={e => set(input.name, e.target.value)}
|
|
104
|
+
aria-label={label}
|
|
105
|
+
>
|
|
106
|
+
{input.options.map(option => (
|
|
107
|
+
<option key={option} value={option}>
|
|
108
|
+
{option.toUpperCase()}
|
|
109
|
+
</option>
|
|
110
|
+
))}
|
|
111
|
+
</Select>
|
|
112
|
+
) : (
|
|
113
|
+
<Input
|
|
114
|
+
type={input.type === 'number' ? 'number' : 'text'}
|
|
115
|
+
value={value}
|
|
116
|
+
placeholder={input.default !== undefined ? String(input.default) : ''}
|
|
117
|
+
onChange={e => set(input.name, e.target.value)}
|
|
118
|
+
aria-label={label}
|
|
119
|
+
/>
|
|
120
|
+
)}
|
|
121
|
+
</View>
|
|
122
|
+
)
|
|
123
|
+
})}
|
|
124
|
+
|
|
125
|
+
<View layout="row" gap="s" style={{ justifyContent: 'flex-end', flexWrap: 'wrap' }}>
|
|
126
|
+
<Button variant="command" onClick={onClose}>
|
|
127
|
+
{t('storage.taskRunDialog.cancel')}
|
|
128
|
+
</Button>
|
|
129
|
+
<Button variant="cta" prefix={task.primaryActionId ? undefined : undefined} onClick={handleConfirm}>
|
|
130
|
+
{t('storage.taskRunDialog.run')}
|
|
131
|
+
</Button>
|
|
132
|
+
</View>
|
|
133
|
+
</View>
|
|
134
|
+
</View>
|
|
135
|
+
</View>
|
|
136
|
+
</View>
|
|
137
|
+
</Overlay>
|
|
138
|
+
)
|
|
139
|
+
}
|
package/src/en.translations.json
CHANGED
|
@@ -37,6 +37,11 @@
|
|
|
37
37
|
"storage.resources.layout": "Layout",
|
|
38
38
|
"storage.resources.viewList": "List view",
|
|
39
39
|
"storage.resources.viewGrid": "Grid view",
|
|
40
|
+
"storage.resources.viewGraph": "Graph view",
|
|
41
|
+
"storage.graph.loading": "Loading graph…",
|
|
42
|
+
"storage.graph.loadingLib": "Initialising 3D engine…",
|
|
43
|
+
"storage.graph.empty": "No embedded resources yet. Run the Embed resource task on some files first.",
|
|
44
|
+
"storage.graph.error": "Could not load graph data.",
|
|
40
45
|
"storage.resources.sort": "Sort",
|
|
41
46
|
"storage.resources.sortByName": "Name",
|
|
42
47
|
"storage.resources.sortByCreated": "Date created",
|
|
@@ -48,5 +53,12 @@
|
|
|
48
53
|
"storage.resources.paginationLabel": "{from}–{to} of {total}",
|
|
49
54
|
"storage.resources.paginationPage": "Page {page} of {pages}",
|
|
50
55
|
"storage.resources.paginationPrevious": "Previous page",
|
|
51
|
-
"storage.resources.paginationNext": "Next page"
|
|
56
|
+
"storage.resources.paginationNext": "Next page",
|
|
57
|
+
"storage.resources.tasks": "Tasks",
|
|
58
|
+
"storage.resources.taskRunning": "Running task…",
|
|
59
|
+
"storage.resources.taskFinished": "Task finished",
|
|
60
|
+
"storage.resources.taskSkipped": "Task skipped",
|
|
61
|
+
"storage.resources.taskFailedTitle": "Task failed",
|
|
62
|
+
"storage.taskRunDialog.cancel": "Cancel",
|
|
63
|
+
"storage.taskRunDialog.run": "Run"
|
|
52
64
|
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* graph.helpers.js — force simulation helpers for ResourceGraphWidget.
|
|
3
|
+
*
|
|
4
|
+
* Pure JS, zero dependencies. Mirrors the role of task-catalog-graph.helpers.js.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const NODE_R = 18 // node circle radius (px at scale 1)
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Per-cluster colors.
|
|
11
|
+
* Use color-mix against the theme accent so they work in both light and dark.
|
|
12
|
+
* The hue-rotate trick keeps them visually distinct while staying on-brand.
|
|
13
|
+
*/
|
|
14
|
+
export const GRAPH_COLORS = [
|
|
15
|
+
'var(--color-accent)',
|
|
16
|
+
'color-mix(in srgb, var(--color-accent) 80%, hsl(270deg 70% 60%))',
|
|
17
|
+
'color-mix(in srgb, var(--color-accent) 60%, hsl(150deg 60% 50%))',
|
|
18
|
+
'color-mix(in srgb, var(--color-accent) 50%, hsl(30deg 80% 55%))',
|
|
19
|
+
'color-mix(in srgb, var(--color-accent) 40%, hsl(330deg 70% 55%))',
|
|
20
|
+
'color-mix(in srgb, var(--color-accent) 70%, hsl(200deg 65% 50%))',
|
|
21
|
+
'color-mix(in srgb, var(--color-accent) 30%, hsl(60deg 75% 50%))',
|
|
22
|
+
'color-mix(in srgb, var(--color-accent) 55%, hsl(0deg 70% 55%))',
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Initialise simulation state on an array of nodes.
|
|
27
|
+
* Mutates each node in-place, adding x, y, vx, vy.
|
|
28
|
+
*/
|
|
29
|
+
export function initPositions (nodes) {
|
|
30
|
+
for (const n of nodes) {
|
|
31
|
+
const angle = 2 * Math.PI * Math.random()
|
|
32
|
+
const r = 60 + Math.random() * 80
|
|
33
|
+
n.x = r * Math.cos(angle)
|
|
34
|
+
n.y = r * Math.sin(angle)
|
|
35
|
+
n.vx = 0
|
|
36
|
+
n.vy = 0
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Run one step of the force simulation. Mutates node positions.
|
|
42
|
+
*
|
|
43
|
+
* @param {object[]} nodes – must have x, y, vx, vy
|
|
44
|
+
* @param {object[]} edges – { source: number, target: number, weight: number }
|
|
45
|
+
* @param {number} alpha – current cooling factor (0…1)
|
|
46
|
+
*/
|
|
47
|
+
export function simStep (nodes, edges, alpha) {
|
|
48
|
+
const REPULSION = 1200
|
|
49
|
+
const SPRING = 0.06
|
|
50
|
+
const DAMPING = 0.80
|
|
51
|
+
|
|
52
|
+
// Repulsion
|
|
53
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
54
|
+
for (let j = i + 1; j < nodes.length; j++) {
|
|
55
|
+
const dx = nodes[j].x - nodes[i].x
|
|
56
|
+
const dy = nodes[j].y - nodes[i].y
|
|
57
|
+
const d2 = dx * dx + dy * dy
|
|
58
|
+
const d = Math.sqrt(d2) || 0.1
|
|
59
|
+
const f = (alpha * REPULSION) / d2
|
|
60
|
+
nodes[i].vx -= dx / d * f; nodes[i].vy -= dy / d * f
|
|
61
|
+
nodes[j].vx += dx / d * f; nodes[j].vy += dy / d * f
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Spring attraction
|
|
66
|
+
for (const e of edges) {
|
|
67
|
+
const a = nodes[e.source], b = nodes[e.target]
|
|
68
|
+
const dx = b.x - a.x, dy = b.y - a.y
|
|
69
|
+
const s = SPRING * (e.weight ?? 0.5) * alpha
|
|
70
|
+
a.vx += dx * s; a.vy += dy * s
|
|
71
|
+
b.vx -= dx * s; b.vy -= dy * s
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Integrate
|
|
75
|
+
for (const n of nodes) {
|
|
76
|
+
n.vx *= DAMPING; n.vy *= DAMPING
|
|
77
|
+
n.x += n.vx; n.y += n.vy
|
|
78
|
+
}
|
|
79
|
+
}
|
package/src/sv.translations.json
CHANGED
|
@@ -37,6 +37,11 @@
|
|
|
37
37
|
"storage.resources.layout": "Layout",
|
|
38
38
|
"storage.resources.viewList": "Listvy",
|
|
39
39
|
"storage.resources.viewGrid": "Rutnätsvy",
|
|
40
|
+
"storage.resources.viewGraph": "Grafvy",
|
|
41
|
+
"storage.graph.loading": "Laddar graf…",
|
|
42
|
+
"storage.graph.loadingLib": "Initierar 3D-motor…",
|
|
43
|
+
"storage.graph.empty": "Inga inbäddade resurser ännu. Kör rutinen Bädda in resurs på några filer först.",
|
|
44
|
+
"storage.graph.error": "Kunde inte ladda grafdata.",
|
|
40
45
|
"storage.resources.sort": "Sortera",
|
|
41
46
|
"storage.resources.sortByName": "Namn",
|
|
42
47
|
"storage.resources.sortByCreated": "Skapad",
|
|
@@ -48,5 +53,12 @@
|
|
|
48
53
|
"storage.resources.paginationLabel": "{from}–{to} av {total}",
|
|
49
54
|
"storage.resources.paginationPage": "Sida {page} av {pages}",
|
|
50
55
|
"storage.resources.paginationPrevious": "Föregående sida",
|
|
51
|
-
"storage.resources.paginationNext": "Nästa sida"
|
|
56
|
+
"storage.resources.paginationNext": "Nästa sida",
|
|
57
|
+
"storage.resources.tasks": "Rutiner",
|
|
58
|
+
"storage.resources.taskRunning": "Kör rutin…",
|
|
59
|
+
"storage.resources.taskFinished": "Rutinen klar",
|
|
60
|
+
"storage.resources.taskSkipped": "Rutinen hoppades över",
|
|
61
|
+
"storage.resources.taskFailedTitle": "Rutinen misslyckades",
|
|
62
|
+
"storage.taskRunDialog.cancel": "Avbryt",
|
|
63
|
+
"storage.taskRunDialog.run": "Kör"
|
|
52
64
|
}
|