@abgov/nx-adsp 13.18.0-beta.3 → 13.18.0-beta.4
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/generators.json +5 -0
- package/package.json +1 -1
- package/src/generators/vue-components/files/AGENTS.md__tmpl__ +2 -2
- package/src/generators/vue-components/files/src/index.ts__tmpl__ +1 -0
- package/src/generators/vue-components/files/src/lib/patterns/RecordDetailShell.vue__tmpl__ +75 -0
- package/src/generators/vue-components/files/src/vue-components.spec.ts__tmpl__ +1 -0
- package/src/generators/vue-components/vue-components.spec.ts +1 -0
- package/src/generators/vue-detail-view/files/src/views/__viewFileName__.vue__tmpl__ +91 -0
- package/src/generators/vue-detail-view/schema.d.ts +29 -0
- package/src/generators/vue-detail-view/schema.json +50 -0
- package/src/generators/vue-detail-view/vue-detail-view.d.ts +3 -0
- package/src/generators/vue-detail-view/vue-detail-view.js +50 -0
- package/src/generators/vue-detail-view/vue-detail-view.js.map +1 -0
- package/src/generators/vue-detail-view/vue-detail-view.spec.ts +156 -0
- package/src/utils/vue-router.d.ts +8 -0
- package/src/utils/vue-router.js +32 -0
- package/src/utils/vue-router.js.map +1 -0
- package/src/utils/vue-router.spec.ts +71 -0
package/generators.json
CHANGED
|
@@ -60,6 +60,11 @@
|
|
|
60
60
|
"description": "Ensures the shared GoA Vue wrapper library (interim). Invoked by vue-app; runnable directly to repair.",
|
|
61
61
|
"hidden": true
|
|
62
62
|
},
|
|
63
|
+
"vue-detail-view": {
|
|
64
|
+
"factory": "./src/generators/vue-detail-view/vue-detail-view",
|
|
65
|
+
"schema": "./src/generators/vue-detail-view/schema.json",
|
|
66
|
+
"description": "Generator that adds a record-detail view (RecordDetailShell + a --fields spec) to an existing vue-app project."
|
|
67
|
+
},
|
|
63
68
|
"mean": {
|
|
64
69
|
"factory": "./src/generators/mean/mean",
|
|
65
70
|
"schema": "./src/generators/mean/schema.json",
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@ app in this workspace imports both instead of carrying its own copy. Generated b
|
|
|
7
7
|
| Folder | Contains | Lifespan |
|
|
8
8
|
|---|---|---|
|
|
9
9
|
| `src/lib/primitives/` | Thin `v-model`/idiomatic-event wrappers over individual `goa-*` elements (`GoabInput`, `GoabButton`, …) | **Interim** — see below |
|
|
10
|
-
| `src/lib/patterns/` | Composite, app-shell components (`AppLayout`, `AppHeader`, `AppFooter`, `AppSideMenu`, `SessionExpiredBanner`) | **Permanent** |
|
|
10
|
+
| `src/lib/patterns/` | Composite, app-shell components (`AppLayout`, `AppHeader`, `AppFooter`, `AppSideMenu`, `SessionExpiredBanner`, `RecordDetailShell`) | **Permanent** |
|
|
11
11
|
|
|
12
12
|
> **⚠️ `primitives/` is interim — do not invest in it as permanent.** It exists
|
|
13
13
|
> only because GoA DS has not yet published an official Vue wrapper package. When
|
|
@@ -142,7 +142,7 @@ detail); just leave it to fall through from the caller.
|
|
|
142
142
|
|
|
143
143
|
A pattern component is app-shell composition — layout, header/footer chrome,
|
|
144
144
|
banners — not a single-element wrapper. Existing examples: `AppLayout`,
|
|
145
|
-
`AppHeader`, `AppFooter`, `AppSideMenu`, `SessionExpiredBanner`.
|
|
145
|
+
`AppHeader`, `AppFooter`, `AppSideMenu`, `SessionExpiredBanner`, `RecordDetailShell`.
|
|
146
146
|
|
|
147
147
|
- It's fine to compose `primitives/` wrappers inside a pattern component (e.g.
|
|
148
148
|
`SessionExpiredBanner` uses `GoabButton`) — import them with a relative path
|
|
@@ -22,3 +22,4 @@ export { default as AppHeader } from './lib/patterns/AppHeader.vue';
|
|
|
22
22
|
export { default as AppFooter } from './lib/patterns/AppFooter.vue';
|
|
23
23
|
export { default as AppSideMenu } from './lib/patterns/AppSideMenu.vue';
|
|
24
24
|
export { default as SessionExpiredBanner } from './lib/patterns/SessionExpiredBanner.vue';
|
|
25
|
+
export { default as RecordDetailShell } from './lib/patterns/RecordDetailShell.vue';
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Chrome for a single-record detail page: heading + optional back button and
|
|
3
|
+
// status badge, loading/error states. NOT the field list or action bar --
|
|
4
|
+
// those vary too much between real detail pages (confirmed across multiple
|
|
5
|
+
// independent GovAlta apps) to genericize; the default slot renders whatever
|
|
6
|
+
// the consuming view needs once the record has loaded.
|
|
7
|
+
import GoabButton from '../primitives/GoabButton.vue';
|
|
8
|
+
|
|
9
|
+
withDefaults(
|
|
10
|
+
defineProps<{
|
|
11
|
+
heading: string;
|
|
12
|
+
loading?: boolean;
|
|
13
|
+
error?: string | null;
|
|
14
|
+
backLabel?: string;
|
|
15
|
+
statusBadge?: {
|
|
16
|
+
type: 'success' | 'emergency' | 'information' | 'important' | 'midtone';
|
|
17
|
+
content: string;
|
|
18
|
+
};
|
|
19
|
+
}>(),
|
|
20
|
+
{
|
|
21
|
+
loading: false,
|
|
22
|
+
error: null,
|
|
23
|
+
},
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const emit = defineEmits<{ back: []; retry: [] }>();
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<template>
|
|
30
|
+
<div class="record-detail-shell">
|
|
31
|
+
<div class="record-detail-shell-header">
|
|
32
|
+
<h1>{{ heading }}</h1>
|
|
33
|
+
<div class="record-detail-shell-header-actions">
|
|
34
|
+
<goa-badge v-if="statusBadge" :type="statusBadge.type" :content="statusBadge.content" />
|
|
35
|
+
<GoabButton v-if="backLabel" type="tertiary" leadingicon="arrow-back" @click="emit('back')">
|
|
36
|
+
{{ backLabel }}
|
|
37
|
+
</GoabButton>
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
|
|
41
|
+
<div v-if="loading" aria-label="Loading">
|
|
42
|
+
<goa-skeleton type="text" size="4" />
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
<goa-callout v-else-if="error" type="emergency" heading="Unable to load">
|
|
46
|
+
<p>{{ error }}</p>
|
|
47
|
+
<goa-spacer vspacing="s" />
|
|
48
|
+
<GoabButton type="tertiary" @click="emit('retry')">Retry</GoabButton>
|
|
49
|
+
</goa-callout>
|
|
50
|
+
|
|
51
|
+
<template v-else>
|
|
52
|
+
<slot />
|
|
53
|
+
</template>
|
|
54
|
+
</div>
|
|
55
|
+
</template>
|
|
56
|
+
|
|
57
|
+
<style scoped>
|
|
58
|
+
.record-detail-shell-header {
|
|
59
|
+
display: flex;
|
|
60
|
+
justify-content: space-between;
|
|
61
|
+
align-items: center;
|
|
62
|
+
gap: var(--goa-space-m);
|
|
63
|
+
margin-bottom: var(--goa-space-m);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.record-detail-shell-header h1 {
|
|
67
|
+
margin: 0;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.record-detail-shell-header-actions {
|
|
71
|
+
display: flex;
|
|
72
|
+
align-items: center;
|
|
73
|
+
gap: var(--goa-space-m);
|
|
74
|
+
}
|
|
75
|
+
</style>
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, onMounted } from 'vue';
|
|
3
|
+
import { useRoute, useRouter } from 'vue-router';
|
|
4
|
+
import { RecordDetailShell } from '<%= goaImportPath %>';
|
|
5
|
+
|
|
6
|
+
// The fetched record's shape isn't known to this generator -- read fields
|
|
7
|
+
// defensively rather than declaring (and likely getting wrong) a fake interface.
|
|
8
|
+
const record = ref<Record<string, unknown> | null>(null);
|
|
9
|
+
const loading = ref(true);
|
|
10
|
+
const error = ref<string | null>(null);
|
|
11
|
+
|
|
12
|
+
const route = useRoute();
|
|
13
|
+
const router = useRouter();
|
|
14
|
+
|
|
15
|
+
async function load() {
|
|
16
|
+
loading.value = true;
|
|
17
|
+
error.value = null;
|
|
18
|
+
try {
|
|
19
|
+
const res = await fetch(`/api/<%= resource %>/${route.params.id}`);
|
|
20
|
+
if (!res.ok) throw new Error(`Failed to load (${res.status})`);
|
|
21
|
+
record.value = await res.json();
|
|
22
|
+
} catch (e) {
|
|
23
|
+
error.value = e instanceof Error ? e.message : 'Failed to load.';
|
|
24
|
+
} finally {
|
|
25
|
+
loading.value = false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
onMounted(load);
|
|
30
|
+
|
|
31
|
+
function goBack() {
|
|
32
|
+
router.back();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function formatDate(value: unknown): string {
|
|
36
|
+
if (!value) return '—';
|
|
37
|
+
try {
|
|
38
|
+
return new Date(String(value)).toLocaleString('en-CA');
|
|
39
|
+
} catch {
|
|
40
|
+
return String(value);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function formatCurrency(value: unknown): string {
|
|
45
|
+
if (value === undefined || value === null || value === '') return '—';
|
|
46
|
+
const n = Number(value);
|
|
47
|
+
if (Number.isNaN(n)) return String(value);
|
|
48
|
+
return new Intl.NumberFormat('en-CA', { style: 'currency', currency: 'CAD' }).format(n);
|
|
49
|
+
}
|
|
50
|
+
</script>
|
|
51
|
+
|
|
52
|
+
<template>
|
|
53
|
+
<RecordDetailShell
|
|
54
|
+
heading="<%= heading %>"
|
|
55
|
+
:loading="loading"
|
|
56
|
+
:error="error"
|
|
57
|
+
back-label="Back"
|
|
58
|
+
@back="goBack"
|
|
59
|
+
@retry="load"
|
|
60
|
+
>
|
|
61
|
+
<dl v-if="record" class="detail-fields">
|
|
62
|
+
<% fields.forEach(function (field) { -%>
|
|
63
|
+
<dt><%= field.label %></dt>
|
|
64
|
+
<dd>
|
|
65
|
+
<% if (field.type === 'badge') { -%>
|
|
66
|
+
<goa-badge type="information" :content="String(record['<%= field.key %>'] ?? '—')" />
|
|
67
|
+
<% } else if (field.type === 'date') { -%>
|
|
68
|
+
{{ formatDate(record['<%= field.key %>']) }}
|
|
69
|
+
<% } else if (field.type === 'currency') { -%>
|
|
70
|
+
{{ formatCurrency(record['<%= field.key %>']) }}
|
|
71
|
+
<% } else { -%>
|
|
72
|
+
{{ record['<%= field.key %>'] ?? '—' }}
|
|
73
|
+
<% } -%>
|
|
74
|
+
</dd>
|
|
75
|
+
<% }); -%>
|
|
76
|
+
</dl>
|
|
77
|
+
</RecordDetailShell>
|
|
78
|
+
</template>
|
|
79
|
+
|
|
80
|
+
<style scoped>
|
|
81
|
+
.detail-fields {
|
|
82
|
+
display: grid;
|
|
83
|
+
grid-template-columns: auto 1fr;
|
|
84
|
+
gap: var(--goa-space-xs) var(--goa-space-l);
|
|
85
|
+
margin: 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.detail-fields dt {
|
|
89
|
+
font-weight: 600;
|
|
90
|
+
}
|
|
91
|
+
</style>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export interface DetailViewField {
|
|
2
|
+
key: string;
|
|
3
|
+
label: string;
|
|
4
|
+
type?: 'text' | 'date' | 'currency' | 'badge';
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface Schema {
|
|
8
|
+
project: string;
|
|
9
|
+
name: string;
|
|
10
|
+
resource: string;
|
|
11
|
+
route: string;
|
|
12
|
+
/**
|
|
13
|
+
* JSON string on the real CLI (Nx's array-typed CLI coercion only supports
|
|
14
|
+
* comma-separated primitives, not JSON -- see schema.json). A real array is
|
|
15
|
+
* also accepted for programmatic callers (e.g. tests).
|
|
16
|
+
*/
|
|
17
|
+
fields: string | DetailViewField[];
|
|
18
|
+
heading?: string;
|
|
19
|
+
requiresAuth?: boolean;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface NormalizedSchema extends Omit<Schema, 'fields'> {
|
|
23
|
+
projectRoot: string;
|
|
24
|
+
/** PascalCase view name with a "View" suffix, e.g. ApplicationDetailView. */
|
|
25
|
+
viewFileName: string;
|
|
26
|
+
fields: DetailViewField[];
|
|
27
|
+
heading: string;
|
|
28
|
+
requiresAuth: boolean;
|
|
29
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/schema",
|
|
3
|
+
"id": "NxAdspVueDetailView",
|
|
4
|
+
"title": "Vue Record Detail View",
|
|
5
|
+
"description": "Generates a record-detail view (loading/error/loaded states, optional status badge, back button) into an existing vue-app project, built on the shared RecordDetailShell pattern component.",
|
|
6
|
+
"type": "object",
|
|
7
|
+
"properties": {
|
|
8
|
+
"project": {
|
|
9
|
+
"type": "string",
|
|
10
|
+
"description": "The vue-app project to add the view to.",
|
|
11
|
+
"$default": {
|
|
12
|
+
"$source": "argv",
|
|
13
|
+
"index": 0
|
|
14
|
+
},
|
|
15
|
+
"x-prompt": "Which project should the detail view be added to?"
|
|
16
|
+
},
|
|
17
|
+
"name": {
|
|
18
|
+
"type": "string",
|
|
19
|
+
"description": "View name, e.g. 'application-detail' generates src/views/ApplicationDetailView.vue.",
|
|
20
|
+
"$default": {
|
|
21
|
+
"$source": "argv",
|
|
22
|
+
"index": 1
|
|
23
|
+
},
|
|
24
|
+
"x-prompt": "What should the view be called?"
|
|
25
|
+
},
|
|
26
|
+
"resource": {
|
|
27
|
+
"type": "string",
|
|
28
|
+
"description": "API resource path segment -- the view fetches /api/<resource>/:id."
|
|
29
|
+
},
|
|
30
|
+
"route": {
|
|
31
|
+
"type": "string",
|
|
32
|
+
"description": "Route path added to router/index.ts, e.g. /applications/:id. Must contain a :id param."
|
|
33
|
+
},
|
|
34
|
+
"fields": {
|
|
35
|
+
"type": "string",
|
|
36
|
+
"description": "JSON array of fields rendered in the record's info list, in display order -- e.g. '[{\"key\":\"status\",\"label\":\"Status\",\"type\":\"badge\"}]'. Each item: { key, label, type?: \"text\"|\"date\"|\"currency\"|\"badge\" (default \"text\") }. A plain array is also accepted when this generator is invoked programmatically. Nx's CLI option coercion only supports comma-separated primitive lists for array-typed schema properties, not JSON -- a JSON string is the only CLI syntax that actually survives Nx's own arg parsing for a structured list like this."
|
|
37
|
+
},
|
|
38
|
+
"heading": {
|
|
39
|
+
"type": "string",
|
|
40
|
+
"description": "Page heading. Defaults to the view name, title-cased."
|
|
41
|
+
},
|
|
42
|
+
"requiresAuth": {
|
|
43
|
+
"type": "boolean",
|
|
44
|
+
"description": "Whether the generated route requires authentication.",
|
|
45
|
+
"default": true
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"required": ["project", "name", "resource", "route", "fields"],
|
|
49
|
+
"additionalProperties": false
|
|
50
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = default_1;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
|
+
const path = require("path");
|
|
7
|
+
const vue_router_1 = require("../../utils/vue-router");
|
|
8
|
+
const vue_components_1 = require("../vue-components/vue-components");
|
|
9
|
+
// Nx's own CLI option coercion (coerceTypesInOptions in nx/src/utils/params)
|
|
10
|
+
// only knows how to split an array-typed option on commas -- it has no JSON
|
|
11
|
+
// support, so a real `"type": "array"` schema for --fields silently mangles
|
|
12
|
+
// a JSON array into garbage fragments when invoked from the actual CLI (only
|
|
13
|
+
// programmatic callers, like this generator's own unit tests, ever pass a
|
|
14
|
+
// real array). --fields is `"type": "string"` in schema.json specifically so
|
|
15
|
+
// Nx leaves it alone, and this generator parses the JSON itself.
|
|
16
|
+
function parseFields(fields) {
|
|
17
|
+
const parsed = typeof fields === 'string' ? JSON.parse(fields) : fields;
|
|
18
|
+
if (!Array.isArray(parsed) || parsed.length === 0) {
|
|
19
|
+
throw new Error('--fields must be a non-empty JSON array of { key, label, type? } objects.');
|
|
20
|
+
}
|
|
21
|
+
return parsed;
|
|
22
|
+
}
|
|
23
|
+
function normalizeOptions(host, options) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
const { root: projectRoot } = (0, devkit_1.readProjectConfiguration)(host, options.project);
|
|
26
|
+
if (!options.route.includes(':id')) {
|
|
27
|
+
throw new Error(`--route "${options.route}" has no :id param -- the generated view reads route.params.id to fetch the record.`);
|
|
28
|
+
}
|
|
29
|
+
const className = (0, devkit_1.names)(options.name).className;
|
|
30
|
+
return Object.assign(Object.assign({}, options), { projectRoot, fields: parseFields(options.fields), viewFileName: `${className}View`,
|
|
31
|
+
// className is PascalCase (e.g. "ApplicationDetail") -- space it out for a
|
|
32
|
+
// readable default heading ("Application Detail").
|
|
33
|
+
heading: (_a = options.heading) !== null && _a !== void 0 ? _a : className.replace(/([A-Z])/g, ' $1').trim(), requiresAuth: (_b = options.requiresAuth) !== null && _b !== void 0 ? _b : true });
|
|
34
|
+
}
|
|
35
|
+
function default_1(host, options) {
|
|
36
|
+
return tslib_1.__awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const normalizedOptions = normalizeOptions(host, options);
|
|
38
|
+
// Idempotent -- ensures RecordDetailShell exists even in a project scaffolded
|
|
39
|
+
// before vue-components carried it.
|
|
40
|
+
yield (0, vue_components_1.default)(host);
|
|
41
|
+
(0, devkit_1.generateFiles)(host, path.join(__dirname, 'files'), normalizedOptions.projectRoot, Object.assign(Object.assign({}, normalizedOptions), { goaImportPath: (0, vue_components_1.vueComponentsImportPath)(host), tmpl: '' }));
|
|
42
|
+
(0, vue_router_1.insertVueRoute)(host, normalizedOptions.projectRoot, normalizedOptions.project, {
|
|
43
|
+
path: normalizedOptions.route,
|
|
44
|
+
componentImportPath: `../views/${normalizedOptions.viewFileName}.vue`,
|
|
45
|
+
requiresAuth: normalizedOptions.requiresAuth,
|
|
46
|
+
});
|
|
47
|
+
yield (0, devkit_1.formatFiles)(host);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=vue-detail-view.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue-detail-view.js","sourceRoot":"","sources":["../../../../../../packages/nx-adsp/src/generators/vue-detail-view/vue-detail-view.ts"],"names":[],"mappings":";;AAqDA,4BAyBC;;AA9ED,uCAMoB;AACpB,6BAA6B;AAC7B,uDAAwD;AACxD,qEAE0C;AAG1C,6EAA6E;AAC7E,4EAA4E;AAC5E,4EAA4E;AAC5E,6EAA6E;AAC7E,0EAA0E;AAC1E,6EAA6E;AAC7E,iEAAiE;AACjE,SAAS,WAAW,CAAC,MAAwB;IAC3C,MAAM,MAAM,GAAG,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC;IACxE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAClD,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAU,EAAE,OAAe;;IACnD,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,IAAA,iCAAwB,EAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IAE9E,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CACb,YAAY,OAAO,CAAC,KAAK,qFAAqF,CAC/G,CAAC;IACJ,CAAC;IAED,MAAM,SAAS,GAAG,IAAA,cAAK,EAAC,OAAO,CAAC,IAAI,CAAC,CAAC,SAAS,CAAC;IAChD,uCACK,OAAO,KACV,WAAW,EACX,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,EACnC,YAAY,EAAE,GAAG,SAAS,MAAM;QAChC,2EAA2E;QAC3E,mDAAmD;QACnD,OAAO,EAAE,MAAA,OAAO,CAAC,OAAO,mCAAI,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,IAAI,EAAE,EACvE,YAAY,EAAE,MAAA,OAAO,CAAC,YAAY,mCAAI,IAAI,IAC1C;AACJ,CAAC;AAED,mBAA+B,IAAU,EAAE,OAAe;;QACxD,MAAM,iBAAiB,GAAG,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAE1D,8EAA8E;QAC9E,oCAAoC;QACpC,MAAM,IAAA,wBAAsB,EAAC,IAAI,CAAC,CAAC;QAEnC,IAAA,sBAAa,EACX,IAAI,EACJ,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,EAC7B,iBAAiB,CAAC,WAAW,kCAExB,iBAAiB,KACpB,aAAa,EAAE,IAAA,wCAAuB,EAAC,IAAI,CAAC,EAC5C,IAAI,EAAE,EAAE,IAEX,CAAC;QAEF,IAAA,2BAAc,EAAC,IAAI,EAAE,iBAAiB,CAAC,WAAW,EAAE,iBAAiB,CAAC,OAAO,EAAE;YAC7E,IAAI,EAAE,iBAAiB,CAAC,KAAK;YAC7B,mBAAmB,EAAE,YAAY,iBAAiB,CAAC,YAAY,MAAM;YACrE,YAAY,EAAE,iBAAiB,CAAC,YAAY;SAC7C,CAAC,CAAC;QAEH,MAAM,IAAA,oBAAW,EAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;CAAA"}
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addProjectConfiguration,
|
|
3
|
+
readProjectConfiguration,
|
|
4
|
+
Tree,
|
|
5
|
+
} from '@nx/devkit';
|
|
6
|
+
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
|
7
|
+
import generator from './vue-detail-view';
|
|
8
|
+
import { Schema } from './schema';
|
|
9
|
+
|
|
10
|
+
// Mirrors the shape vue-app's own template generates -- vue-detail-view retrofits
|
|
11
|
+
// into this file, so the fixture must match what it actually looks for.
|
|
12
|
+
const ROUTER_FIXTURE = `import { createRouter, createWebHistory } from 'vue-router';
|
|
13
|
+
import HomeView from '../views/HomeView.vue';
|
|
14
|
+
|
|
15
|
+
const router = createRouter({
|
|
16
|
+
history: createWebHistory(import.meta.env.BASE_URL),
|
|
17
|
+
routes: [
|
|
18
|
+
{ path: '/', component: HomeView },
|
|
19
|
+
],
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export default router;
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
describe('Vue Detail View Generator', () => {
|
|
26
|
+
let host: Tree;
|
|
27
|
+
const baseOptions: Schema = {
|
|
28
|
+
project: 'test',
|
|
29
|
+
name: 'application-detail',
|
|
30
|
+
resource: 'applications',
|
|
31
|
+
route: '/applications/:id',
|
|
32
|
+
fields: [
|
|
33
|
+
{ key: 'status', label: 'Status', type: 'badge' },
|
|
34
|
+
{ key: 'lastSaved', label: 'Last saved', type: 'date' },
|
|
35
|
+
{ key: 'requestTotal', label: 'Request total', type: 'currency' },
|
|
36
|
+
{ key: 'serviceModel', label: 'Service Model' },
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
host = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
|
|
42
|
+
addProjectConfiguration(host, 'test', { root: 'apps/test' });
|
|
43
|
+
host.write('apps/test/src/router/index.ts', ROUTER_FIXTURE);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('throws when --project does not exist', async () => {
|
|
47
|
+
await expect(
|
|
48
|
+
generator(host, { ...baseOptions, project: 'no-such-app' }),
|
|
49
|
+
).rejects.toThrow();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('throws when --route has no :id param', async () => {
|
|
53
|
+
await expect(
|
|
54
|
+
generator(host, { ...baseOptions, route: '/applications' }),
|
|
55
|
+
).rejects.toThrow(/:id/);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("throws a clear error when the project isn't a vue-app (no router/index.ts)", async () => {
|
|
59
|
+
addProjectConfiguration(host, 'not-vue', { root: 'apps/not-vue' });
|
|
60
|
+
await expect(
|
|
61
|
+
generator(host, { ...baseOptions, project: 'not-vue' }),
|
|
62
|
+
).rejects.toThrow(/router\/index\.ts/);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Regression guard: Nx's own CLI option coercion for `"type": "array"` splits
|
|
66
|
+
// on commas, not JSON -- --fields is `"type": "string"` in schema.json
|
|
67
|
+
// specifically so the real CLI's JSON string survives unmangled. Assert the
|
|
68
|
+
// string form the CLI actually produces, not just the array form direct
|
|
69
|
+
// (unit-test) callers use.
|
|
70
|
+
it('accepts --fields as a JSON string, the form the real CLI produces', async () => {
|
|
71
|
+
await generator(host, {
|
|
72
|
+
...baseOptions,
|
|
73
|
+
fields: JSON.stringify(baseOptions.fields),
|
|
74
|
+
});
|
|
75
|
+
const view = host
|
|
76
|
+
.read('apps/test/src/views/ApplicationDetailView.vue')
|
|
77
|
+
.toString();
|
|
78
|
+
expect(view).toContain('<dt>Status</dt>');
|
|
79
|
+
}, 30000);
|
|
80
|
+
|
|
81
|
+
it('throws a clear error when --fields is not valid JSON', async () => {
|
|
82
|
+
await expect(
|
|
83
|
+
generator(host, { ...baseOptions, fields: '{not json' }),
|
|
84
|
+
).rejects.toThrow();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('throws a clear error when --fields parses to an empty array', async () => {
|
|
88
|
+
await expect(
|
|
89
|
+
generator(host, { ...baseOptions, fields: '[]' }),
|
|
90
|
+
).rejects.toThrow(/non-empty/);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('generates the view with each field type rendered correctly', async () => {
|
|
94
|
+
await generator(host, baseOptions);
|
|
95
|
+
|
|
96
|
+
const view = host
|
|
97
|
+
.read('apps/test/src/views/ApplicationDetailView.vue')
|
|
98
|
+
.toString();
|
|
99
|
+
expect(view).toContain('heading="Application Detail"');
|
|
100
|
+
expect(view).toContain("fetch(`/api/applications/${route.params.id}`)");
|
|
101
|
+
expect(view).toContain(
|
|
102
|
+
"<goa-badge type=\"information\" :content=\"String(record['status'] ?? '—')\" />",
|
|
103
|
+
);
|
|
104
|
+
expect(view).toContain("formatDate(record['lastSaved'])");
|
|
105
|
+
expect(view).toContain("formatCurrency(record['requestTotal'])");
|
|
106
|
+
expect(view).toContain("record['serviceModel'] ?? '—'");
|
|
107
|
+
expect(view).toContain('<dt>Status</dt>');
|
|
108
|
+
expect(view).toContain('<dt>Service Model</dt>');
|
|
109
|
+
// Uses the shared shell, not hand-rolled loading/error markup.
|
|
110
|
+
expect(view).toContain("import { RecordDetailShell } from '@proj/vue-components';");
|
|
111
|
+
expect(view).toContain('<RecordDetailShell');
|
|
112
|
+
}, 30000);
|
|
113
|
+
|
|
114
|
+
it('respects an explicit --heading', async () => {
|
|
115
|
+
await generator(host, { ...baseOptions, heading: 'Grant Application' });
|
|
116
|
+
const view = host
|
|
117
|
+
.read('apps/test/src/views/ApplicationDetailView.vue')
|
|
118
|
+
.toString();
|
|
119
|
+
expect(view).toContain('heading="Grant Application"');
|
|
120
|
+
}, 30000);
|
|
121
|
+
|
|
122
|
+
it('inserts the route into router/index.ts, requiring auth by default', async () => {
|
|
123
|
+
await generator(host, baseOptions);
|
|
124
|
+
|
|
125
|
+
const routerTs = host.read('apps/test/src/router/index.ts').toString();
|
|
126
|
+
expect(routerTs).toContain("path: '/applications/:id'");
|
|
127
|
+
expect(routerTs).toContain(
|
|
128
|
+
"component: () => import('../views/ApplicationDetailView.vue')",
|
|
129
|
+
);
|
|
130
|
+
expect(routerTs).toContain('meta: { requiresAuth: true }');
|
|
131
|
+
// The existing route is untouched, not replaced.
|
|
132
|
+
expect(routerTs).toContain("{ path: '/', component: HomeView }");
|
|
133
|
+
}, 30000);
|
|
134
|
+
|
|
135
|
+
it('omits the requiresAuth meta when --requiresAuth=false', async () => {
|
|
136
|
+
await generator(host, { ...baseOptions, requiresAuth: false });
|
|
137
|
+
const routerTs = host.read('apps/test/src/router/index.ts').toString();
|
|
138
|
+
expect(routerTs).not.toContain('requiresAuth');
|
|
139
|
+
}, 30000);
|
|
140
|
+
|
|
141
|
+
it('ensures the shared RecordDetailShell pattern component exists', async () => {
|
|
142
|
+
await generator(host, baseOptions);
|
|
143
|
+
expect(
|
|
144
|
+
host.exists(
|
|
145
|
+
'libs/vue-components/src/lib/patterns/RecordDetailShell.vue',
|
|
146
|
+
),
|
|
147
|
+
).toBeTruthy();
|
|
148
|
+
}, 30000);
|
|
149
|
+
|
|
150
|
+
it('does not touch the target project configuration', async () => {
|
|
151
|
+
const before = readProjectConfiguration(host, 'test');
|
|
152
|
+
await generator(host, baseOptions);
|
|
153
|
+
const after = readProjectConfiguration(host, 'test');
|
|
154
|
+
expect(after).toEqual(before);
|
|
155
|
+
}, 30000);
|
|
156
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
export interface VueRouteSpec {
|
|
3
|
+
path: string;
|
|
4
|
+
/** Relative import path passed to () => import(...), e.g. '../views/FooView.vue'. */
|
|
5
|
+
componentImportPath: string;
|
|
6
|
+
requiresAuth?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function insertVueRoute(host: Tree, projectRoot: string, project: string, route: VueRouteSpec): void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.insertVueRoute = insertVueRoute;
|
|
4
|
+
// Deterministic text insertion, not an AST edit -- vue-app's router/index.ts
|
|
5
|
+
// template has a fixed `routes: [ ... ]` shape, so a targeted anchor is
|
|
6
|
+
// simpler and safer here than pulling in an AST library for one array entry.
|
|
7
|
+
function insertVueRoute(host, projectRoot, project, route) {
|
|
8
|
+
var _a;
|
|
9
|
+
const routerPath = `${projectRoot}/src/router/index.ts`;
|
|
10
|
+
const content = (_a = host.read(routerPath)) === null || _a === void 0 ? void 0 : _a.toString();
|
|
11
|
+
if (content === undefined) {
|
|
12
|
+
throw new Error(`Could not find ${routerPath} -- is "${project}" a vue-app project generated by @abgov/nx-adsp:vue-app?`);
|
|
13
|
+
}
|
|
14
|
+
const marker = 'routes: [';
|
|
15
|
+
const markerIndex = content.indexOf(marker);
|
|
16
|
+
if (markerIndex === -1) {
|
|
17
|
+
throw new Error(`Could not find "${marker}" in ${routerPath} -- has its shape changed since @abgov/nx-adsp:vue-app generated it?`);
|
|
18
|
+
}
|
|
19
|
+
const metaLine = route.requiresAuth
|
|
20
|
+
? `\n meta: { requiresAuth: true },`
|
|
21
|
+
: '';
|
|
22
|
+
const routeSnippet = `{\n` +
|
|
23
|
+
` path: '${route.path}',\n` +
|
|
24
|
+
` component: () => import('${route.componentImportPath}'),${metaLine}\n` +
|
|
25
|
+
` },`;
|
|
26
|
+
const insertAt = markerIndex + marker.length;
|
|
27
|
+
const updated = content.slice(0, insertAt) +
|
|
28
|
+
`\n ${routeSnippet}` +
|
|
29
|
+
content.slice(insertAt);
|
|
30
|
+
host.write(routerPath, updated);
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=vue-router.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vue-router.js","sourceRoot":"","sources":["../../../../../packages/nx-adsp/src/utils/vue-router.ts"],"names":[],"mappings":";;AAYA,wCAqCC;AAxCD,6EAA6E;AAC7E,wEAAwE;AACxE,6EAA6E;AAC7E,SAAgB,cAAc,CAC5B,IAAU,EACV,WAAmB,EACnB,OAAe,EACf,KAAmB;;IAEnB,MAAM,UAAU,GAAG,GAAG,WAAW,sBAAsB,CAAC;IACxD,MAAM,OAAO,GAAG,MAAA,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,0CAAE,QAAQ,EAAE,CAAC;IAClD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,kBAAkB,UAAU,WAAW,OAAO,0DAA0D,CACzG,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,WAAW,CAAC;IAC3B,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC5C,IAAI,WAAW,KAAK,CAAC,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CACb,mBAAmB,MAAM,QAAQ,UAAU,sEAAsE,CAClH,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,KAAK,CAAC,YAAY;QACjC,CAAC,CAAC,uCAAuC;QACzC,CAAC,CAAC,EAAE,CAAC;IACP,MAAM,YAAY,GAChB,KAAK;QACL,gBAAgB,KAAK,CAAC,IAAI,MAAM;QAChC,kCAAkC,KAAK,CAAC,mBAAmB,MAAM,QAAQ,IAAI;QAC7E,QAAQ,CAAC;IAEX,MAAM,QAAQ,GAAG,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7C,MAAM,OAAO,GACX,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC;QAC1B,SAAS,YAAY,EAAE;QACvB,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IAC1B,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Tree } from '@nx/devkit';
|
|
2
|
+
import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
|
|
3
|
+
import { insertVueRoute } from './vue-router';
|
|
4
|
+
|
|
5
|
+
const ROUTER_FIXTURE = `import { createRouter, createWebHistory } from 'vue-router';
|
|
6
|
+
import HomeView from '../views/HomeView.vue';
|
|
7
|
+
|
|
8
|
+
const router = createRouter({
|
|
9
|
+
history: createWebHistory(import.meta.env.BASE_URL),
|
|
10
|
+
routes: [
|
|
11
|
+
{ path: '/', component: HomeView },
|
|
12
|
+
],
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
export default router;
|
|
16
|
+
`;
|
|
17
|
+
|
|
18
|
+
describe('insertVueRoute', () => {
|
|
19
|
+
let host: Tree;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
host = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
|
|
23
|
+
host.write('apps/test/src/router/index.ts', ROUTER_FIXTURE);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('inserts a new route ahead of the existing ones, with a requiresAuth meta', () => {
|
|
27
|
+
insertVueRoute(host, 'apps/test', 'test', {
|
|
28
|
+
path: '/things/:id',
|
|
29
|
+
componentImportPath: '../views/ThingView.vue',
|
|
30
|
+
requiresAuth: true,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const routerTs = host.read('apps/test/src/router/index.ts').toString();
|
|
34
|
+
expect(routerTs).toContain("path: '/things/:id'");
|
|
35
|
+
expect(routerTs).toContain(
|
|
36
|
+
"component: () => import('../views/ThingView.vue')",
|
|
37
|
+
);
|
|
38
|
+
expect(routerTs).toContain('meta: { requiresAuth: true }');
|
|
39
|
+
expect(routerTs).toContain("{ path: '/', component: HomeView }");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('omits the meta line when requiresAuth is not set', () => {
|
|
43
|
+
insertVueRoute(host, 'apps/test', 'test', {
|
|
44
|
+
path: '/public-things',
|
|
45
|
+
componentImportPath: '../views/ThingsListView.vue',
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const routerTs = host.read('apps/test/src/router/index.ts').toString();
|
|
49
|
+
expect(routerTs).not.toContain('requiresAuth');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('throws a clear error when the project has no router/index.ts', () => {
|
|
53
|
+
host.write('apps/no-router/src/main.ts', '// no router here\n');
|
|
54
|
+
expect(() =>
|
|
55
|
+
insertVueRoute(host, 'apps/no-router', 'no-router', {
|
|
56
|
+
path: '/x',
|
|
57
|
+
componentImportPath: '../views/XView.vue',
|
|
58
|
+
}),
|
|
59
|
+
).toThrow(/router\/index\.ts/);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('throws when routes: [ has been renamed or removed', () => {
|
|
63
|
+
host.write('apps/test/src/router/index.ts', 'export default {};\n');
|
|
64
|
+
expect(() =>
|
|
65
|
+
insertVueRoute(host, 'apps/test', 'test', {
|
|
66
|
+
path: '/x',
|
|
67
|
+
componentImportPath: '../views/XView.vue',
|
|
68
|
+
}),
|
|
69
|
+
).toThrow(/routes: \[/);
|
|
70
|
+
});
|
|
71
|
+
});
|