@skaile/forge-layer-data-browser 0.0.0 → 0.2.0
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/CHANGELOG.md +13 -0
- package/README.md +33 -13
- package/app/app.config.ts +2 -1
- package/app/components/DataFilterBuilder.vue +2 -2
- package/app/components/DataRowSlideover.vue +1 -1
- package/app/components/DataValue.vue +6 -7
- package/app/pages/data/[entity].vue +42 -40
- package/app/pages/data/index.vue +67 -36
- package/app/plugins/data-browser.ts +32 -0
- package/app/utils/dataBrowser.ts +4 -4
- package/package.json +1 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# @skaile/forge-layer-data-browser
|
|
2
|
+
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 0454102: Paper look from forge-template-app: `/data` is now a tool (`appShell.tools`, reached through ⌘K and the user menu) instead of a sidebar entry, and a new ⌘K group "Data" lists every entity for owners. The entity overview is a calm list with quiet row counts and access words instead of cards and badges, entity tables drop the primary-key column, show booleans and enums without colour badges, put "New <entity>" in the header's primary action and show `ListEmpty` when there are no rows. Icons switch from Lucide to Tabler. Hosts need the matching forge-template-app core: `appShell.tools`, the `app-shell:extend` hook, `AppHeader`'s `count`/`primary` props, `ListEmpty`, the `calm-row` classes and the Tabler icon set (see the README's host contract).
|
|
8
|
+
|
|
9
|
+
## 0.1.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 6270e62: New package: the data-browser layer of forge-template-app as a versioned Nuxt layer (`extends: ['@skaile/forge-layer-data-browser']`) instead of a copy in each app. The owner's view of every entity `data.describe` exposes at `/data`: a table per entity with search, sort, paging and a filter builder, and a generic row form on the app's `SchemaForm`. It builds on the core of forge-template-app (host contract in the README); an app overrides single files by putting a file at the same path.
|
package/README.md
CHANGED
|
@@ -33,30 +33,48 @@ has all of them; an app that renamed or removed one overrides the layer file tha
|
|
|
33
33
|
| Kind | Used | Where in the template |
|
|
34
34
|
|---|---|---|
|
|
35
35
|
| Explicit imports | `~/utils/format` (`fromDateTimeInput`, `toDateTimeInput`), `~/utils/jsonSchema` (`labelOfKey`, `JsonSchema`) | `app/utils/` |
|
|
36
|
-
| Composables | `useDataApi`, `useMe`, `useDates`, `useConfirm`, `useDiscardGuard`, `useFormDirty` | `app/composables/` |
|
|
36
|
+
| Composables | `useDataApi`, `useMe`, `useDates`, `useConfirm`, `useDiscardGuard`, `useFormDirty`; the `me` payload under the `useNuxtData` key `'me'` (as `useMe` stores it) | `app/composables/` |
|
|
37
37
|
| Utils | `applyServerError`, `actionErrorMessage` | `app/utils/formErrors.ts`, `app/composables/useActions.ts` |
|
|
38
|
-
| Components | `AppHeader`, `SchemaForm`, `FormDiscardPrompt`, `FormSaveHint` | `app/components/` |
|
|
39
|
-
|
|
|
38
|
+
| Components | `AppHeader` with the `count`, `back`, `back-label` and `primary` (`{ label, icon, onClick }`) props, `ListEmpty` (`title`, `description`), `SchemaForm`, `FormDiscardPrompt`, `FormSaveHint` | `app/components/` |
|
|
39
|
+
| CSS | the calm-list row classes `calm-list`, `calm-row`, `calm-row-target` (`/data`'s entity list) | `app/assets/css/main.css` |
|
|
40
|
+
| Icons | the Tabler set (`i-tabler-*`, `@iconify-json/tabler`) | `package.json` |
|
|
41
|
+
| App config | `appShell.tools` entries with `roles` (read by `useAppShell`; ⌘K and the user menu) | `app/utils/appShell.ts`, `app/components/UserMenu.vue` |
|
|
42
|
+
| Shell hook | `app-shell:extend` with `shell.commands` (⌘K groups), called after `me` loaded | `app/layouts/default.vue`, `app/types/app-shell.d.ts` |
|
|
43
|
+
| Modules | `@vueuse/nuxt` (auto-imports `refDebounced`, `watchDebounced`) | `nuxt.config.ts` `modules` |
|
|
40
44
|
| Actions | `data.describe`, `data.list`, `data.get`, `data.aggregate`, `data.create`, `data.update`, `data.delete`, `me.get` | `server/utils/actions/` |
|
|
41
45
|
|
|
42
46
|
Peers: `nuxt ^4`, `@nuxt/ui ^4.11`, `vue ^3.5`, `@skaile/forge-data ^0.2.1` (types).
|
|
43
47
|
|
|
44
48
|
## Overrides
|
|
45
49
|
|
|
46
|
-
A Nuxt layer is overridden
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
A Nuxt layer is overridden piece by piece; the app's piece wins, the rest keeps coming from the package, so fixes in
|
|
51
|
+
the other files still arrive with updates:
|
|
52
|
+
|
|
53
|
+
- a component: a file with the same name in the app's `app/components/` (e.g. `DataValue.vue` to render a field type differently)
|
|
54
|
+
- a page: a page at the same route in the app's `app/pages/`
|
|
55
|
+
- an auto-imported composable or util: an export with the same name in the app's `app/composables/` or `app/utils/`
|
|
56
|
+
(override the whole file: the app's file replaces every export of that name)
|
|
57
|
+
- `app/app.config.ts`: the app's own `app.config.ts` is merged over the layer's, so set only the keys you change.
|
|
58
|
+
Arrays such as `appShell.tools` are joined, the app's entries first, so an app entry with the same `to` shows next
|
|
59
|
+
to the layer's unless the app's `useAppShell` keeps one entry per route, e.g. for
|
|
60
|
+
`{ label: 'Daten', icon: 'i-tabler-database', to: '/data', order: 80, roles: ['owner'] }`
|
|
61
|
+
|
|
62
|
+
The layer has no server code: it reads and writes only through the host's `data.*` actions.
|
|
49
63
|
|
|
50
64
|
## What you get
|
|
51
65
|
|
|
52
|
-
- `/data` (
|
|
53
|
-
they are read-only or owner-only
|
|
54
|
-
|
|
66
|
+
- `/data` (a tool: ⌘K "Tools" and the user menu, order 80, owners only): a calm list of the entities with their
|
|
67
|
+
description, row count (`data.aggregate`) and, as quiet words, whether they are read-only or owner-only; `ListEmpty`
|
|
68
|
+
when the app exposes none. The header counts the entities.
|
|
69
|
+
- ⌘K group "Data" (owners only, `app/plugins/data-browser.ts`): one entry per entity, `Data › <Entity>` →
|
|
70
|
+
`/data/<entity>`, filled once `data.describe` answers in the browser.
|
|
71
|
+
- `/data/<entity>`: a table with one column per described field except the primary key (shown in the row's slideover;
|
|
55
72
|
foreign keys show the related row's label via `expand`), search over the entity's search fields, sort by clicking a
|
|
56
73
|
sortable column (asc, desc, default), pages of 25 with the total, and a filter builder: rows of field (own fields and
|
|
57
|
-
one-level relation paths such as `
|
|
74
|
+
one-level relation paths such as `folder.name`), operator (by field type; datetimes get ranges, not equality) and
|
|
58
75
|
value, ANDed into `where`. "Is any of" on a foreign key picks rows of the target; on numbers it keeps only the tags
|
|
59
|
-
that are numbers.
|
|
76
|
+
that are numbers. Booleans show as a check or a dash, enums as plain text; without rows the table shows `ListEmpty`
|
|
77
|
+
("No rows match" under a search or filter, else "No <entity> rows yet"). "New <entity>" is the header's primary action.
|
|
60
78
|
- A slideover per row and "New <entity>": the core's `SchemaForm` with a schema built from the field descriptors
|
|
61
79
|
(`rowSchemaOf`). Foreign keys pick a row of the target by its `labelField` (searchable once there are more than 10),
|
|
62
80
|
datetimes are entered and shown on the app's clock (`app.timezone`, `useDates().timeZone`) and sent as ISO, nullable
|
|
@@ -67,8 +85,9 @@ into the app and keep the rest from the package, so fixes in the other files sti
|
|
|
67
85
|
|
|
68
86
|
## Owners only
|
|
69
87
|
|
|
70
|
-
- UI: the
|
|
71
|
-
`owner-only` route middleware, which sends non-owners to the dashboard (`me.get` ›
|
|
88
|
+
- UI: the tool entry carries `roles: ['owner']` (`useAppShell` hides it from everyone else), the ⌘K group is added only
|
|
89
|
+
for owners, and both pages use the `owner-only` route middleware, which sends non-owners to the dashboard (`me.get` ›
|
|
90
|
+
`principal.roles`).
|
|
72
91
|
- Server: the browser is a UI convenience, a client like any other. Members reach the same rows of every entity the app
|
|
73
92
|
exposes through `data.*` (HTTP, CLI, MCP, the curated pages); hiding `/data` from them restricts nothing. An entity
|
|
74
93
|
meant for owners only says so in its `defineEntity`: `ops: { ownerOnly: true }`; forge-data's service then answers 403
|
|
@@ -83,6 +102,7 @@ into the app and keep the rest from the package, so fixes in the other files sti
|
|
|
83
102
|
| The shared model (`data.describe`); rows via the core's `useDataApi()` | `app/composables/useDataBrowser.ts` |
|
|
84
103
|
| Operators per type, filter rows → `where`, form schema, changed values | `app/utils/dataBrowser.ts` |
|
|
85
104
|
| Route guard | `app/middleware/owner-only.ts` |
|
|
105
|
+
| ⌘K group "Data" | `app/plugins/data-browser.ts` |
|
|
86
106
|
|
|
87
107
|
## Tests
|
|
88
108
|
|
package/app/app.config.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export default defineAppConfig({
|
|
2
2
|
appShell: {
|
|
3
|
-
|
|
3
|
+
// A tool, not a nav entry: reached through ⌘K and the user menu (forge-template-app's APP-DESIGN.md SHELL-2).
|
|
4
|
+
tools: [{ label: 'Data', icon: 'i-tabler-database', to: '/data', order: 80, roles: ['owner'] }],
|
|
4
5
|
},
|
|
5
6
|
})
|
|
@@ -178,7 +178,7 @@ watchDebounced(
|
|
|
178
178
|
/>
|
|
179
179
|
</template>
|
|
180
180
|
<UButton
|
|
181
|
-
icon="i-
|
|
181
|
+
icon="i-tabler-x"
|
|
182
182
|
color="neutral"
|
|
183
183
|
variant="ghost"
|
|
184
184
|
aria-label="Remove condition"
|
|
@@ -186,7 +186,7 @@ watchDebounced(
|
|
|
186
186
|
/>
|
|
187
187
|
</div>
|
|
188
188
|
<UButton
|
|
189
|
-
icon="i-
|
|
189
|
+
icon="i-tabler-plus"
|
|
190
190
|
label="Add condition"
|
|
191
191
|
color="neutral"
|
|
192
192
|
variant="soft"
|
|
@@ -27,15 +27,14 @@ const text = computed(() => {
|
|
|
27
27
|
>—</span>
|
|
28
28
|
<UIcon
|
|
29
29
|
v-else-if="field.type === 'boolean'"
|
|
30
|
-
:name="value ? 'i-
|
|
31
|
-
:class="value ? 'size-4 text-
|
|
30
|
+
:name="value ? 'i-tabler-check' : 'i-tabler-minus'"
|
|
31
|
+
:class="value ? 'size-4 text-default' : 'size-4 text-dimmed'"
|
|
32
|
+
:aria-label="value ? 'Yes' : 'No'"
|
|
32
33
|
/>
|
|
33
|
-
<
|
|
34
|
+
<span
|
|
34
35
|
v-else-if="field.enum"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
:label="text"
|
|
38
|
-
/>
|
|
36
|
+
class="text-default"
|
|
37
|
+
>{{ text }}</span>
|
|
39
38
|
<code
|
|
40
39
|
v-else-if="field.type === 'json'"
|
|
41
40
|
class="block max-w-xs truncate text-xs"
|
|
@@ -63,31 +63,35 @@ function headerOf(field: FieldDescriptor, label: string) {
|
|
|
63
63
|
class: '-mx-2.5',
|
|
64
64
|
trailingIcon:
|
|
65
65
|
order === 'asc'
|
|
66
|
-
? 'i-
|
|
66
|
+
? 'i-tabler-sort-ascending'
|
|
67
67
|
: order === 'desc'
|
|
68
|
-
? 'i-
|
|
69
|
-
: 'i-
|
|
68
|
+
? 'i-tabler-sort-descending'
|
|
69
|
+
: 'i-tabler-arrows-sort',
|
|
70
70
|
'aria-label': `Sort by ${label}`,
|
|
71
71
|
onClick: () => toggleSort(field.key),
|
|
72
72
|
})
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
+
// A generated id says nothing in a list: primary keys stay in the row's slideover, not as the
|
|
76
|
+
// leading column.
|
|
75
77
|
const columns = computed<TableColumn<Row>[]>(() =>
|
|
76
|
-
entity.fields
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
78
|
+
entity.fields
|
|
79
|
+
.filter(field => !field.primaryKey)
|
|
80
|
+
.map(field => {
|
|
81
|
+
const relation = relationOfField(entity, field.key)
|
|
82
|
+
const label = relation ? relationLabelOf(entity, relation) : field.label
|
|
83
|
+
return {
|
|
84
|
+
id: field.key,
|
|
85
|
+
accessorFn: row => row[field.key],
|
|
86
|
+
header: () => headerOf(field, label),
|
|
87
|
+
cell: ({ row }) =>
|
|
88
|
+
h(DataValue, {
|
|
89
|
+
field,
|
|
90
|
+
value: row.original[field.key],
|
|
91
|
+
relation: relation ? row.original[relation.name] : undefined,
|
|
92
|
+
}),
|
|
93
|
+
}
|
|
94
|
+
}),
|
|
91
95
|
)
|
|
92
96
|
|
|
93
97
|
const selected = ref<Row | null>(null)
|
|
@@ -110,34 +114,23 @@ const range = computed(() => {
|
|
|
110
114
|
<template #header>
|
|
111
115
|
<AppHeader
|
|
112
116
|
:title="entityTitleOf(entity)"
|
|
113
|
-
:
|
|
117
|
+
:count="data?.total"
|
|
114
118
|
back="/data"
|
|
115
119
|
back-label="All entities"
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
v-if="entity.ops.create"
|
|
119
|
-
#actions
|
|
120
|
-
>
|
|
121
|
-
<UButton
|
|
122
|
-
icon="i-lucide-plus"
|
|
123
|
-
:label="`New ${entity.label.toLowerCase()}`"
|
|
124
|
-
data-testid="data-new"
|
|
125
|
-
@click="openRow(null)"
|
|
126
|
-
/>
|
|
127
|
-
</template>
|
|
128
|
-
</AppHeader>
|
|
120
|
+
:primary="entity.ops.create ? { label: `New ${entity.label.toLowerCase()}`, icon: 'i-tabler-plus', onClick: () => openRow(null) } : undefined"
|
|
121
|
+
/>
|
|
129
122
|
<UDashboardToolbar>
|
|
130
123
|
<template #left>
|
|
131
124
|
<UInput
|
|
132
125
|
v-if="entity.search.length > 0"
|
|
133
126
|
v-model="q"
|
|
134
|
-
icon="i-
|
|
127
|
+
icon="i-tabler-search"
|
|
135
128
|
:placeholder="`Search ${entity.search.join(', ')}…`"
|
|
136
|
-
class="w-64"
|
|
129
|
+
class="min-w-0 flex-1 sm:w-64 sm:flex-none"
|
|
137
130
|
data-testid="data-search"
|
|
138
131
|
/>
|
|
139
132
|
<UButton
|
|
140
|
-
icon="i-
|
|
133
|
+
icon="i-tabler-filter"
|
|
141
134
|
:label="where.length > 0 ? `Filter (${where.length})` : 'Filter'"
|
|
142
135
|
color="neutral"
|
|
143
136
|
:variant="showFilters ? 'soft' : 'ghost'"
|
|
@@ -146,13 +139,16 @@ const range = computed(() => {
|
|
|
146
139
|
/>
|
|
147
140
|
</template>
|
|
148
141
|
<template #right>
|
|
149
|
-
<span class="text-sm text-muted">{{ range }}</span>
|
|
142
|
+
<span class="text-sm text-muted tabular-nums">{{ range }}</span>
|
|
150
143
|
</template>
|
|
151
144
|
</UDashboardToolbar>
|
|
152
145
|
</template>
|
|
153
146
|
|
|
154
147
|
<template #body>
|
|
155
|
-
<p
|
|
148
|
+
<p
|
|
149
|
+
v-if="entity.description"
|
|
150
|
+
class="max-w-prose text-sm text-muted"
|
|
151
|
+
>
|
|
156
152
|
{{ entity.description }}
|
|
157
153
|
</p>
|
|
158
154
|
<DataFilterBuilder
|
|
@@ -165,19 +161,25 @@ const range = computed(() => {
|
|
|
165
161
|
v-if="error"
|
|
166
162
|
color="error"
|
|
167
163
|
variant="subtle"
|
|
168
|
-
icon="i-
|
|
164
|
+
icon="i-tabler-alert-circle"
|
|
169
165
|
:title="actionErrorMessage(error)"
|
|
170
166
|
/>
|
|
171
167
|
<UTable
|
|
172
168
|
:data="data?.items ?? []"
|
|
173
169
|
:columns="columns"
|
|
174
170
|
:loading="status === 'pending'"
|
|
175
|
-
empty="No rows match."
|
|
176
171
|
class="flex-1"
|
|
177
172
|
:ui="{ tr: 'cursor-pointer' }"
|
|
178
173
|
data-testid="data-table"
|
|
179
174
|
@select="(_event, row) => openRow(row.original)"
|
|
180
|
-
|
|
175
|
+
>
|
|
176
|
+
<template #empty>
|
|
177
|
+
<ListEmpty
|
|
178
|
+
:title="where.length || search ? 'No rows match' : `No ${entity.label.toLowerCase()} rows yet`"
|
|
179
|
+
:description="where.length || search ? 'Change the search or the filter.' : undefined"
|
|
180
|
+
/>
|
|
181
|
+
</template>
|
|
182
|
+
</UTable>
|
|
181
183
|
<div
|
|
182
184
|
v-if="(data?.total ?? 0) > PAGE_SIZE"
|
|
183
185
|
class="flex justify-end"
|
package/app/pages/data/index.vue
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import type { DataModel } from '@skaile/forge-data'
|
|
3
|
+
|
|
2
4
|
definePageMeta({ middleware: 'owner-only' })
|
|
3
5
|
useHead({ title: 'Data' })
|
|
4
6
|
|
|
@@ -17,52 +19,81 @@ const { data: counts } = await useAsyncData(
|
|
|
17
19
|
},
|
|
18
20
|
{ watch: [model] },
|
|
19
21
|
)
|
|
22
|
+
|
|
23
|
+
type Entity = DataModel['entities'][number]
|
|
24
|
+
|
|
25
|
+
/** "read-only · owner only": what the entity allows, as quiet words (no badges). */
|
|
26
|
+
function accessOf(entity: Entity) {
|
|
27
|
+
return [
|
|
28
|
+
!entity.ops.create && !entity.ops.update && !entity.ops.delete ? 'read-only' : null,
|
|
29
|
+
entity.ops.ownerOnly ? 'owner only' : null,
|
|
30
|
+
]
|
|
31
|
+
.filter(Boolean)
|
|
32
|
+
.join(' · ')
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function countOf(name: string) {
|
|
36
|
+
if (!counts.value) return '…'
|
|
37
|
+
const count = counts.value[name] ?? 0
|
|
38
|
+
return `${count} ${count === 1 ? 'row' : 'rows'}`
|
|
39
|
+
}
|
|
20
40
|
</script>
|
|
21
41
|
|
|
22
42
|
<template>
|
|
23
43
|
<UDashboardPanel id="data">
|
|
24
44
|
<template #header>
|
|
25
|
-
<AppHeader
|
|
45
|
+
<AppHeader
|
|
46
|
+
title="Data"
|
|
47
|
+
:count="model?.entities.length"
|
|
48
|
+
/>
|
|
26
49
|
</template>
|
|
27
50
|
|
|
28
51
|
<template #body>
|
|
29
|
-
<
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
<
|
|
34
|
-
v-
|
|
35
|
-
|
|
36
|
-
:to="`/data/${entity.name}`"
|
|
37
|
-
:title="entityTitleOf(entity)"
|
|
38
|
-
:description="entity.description"
|
|
39
|
-
icon="i-lucide-table-2"
|
|
40
|
-
variant="subtle"
|
|
41
|
-
:data-testid="`data-entity-${entity.name}`"
|
|
52
|
+
<div class="mx-auto flex w-full flex-col gap-3 lg:max-w-3xl">
|
|
53
|
+
<p class="max-w-prose text-sm text-muted">
|
|
54
|
+
Every entity the app exposes through the <code>data.*</code> actions, with the same checks as the API and the agents.
|
|
55
|
+
</p>
|
|
56
|
+
<ul
|
|
57
|
+
v-if="model?.entities.length"
|
|
58
|
+
class="calm-list -mx-3 flex flex-col"
|
|
42
59
|
>
|
|
43
|
-
<
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
<li
|
|
61
|
+
v-for="entity in model.entities"
|
|
62
|
+
:key="entity.name"
|
|
63
|
+
class="calm-row relative"
|
|
64
|
+
:data-testid="`data-entity-${entity.name}`"
|
|
65
|
+
>
|
|
66
|
+
<UIcon
|
|
67
|
+
name="i-tabler-table"
|
|
68
|
+
class="size-4 shrink-0 text-dimmed"
|
|
69
|
+
/>
|
|
70
|
+
<div class="min-w-0 flex-1">
|
|
71
|
+
<NuxtLink
|
|
72
|
+
:to="`/data/${entity.name}`"
|
|
73
|
+
class="calm-row-target block truncate text-sm font-medium text-highlighted after:absolute after:inset-0"
|
|
74
|
+
>
|
|
75
|
+
{{ entityTitleOf(entity) }}
|
|
76
|
+
</NuxtLink>
|
|
77
|
+
<p
|
|
78
|
+
v-if="entity.description"
|
|
79
|
+
class="truncate text-xs text-muted"
|
|
80
|
+
>
|
|
81
|
+
{{ entity.description }}
|
|
82
|
+
</p>
|
|
62
83
|
</div>
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
84
|
+
<span
|
|
85
|
+
v-if="accessOf(entity)"
|
|
86
|
+
class="hidden shrink-0 text-xs text-muted sm:block"
|
|
87
|
+
>{{ accessOf(entity) }}</span>
|
|
88
|
+
<span class="w-20 shrink-0 text-right text-xs text-muted tabular-nums">{{ countOf(entity.name) }}</span>
|
|
89
|
+
</li>
|
|
90
|
+
</ul>
|
|
91
|
+
<ListEmpty
|
|
92
|
+
v-else
|
|
93
|
+
title="No entities"
|
|
94
|
+
description="Entities appear here once a layer defines them with defineEntity."
|
|
95
|
+
/>
|
|
96
|
+
</div>
|
|
66
97
|
</template>
|
|
67
98
|
</UDashboardPanel>
|
|
68
99
|
</template>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { CommandPaletteGroup, CommandPaletteItem } from '@nuxt/ui'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ⌘K group "Data": one entry per exposed entity (`/data/<entity>`), for owners only (the
|
|
5
|
+
* pages guard themselves with `owner-only`). `/data` itself is the layer's tool entry
|
|
6
|
+
* (`app.config.ts`). The entities come from `data.describe`, loaded in the browser; the
|
|
7
|
+
* group fills when they arrive.
|
|
8
|
+
*/
|
|
9
|
+
export default defineNuxtPlugin(nuxtApp => {
|
|
10
|
+
// The layout loads `me` before it calls `app-shell:extend`.
|
|
11
|
+
const { data: me } = useNuxtData<{ principal: { roles: string[] } }>('me')
|
|
12
|
+
const api = useDataApi()
|
|
13
|
+
|
|
14
|
+
nuxtApp.hook('app-shell:extend', shell => {
|
|
15
|
+
if (!me.value?.principal.roles.includes('owner')) return
|
|
16
|
+
// Only the item list is reactive: the palette re-renders when it fills.
|
|
17
|
+
const items = shallowReactive<CommandPaletteItem[]>([])
|
|
18
|
+
const group: CommandPaletteGroup<CommandPaletteItem> = { id: 'data', label: 'Data', items }
|
|
19
|
+
shell.commands.push(group)
|
|
20
|
+
if (import.meta.server) return
|
|
21
|
+
void api.describe().then(model => {
|
|
22
|
+
items.push(
|
|
23
|
+
...model.entities.map(entity => ({
|
|
24
|
+
id: `data:${entity.name}`,
|
|
25
|
+
label: `Data › ${entityTitleOf(entity)}`,
|
|
26
|
+
icon: 'i-tabler-table',
|
|
27
|
+
to: `/data/${entity.name}`,
|
|
28
|
+
})),
|
|
29
|
+
)
|
|
30
|
+
})
|
|
31
|
+
})
|
|
32
|
+
})
|
package/app/utils/dataBrowser.ts
CHANGED
|
@@ -53,7 +53,7 @@ export function filterOpsOf(field: FieldDescriptor): FilterOp[] {
|
|
|
53
53
|
return ops.filter(op => op !== 'isNull' && op !== 'notNull')
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
/** One choice of the filter builder's field select: an own field or a one-level relation path (`
|
|
56
|
+
/** One choice of the filter builder's field select: an own field or a one-level relation path (`folder.name`). */
|
|
57
57
|
export interface FilterPath {
|
|
58
58
|
path: string
|
|
59
59
|
label: string
|
|
@@ -62,7 +62,7 @@ export interface FilterPath {
|
|
|
62
62
|
target?: EntityDescriptor
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
/** A relation's heading: its foreign key's label without the id (`
|
|
65
|
+
/** A relation's heading: its foreign key's label without the id (`Folder id` → `Folder`, `Created by` stays). */
|
|
66
66
|
export function relationLabelOf(entity: EntityDescriptor, relation: RelationDescriptor): string {
|
|
67
67
|
const label = entity.fields.find(field => field.key === relation.field)?.label ?? labelOfKey(relation.name)
|
|
68
68
|
return label.replace(/ id$/i, '')
|
|
@@ -145,7 +145,7 @@ export function filterRowOf(cond: Cond, path: FilterPath | undefined, timeZone:
|
|
|
145
145
|
return { path: cond.field, op: cond.op, value: local ? toDateTimeInput(cond.value as string, timeZone) : cond.value }
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
-
/** Plural title of an entity for headings (`
|
|
148
|
+
/** Plural title of an entity for headings (`notes` → `Notes`). */
|
|
149
149
|
export const entityTitleOf = (entity: EntityDescriptor) => labelOfKey(entity.name)
|
|
150
150
|
|
|
151
151
|
/** The own to-one relation whose foreign key is `field`, if any. */
|
|
@@ -184,7 +184,7 @@ function jsonTypeOf(field: FieldDescriptor): JsonSchema {
|
|
|
184
184
|
* the writable ones, the rest has no value yet),
|
|
185
185
|
* nullable where the column is, read-only where the form may not write,
|
|
186
186
|
* required where it has neither a default nor `null`. Foreign keys are titled
|
|
187
|
-
* after their relation (`
|
|
187
|
+
* after their relation (`Folder`, not `Folder id`).
|
|
188
188
|
*/
|
|
189
189
|
export function rowSchemaOf(entity: EntityDescriptor, mode: FormMode): JsonSchema {
|
|
190
190
|
const properties: Record<string, JsonSchema> = {}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skaile/forge-layer-data-browser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Nuxt layer for apps built on forge-template-app: the owner's view of every entity data.describe exposes (/data), with a filterable table, a filter builder and a generic row form.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./nuxt.config.ts",
|