@sixbell-telco/sdk-tools 0.0.0 → 0.1.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +277 -2
  3. package/data/security-floors.json +47 -0
  4. package/package.json +40 -4
  5. package/recipes/README.md +53 -0
  6. package/recipes/crud-list.md +21 -0
  7. package/recipes/custom-component.md +35 -0
  8. package/recipes/detail-page.md +19 -0
  9. package/recipes/form-dialog.md +17 -0
  10. package/recipes/parts/crud-list/i18n.json +83 -0
  11. package/recipes/parts/crud-list/src/app/features/__name__/__name__.routes.ts.tpl +30 -0
  12. package/recipes/parts/crud-list/src/app/features/__name__/pages/__name__-list/__name__-list.component.html.tpl +102 -0
  13. package/recipes/parts/crud-list/src/app/features/__name__/pages/__name__-list/__name__-list.component.spec.ts.tpl +101 -0
  14. package/recipes/parts/crud-list/src/app/features/__name__/pages/__name__-list/__name__-list.component.ts.tpl +143 -0
  15. package/recipes/parts/detail-page/i18n.json +32 -0
  16. package/recipes/parts/detail-page/src/app/features/__name__/pages/__name__-detail/__name__-detail.component.html.tpl +35 -0
  17. package/recipes/parts/detail-page/src/app/features/__name__/pages/__name__-detail/__name__-detail.component.spec.ts.tpl +58 -0
  18. package/recipes/parts/detail-page/src/app/features/__name__/pages/__name__-detail/__name__-detail.component.ts.tpl +68 -0
  19. package/recipes/parts/entity/i18n.json +5 -0
  20. package/recipes/parts/entity/src/app/features/__name__/__name__.model.ts.tpl +9 -0
  21. package/recipes/parts/entity/src/app/features/__name__/__name__.service.spec.ts.tpl +29 -0
  22. package/recipes/parts/entity/src/app/features/__name__/__name__.service.ts.tpl +33 -0
  23. package/recipes/parts/form-dialog/i18n.json +35 -0
  24. package/recipes/parts/form-dialog/src/app/features/__name__/components/__name__-form-dialog/__name__-form-dialog.component.html.tpl +33 -0
  25. package/recipes/parts/form-dialog/src/app/features/__name__/components/__name__-form-dialog/__name__-form-dialog.component.spec.ts.tpl +69 -0
  26. package/recipes/parts/form-dialog/src/app/features/__name__/components/__name__-form-dialog/__name__-form-dialog.component.ts.tpl +73 -0
  27. package/src/add/add.mjs +251 -0
  28. package/src/check/config.mjs +112 -0
  29. package/src/check/exceptions.mjs +103 -0
  30. package/src/check/federation.mjs +224 -0
  31. package/src/check/finding.mjs +23 -0
  32. package/src/check/harness.mjs +146 -0
  33. package/src/check/i18n.mjs +218 -0
  34. package/src/check/integration.mjs +566 -0
  35. package/src/check/security.mjs +165 -0
  36. package/src/check/steps.mjs +37 -0
  37. package/src/check/styles.mjs +347 -0
  38. package/src/check/wiring.mjs +198 -0
  39. package/src/check.mjs +333 -0
  40. package/src/cli.mjs +551 -0
  41. package/src/docs/docs.mjs +154 -0
  42. package/src/doctor/doctor.mjs +492 -0
  43. package/src/format.mjs +102 -0
  44. package/src/info/info.mjs +149 -0
  45. package/src/init/init.mjs +490 -0
  46. package/src/init/merge.mjs +191 -0
  47. package/src/init/template.mjs +292 -0
  48. package/src/mcp/catalog.mjs +248 -0
  49. package/src/mcp/glossary.mjs +75 -0
  50. package/src/mcp/manifest.mjs +53 -0
  51. package/src/mcp/recipes.mjs +198 -0
  52. package/src/mcp/server.mjs +249 -0
  53. package/src/mcp/upgrade-guide.mjs +116 -0
  54. package/src/mcp/usage.mjs +48 -0
  55. package/src/project/project.mjs +220 -0
  56. package/src/types.d.ts +448 -0
  57. package/src/upgrade/lockstep.mjs +153 -0
  58. package/src/upgrade/upgrade.mjs +623 -0
@@ -0,0 +1,83 @@
1
+ {
2
+ "en": {
3
+ "actions": {
4
+ "cancel": "Cancel",
5
+ "view": "View",
6
+ "edit": "Edit",
7
+ "delete": "Delete",
8
+ "clear": "Clear"
9
+ },
10
+ "list": {
11
+ "title": "Records",
12
+ "subtitle": "Search, create and edit records",
13
+ "new": "New record",
14
+ "search": "Search",
15
+ "search_placeholder": "Name or description",
16
+ "actions_column": "Actions",
17
+ "empty_title": "No records yet",
18
+ "empty_description": "Records you create appear here.",
19
+ "no_results_title": "No results",
20
+ "no_results_description": "No record matches the search.",
21
+ "clear_filters": "Clear filters"
22
+ },
23
+ "delete": {
24
+ "title": "Delete record",
25
+ "question": "This cannot be undone. Do you want to delete this record?",
26
+ "confirm": "Delete"
27
+ }
28
+ },
29
+ "es": {
30
+ "actions": {
31
+ "cancel": "Cancelar",
32
+ "view": "Ver",
33
+ "edit": "Editar",
34
+ "delete": "Eliminar",
35
+ "clear": "Limpiar"
36
+ },
37
+ "list": {
38
+ "title": "Registros",
39
+ "subtitle": "Busca, crea y edita registros",
40
+ "new": "Nuevo registro",
41
+ "search": "Buscar",
42
+ "search_placeholder": "Nombre o descripción",
43
+ "actions_column": "Acciones",
44
+ "empty_title": "Aún no hay registros",
45
+ "empty_description": "Los registros que cree aparecerán aquí.",
46
+ "no_results_title": "Sin resultados",
47
+ "no_results_description": "Ningún registro coincide con la búsqueda.",
48
+ "clear_filters": "Limpiar filtros"
49
+ },
50
+ "delete": {
51
+ "title": "Eliminar registro",
52
+ "question": "Esta acción no se puede deshacer. ¿Desea eliminar este registro?",
53
+ "confirm": "Eliminar"
54
+ }
55
+ },
56
+ "pt": {
57
+ "actions": {
58
+ "cancel": "Cancelar",
59
+ "view": "Ver",
60
+ "edit": "Editar",
61
+ "delete": "Excluir",
62
+ "clear": "Limpar"
63
+ },
64
+ "list": {
65
+ "title": "Registros",
66
+ "subtitle": "Pesquise, crie e edite registros",
67
+ "new": "Novo registro",
68
+ "search": "Pesquisar",
69
+ "search_placeholder": "Nome ou descrição",
70
+ "actions_column": "Ações",
71
+ "empty_title": "Ainda não há registros",
72
+ "empty_description": "Os registros que você criar aparecerão aqui.",
73
+ "no_results_title": "Nenhum resultado",
74
+ "no_results_description": "Nenhum registro corresponde à pesquisa.",
75
+ "clear_filters": "Limpar filtros"
76
+ },
77
+ "delete": {
78
+ "title": "Excluir registro",
79
+ "question": "Esta ação não pode ser desfeita. Deseja excluir este registro?",
80
+ "confirm": "Excluir"
81
+ }
82
+ }
83
+ }
@@ -0,0 +1,30 @@
1
+ import { Routes } from '@angular/router';
2
+ import { configurationGuard } from '@core/guards/configuration/configuration.guard';
3
+ import { __Name__DetailComponent } from './pages/__name__-detail/__name__-detail.component';
4
+ import { __Name__ListComponent } from './pages/__name__-list/__name__-list.component';
5
+
6
+ /** The __name__ feature: spread into the app's feature routes (`children: [...__NAME___ROUTES]`). */
7
+ export const __NAME___ROUTES: Routes = [
8
+ {
9
+ path: '__name__',
10
+ component: __Name__ListComponent,
11
+ canActivate: [configurationGuard],
12
+ title: '__i18n__.list.title',
13
+ data: {
14
+ title: '__i18n__.list.title',
15
+ subtitle: '__i18n__.list.subtitle',
16
+ sidebarVisible: true,
17
+ },
18
+ },
19
+ {
20
+ path: '__name__/:id',
21
+ component: __Name__DetailComponent,
22
+ canActivate: [configurationGuard],
23
+ title: '__i18n__.detail.title',
24
+ data: {
25
+ title: '__i18n__.detail.title',
26
+ subtitle: '__i18n__.detail.subtitle',
27
+ sidebarVisible: true,
28
+ },
29
+ },
30
+ ];
@@ -0,0 +1,102 @@
1
+ <st-card>
2
+ <st-card-header>
3
+ <st-card-title as="h2" preset="3">{{ '__i18n__.list.title' | translate }}</st-card-title>
4
+ <st-card-header-aside>
5
+ <st-button variant="primary" [icon]="addIcon" (clicked)="create()">{{ '__i18n__.list.new' | translate }}</st-button>
6
+ </st-card-header-aside>
7
+ </st-card-header>
8
+ <st-card-body>
9
+ <div class="flex flex-wrap items-end gap-2">
10
+ <st-input
11
+ class="w-full max-w-80"
12
+ [label]="'__i18n__.list.search' | translate"
13
+ [placeholder]="'__i18n__.list.search_placeholder' | translate"
14
+ [value]="search()"
15
+ (valueDebounced)="onSearch($event)"
16
+ />
17
+ @if (hasFilters()) {
18
+ <st-button variant="primary" size="sm" [ghost]="true" (clicked)="clearFilters()">{{
19
+ '__i18n__.actions.clear' | translate
20
+ }}</st-button>
21
+ }
22
+ </div>
23
+ <st-table
24
+ [data]="rows()"
25
+ [totalItems]="filtered().length"
26
+ [pagination]="pagination()"
27
+ (pageChanged)="page.set($event)"
28
+ (pageSizeChanged)="onPageSize($event)"
29
+ >
30
+ <thead>
31
+ <tr>
32
+ <th>{{ '__i18n__.fields.name' | translate }}</th>
33
+ <th>{{ '__i18n__.fields.description' | translate }}</th>
34
+ <th class="w-px">{{ '__i18n__.list.actions_column' | translate }}</th>
35
+ </tr>
36
+ </thead>
37
+ <tbody>
38
+ @for (row of rows(); track row.id) {
39
+ <tr>
40
+ <td>{{ row.name }}</td>
41
+ <td>{{ row.description }}</td>
42
+ <td>
43
+ <st-table-actions
44
+ mode="dropdown"
45
+ size="sm"
46
+ [actions]="rowActions"
47
+ [contextLabel]="row.name"
48
+ (actionTriggered)="onRowAction($event, row)"
49
+ />
50
+ </td>
51
+ </tr>
52
+ }
53
+ </tbody>
54
+ @if (hasFilters()) {
55
+ <st-empty-state
56
+ size="sm"
57
+ [heading]="'__i18n__.list.no_results_title' | translate"
58
+ [description]="'__i18n__.list.no_results_description' | translate"
59
+ >
60
+ <st-empty-state-actions>
61
+ <st-button variant="secondary" (clicked)="clearFilters()">{{ '__i18n__.list.clear_filters' | translate }}</st-button>
62
+ </st-empty-state-actions>
63
+ </st-empty-state>
64
+ } @else {
65
+ <st-empty-state
66
+ size="sm"
67
+ [heading]="'__i18n__.list.empty_title' | translate"
68
+ [description]="'__i18n__.list.empty_description' | translate"
69
+ />
70
+ }
71
+ </st-table>
72
+ </st-card-body>
73
+ </st-card>
74
+
75
+ <app-__name__-form-dialog [(opened)]="formOpen" [value]="editing()" (saved)="save($event)" />
76
+
77
+ <st-dialog width="xl" [(opened)]="deleteOpen">
78
+ <st-dialog-title>{{ '__i18n__.delete.title' | translate }}</st-dialog-title>
79
+ <st-dialog-sub-title>{{ '__i18n__.delete.question' | translate }}</st-dialog-sub-title>
80
+ <st-dialog-content>
81
+ @if (deleting(); as row) {
82
+ <st-table class="mt-4 block" size="sm" [showFooter]="false" [totalItems]="1" [data]="[row]">
83
+ <thead>
84
+ <tr>
85
+ <th>{{ '__i18n__.fields.name' | translate }}</th>
86
+ <th>{{ '__i18n__.fields.description' | translate }}</th>
87
+ </tr>
88
+ </thead>
89
+ <tbody>
90
+ <tr>
91
+ <td>{{ row.name }}</td>
92
+ <td>{{ row.description }}</td>
93
+ </tr>
94
+ </tbody>
95
+ </st-table>
96
+ }
97
+ </st-dialog-content>
98
+ <st-dialog-actions>
99
+ <st-button variant="secondary" (clicked)="deleteOpen.set(false)">{{ '__i18n__.actions.cancel' | translate }}</st-button>
100
+ <st-button variant="error" (clicked)="confirmDelete()">{{ '__i18n__.delete.confirm' | translate }}</st-button>
101
+ </st-dialog-actions>
102
+ </st-dialog>
@@ -0,0 +1,101 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+ import { ActivatedRoute, Router } from '@angular/router';
3
+ import { TableActionConfig } from '@sixbell-telco/sdk/components/table';
4
+ import { TranslatePipe } from '@sixbell-telco/sdk/utils/translation';
5
+ import { MockPipe, MockProvider } from 'ng-mocks';
6
+ import { __Name__Service } from '../../__name__.service';
7
+ import { __Name__ListComponent } from './__name__-list.component';
8
+
9
+ describe('__Name__ListComponent', () => {
10
+ let fixture: ComponentFixture<__Name__ListComponent>;
11
+ let component: __Name__ListComponent;
12
+ let service: __Name__Service;
13
+ let router: Router;
14
+
15
+ const action = (id: string): TableActionConfig => ({ id });
16
+
17
+ beforeEach(async () => {
18
+ await TestBed.configureTestingModule({
19
+ imports: [__Name__ListComponent, MockPipe(TranslatePipe, (key: string) => key)],
20
+ providers: [
21
+ MockProvider(Router, { navigate: jest.fn().mockResolvedValue(true) }),
22
+ MockProvider(ActivatedRoute),
23
+ ],
24
+ })
25
+ // Kit components render in CDK overlays and need the runtime theme; these tests drive the page logic.
26
+ .overrideComponent(__Name__ListComponent, { set: { template: '' } })
27
+ .compileComponents();
28
+
29
+ service = TestBed.inject(__Name__Service);
30
+ router = TestBed.inject(Router);
31
+ fixture = TestBed.createComponent(__Name__ListComponent);
32
+ component = fixture.componentInstance;
33
+ fixture.detectChanges();
34
+ });
35
+
36
+ it('filters by name or description and goes back to page 1', () => {
37
+ service.create({ name: 'Alpha', description: 'first' });
38
+ service.create({ name: 'Beta', description: 'second' });
39
+ component.page.set(2);
40
+
41
+ component.onSearch('SEC');
42
+
43
+ expect(component.page()).toBe(1);
44
+ expect(component.rows().map((row) => row.name)).toEqual(['Beta']);
45
+ expect(component.hasFilters()).toBe(true);
46
+
47
+ component.clearFilters();
48
+ expect(component.rows()).toHaveLength(2);
49
+ });
50
+
51
+ it('pages the filtered rows', () => {
52
+ for (let i = 1; i <= 12; i++) service.create({ name: `Item ${i}`, description: '' });
53
+
54
+ expect(component.rows()).toHaveLength(10);
55
+ component.page.set(2);
56
+ expect(component.rows().map((row) => row.name)).toEqual(['Item 11', 'Item 12']);
57
+
58
+ component.onPageSize(25);
59
+ expect(component.page()).toBe(1);
60
+ expect(component.rows()).toHaveLength(12);
61
+ });
62
+
63
+ it('opens the dialog empty to create and saves a new record', () => {
64
+ component.create();
65
+ expect(component.formOpen()).toBe(true);
66
+ expect(component.editing()).toBeNull();
67
+
68
+ component.save({ name: 'New', description: '' });
69
+
70
+ expect(component.formOpen()).toBe(false);
71
+ expect(service.items().map((item) => item.name)).toEqual(['New']);
72
+ });
73
+
74
+ it('edits the row from the row action', () => {
75
+ const row = service.create({ name: 'Old', description: '' });
76
+
77
+ component.onRowAction(action('edit'), row);
78
+ expect(component.editing()).toEqual(row);
79
+ component.save({ name: 'Renamed', description: 'x' });
80
+
81
+ expect(service.find(row.id)?.name).toBe('Renamed');
82
+ });
83
+
84
+ it('navigates to the record on view', () => {
85
+ const row = service.create({ name: 'Seen', description: '' });
86
+ component.onRowAction(action('view'), row);
87
+ expect(router.navigate).toHaveBeenCalledWith([row.id], expect.objectContaining({ relativeTo: expect.anything(), queryParamsHandling: 'merge' }));
88
+ });
89
+
90
+ it('deletes only after the confirm', () => {
91
+ const row = service.create({ name: 'Gone', description: '' });
92
+
93
+ component.onRowAction(action('delete'), row);
94
+ expect(component.deleteOpen()).toBe(true);
95
+ expect(service.items()).toHaveLength(1);
96
+
97
+ component.confirmDelete();
98
+ expect(component.deleteOpen()).toBe(false);
99
+ expect(service.items()).toEqual([]);
100
+ });
101
+ });
@@ -0,0 +1,143 @@
1
+ import { ChangeDetectionStrategy, Component, computed, inject, signal } from '@angular/core';
2
+ import { ActivatedRoute, Router } from '@angular/router';
3
+ import { heroEye, heroPencilSquare, heroPlus, heroTrash } from '@ng-icons/heroicons/outline';
4
+ import { ButtonComponent } from '@sixbell-telco/sdk/components/button';
5
+ import {
6
+ CardBodyComponent,
7
+ CardComponent,
8
+ CardHeaderAsideComponent,
9
+ CardHeaderComponent,
10
+ CardTitleComponent,
11
+ } from '@sixbell-telco/sdk/components/card';
12
+ import {
13
+ DialogActionsComponent,
14
+ DialogComponent,
15
+ DialogContentComponent,
16
+ DialogSubTitleComponent,
17
+ DialogTitleComponent,
18
+ } from '@sixbell-telco/sdk/components/dialog';
19
+ import { EmptyStateActionsComponent, EmptyStateComponent } from '@sixbell-telco/sdk/components/empty-state';
20
+ import { InputComponent } from '@sixbell-telco/sdk/components/forms/input';
21
+ import { TableActionConfig, TableActionsComponent, TableComponent, TablePagination } from '@sixbell-telco/sdk/components/table';
22
+ import { TranslatePipe } from '@sixbell-telco/sdk/utils/translation';
23
+ import { __Name__FormDialogComponent } from '../../components/__name__-form-dialog/__name__-form-dialog.component';
24
+ import { __Name__, __Name__Draft } from '../../__name__.model';
25
+ import { __Name__Service } from '../../__name__.service';
26
+
27
+ /** List page for __name__ records: search, paging, row actions, create/edit dialog and delete confirm. */
28
+ @Component({
29
+ selector: 'app-__name__-list',
30
+ imports: [
31
+ ButtonComponent,
32
+ CardComponent,
33
+ CardHeaderComponent,
34
+ CardTitleComponent,
35
+ CardHeaderAsideComponent,
36
+ CardBodyComponent,
37
+ DialogComponent,
38
+ DialogTitleComponent,
39
+ DialogSubTitleComponent,
40
+ DialogContentComponent,
41
+ DialogActionsComponent,
42
+ EmptyStateComponent,
43
+ EmptyStateActionsComponent,
44
+ InputComponent,
45
+ TableComponent,
46
+ TableActionsComponent,
47
+ TranslatePipe,
48
+ __Name__FormDialogComponent,
49
+ ],
50
+ templateUrl: './__name__-list.component.html',
51
+ changeDetection: ChangeDetectionStrategy.OnPush,
52
+ })
53
+ export class __Name__ListComponent {
54
+ private readonly service = inject(__Name__Service);
55
+ private readonly router = inject(Router);
56
+ private readonly route = inject(ActivatedRoute);
57
+
58
+ readonly addIcon = heroPlus;
59
+
60
+ /** Three row actions, so they go in the kit kebab menu; labels are i18n keys. */
61
+ readonly rowActions: TableActionConfig[] = [
62
+ { id: 'view', icon: heroEye, label: '__i18n__.actions.view', variant: 'primary' },
63
+ { id: 'edit', icon: heroPencilSquare, label: '__i18n__.actions.edit', variant: 'warning' },
64
+ { id: 'delete', icon: heroTrash, label: '__i18n__.actions.delete', variant: 'error' },
65
+ ];
66
+
67
+ readonly search = signal('');
68
+ readonly page = signal(1);
69
+ readonly pageSize = signal(10);
70
+
71
+ readonly hasFilters = computed(() => this.search().trim() !== '');
72
+ readonly filtered = computed(() => {
73
+ const term = this.search().trim().toLowerCase();
74
+ const items = this.service.items();
75
+ return term ? items.filter((item) => `${item.name} ${item.description}`.toLowerCase().includes(term)) : items;
76
+ });
77
+ readonly rows = computed(() => {
78
+ const start = (this.page() - 1) * this.pageSize();
79
+ return this.filtered().slice(start, start + this.pageSize());
80
+ });
81
+ readonly pagination = computed<TablePagination>(() => ({
82
+ id: '__name__-paginator',
83
+ currentPage: this.page(),
84
+ itemsPerPage: this.pageSize(),
85
+ search: this.search(),
86
+ }));
87
+
88
+ readonly formOpen = signal(false);
89
+ readonly editing = signal<__Name__ | null>(null);
90
+ readonly deleteOpen = signal(false);
91
+ readonly deleting = signal<__Name__ | null>(null);
92
+
93
+ onSearch(term: string): void {
94
+ this.search.set(term);
95
+ this.page.set(1);
96
+ }
97
+
98
+ clearFilters(): void {
99
+ this.onSearch('');
100
+ }
101
+
102
+ onPageSize(size: number): void {
103
+ this.pageSize.set(size);
104
+ this.page.set(1);
105
+ }
106
+
107
+ create(): void {
108
+ this.editing.set(null);
109
+ this.formOpen.set(true);
110
+ }
111
+
112
+ onRowAction(action: TableActionConfig, row: __Name__): void {
113
+ switch (action.id) {
114
+ case 'view':
115
+ void this.router.navigate([row.id], { relativeTo: this.route, queryParamsHandling: 'merge' });
116
+ break;
117
+ case 'edit':
118
+ this.editing.set(row);
119
+ this.formOpen.set(true);
120
+ break;
121
+ case 'delete':
122
+ this.deleting.set(row);
123
+ this.deleteOpen.set(true);
124
+ break;
125
+ }
126
+ }
127
+
128
+ save(draft: __Name__Draft): void {
129
+ const current = this.editing();
130
+ if (current) this.service.update(current.id, draft);
131
+ else this.service.create(draft);
132
+ this.formOpen.set(false);
133
+ }
134
+
135
+ confirmDelete(): void {
136
+ const row = this.deleting();
137
+ if (row) this.service.remove(row.id);
138
+ this.deleteOpen.set(false);
139
+ this.deleting.set(null);
140
+ const lastPage = Math.max(1, Math.ceil(this.filtered().length / this.pageSize()));
141
+ if (this.page() > lastPage) this.page.set(lastPage);
142
+ }
143
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "en": {
3
+ "detail": {
4
+ "title": "Record detail",
5
+ "subtitle": "Record information",
6
+ "general": "General information",
7
+ "edit": "Edit record",
8
+ "not_found_title": "Record not found",
9
+ "not_found_description": "The record does not exist or was deleted."
10
+ }
11
+ },
12
+ "es": {
13
+ "detail": {
14
+ "title": "Detalle del registro",
15
+ "subtitle": "Información del registro",
16
+ "general": "Información general",
17
+ "edit": "Editar registro",
18
+ "not_found_title": "No se encontró el registro",
19
+ "not_found_description": "El registro no existe o fue eliminado."
20
+ }
21
+ },
22
+ "pt": {
23
+ "detail": {
24
+ "title": "Detalhe do registro",
25
+ "subtitle": "Informações do registro",
26
+ "general": "Informações gerais",
27
+ "edit": "Editar registro",
28
+ "not_found_title": "Registro não encontrado",
29
+ "not_found_description": "O registro não existe ou foi excluído."
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,35 @@
1
+ @if (item(); as item) {
2
+ <st-card>
3
+ <st-card-header>
4
+ <st-card-title as="h2" preset="3">{{ item.name }}</st-card-title>
5
+ <st-card-header-aside>
6
+ <st-button variant="primary" size="sm" class="h-fit" [outline]="true" (clicked)="edit()">{{
7
+ '__i18n__.detail.edit' | translate
8
+ }}</st-button>
9
+ </st-card-header-aside>
10
+ </st-card-header>
11
+ <st-card-body>
12
+ <st-card-section-group [divided]="true">
13
+ <st-card-section>
14
+ <st-card-section-header>
15
+ <st-card-title>{{ '__i18n__.detail.general' | translate }}</st-card-title>
16
+ </st-card-section-header>
17
+ <st-card-section-body>
18
+ <st-description-list>
19
+ <div st-description-item [label]="'__i18n__.fields.id' | translate" [value]="item.id" [copyable]="true"></div>
20
+ <div st-description-item [label]="'__i18n__.fields.name' | translate" [value]="item.name"></div>
21
+ <div st-description-item [label]="'__i18n__.fields.description' | translate" [value]="item.description"></div>
22
+ </st-description-list>
23
+ </st-card-section-body>
24
+ </st-card-section>
25
+ </st-card-section-group>
26
+ </st-card-body>
27
+ </st-card>
28
+
29
+ <app-__name__-form-dialog [(opened)]="editOpen" [value]="item" (saved)="save($event)" />
30
+ } @else {
31
+ <st-empty-state
32
+ [heading]="'__i18n__.detail.not_found_title' | translate"
33
+ [description]="'__i18n__.detail.not_found_description' | translate"
34
+ />
35
+ }
@@ -0,0 +1,58 @@
1
+ import { ComponentFixture, TestBed } from '@angular/core/testing';
2
+ import { ActivatedRoute, convertToParamMap, ParamMap } from '@angular/router';
3
+ import { TranslatePipe } from '@sixbell-telco/sdk/utils/translation';
4
+ import { MockPipe } from 'ng-mocks';
5
+ import { BehaviorSubject } from 'rxjs';
6
+ import { __Name__Service } from '../../__name__.service';
7
+ import { __Name__DetailComponent } from './__name__-detail.component';
8
+
9
+ describe('__Name__DetailComponent', () => {
10
+ let fixture: ComponentFixture<__Name__DetailComponent>;
11
+ let component: __Name__DetailComponent;
12
+ let service: __Name__Service;
13
+ const params = new BehaviorSubject<ParamMap>(convertToParamMap({}));
14
+
15
+ beforeEach(async () => {
16
+ await TestBed.configureTestingModule({
17
+ imports: [__Name__DetailComponent, MockPipe(TranslatePipe, (key: string) => key)],
18
+ providers: [
19
+ { provide: ActivatedRoute, useValue: { paramMap: params.asObservable() } },
20
+ ],
21
+ })
22
+ // Kit components need the runtime theme; these tests drive the page logic.
23
+ .overrideComponent(__Name__DetailComponent, { set: { template: '' } })
24
+ .compileComponents();
25
+
26
+ service = TestBed.inject(__Name__Service);
27
+ });
28
+
29
+ const open = (id: string) => {
30
+ params.next(convertToParamMap({ id }));
31
+ fixture = TestBed.createComponent(__Name__DetailComponent);
32
+ component = fixture.componentInstance;
33
+ fixture.detectChanges();
34
+ };
35
+
36
+ it('shows the record named by the route', () => {
37
+ const record = service.create({ name: 'Alpha', description: 'First' });
38
+ open(record.id);
39
+ expect(component.item()).toEqual(record);
40
+ });
41
+
42
+ it('has no record for an unknown id', () => {
43
+ open('missing');
44
+ expect(component.item()).toBeUndefined();
45
+ });
46
+
47
+ it('saves edits from the dialog', () => {
48
+ const record = service.create({ name: 'Alpha', description: '' });
49
+ open(record.id);
50
+
51
+ component.edit();
52
+ expect(component.editOpen()).toBe(true);
53
+ component.save({ name: 'Renamed', description: 'Changed' });
54
+
55
+ expect(component.editOpen()).toBe(false);
56
+ expect(component.item()).toEqual({ id: record.id, name: 'Renamed', description: 'Changed' });
57
+ });
58
+ });
@@ -0,0 +1,68 @@
1
+ import { ChangeDetectionStrategy, Component, computed, inject, signal } from '@angular/core';
2
+ import { toSignal } from '@angular/core/rxjs-interop';
3
+ import { ActivatedRoute } from '@angular/router';
4
+ import { ButtonComponent } from '@sixbell-telco/sdk/components/button';
5
+ import {
6
+ CardBodyComponent,
7
+ CardComponent,
8
+ CardHeaderAsideComponent,
9
+ CardHeaderComponent,
10
+ CardSectionBodyComponent,
11
+ CardSectionComponent,
12
+ CardSectionGroupComponent,
13
+ CardSectionHeaderComponent,
14
+ CardTitleComponent,
15
+ } from '@sixbell-telco/sdk/components/card';
16
+ import { DescriptionItemComponent, DescriptionListComponent } from '@sixbell-telco/sdk/components/description-list';
17
+ import { EmptyStateComponent } from '@sixbell-telco/sdk/components/empty-state';
18
+ import { TranslatePipe } from '@sixbell-telco/sdk/utils/translation';
19
+ import { map } from 'rxjs';
20
+ import { __Name__FormDialogComponent } from '../../components/__name__-form-dialog/__name__-form-dialog.component';
21
+ import { __Name__Draft } from '../../__name__.model';
22
+ import { __Name__Service } from '../../__name__.service';
23
+
24
+ /**
25
+ * Read-only detail page for one __name__ record (route parameter `id`). No footer: the page
26
+ * banner back link is the way back; Edit sits in the card header and opens the form dialog.
27
+ */
28
+ @Component({
29
+ selector: 'app-__name__-detail',
30
+ imports: [
31
+ ButtonComponent,
32
+ CardComponent,
33
+ CardHeaderComponent,
34
+ CardHeaderAsideComponent,
35
+ CardTitleComponent,
36
+ CardBodyComponent,
37
+ CardSectionGroupComponent,
38
+ CardSectionComponent,
39
+ CardSectionHeaderComponent,
40
+ CardSectionBodyComponent,
41
+ DescriptionListComponent,
42
+ DescriptionItemComponent,
43
+ EmptyStateComponent,
44
+ TranslatePipe,
45
+ __Name__FormDialogComponent,
46
+ ],
47
+ templateUrl: './__name__-detail.component.html',
48
+ changeDetection: ChangeDetectionStrategy.OnPush,
49
+ })
50
+ export class __Name__DetailComponent {
51
+ private readonly route = inject(ActivatedRoute);
52
+ private readonly service = inject(__Name__Service);
53
+
54
+ private readonly id = toSignal(this.route.paramMap.pipe(map((params) => params.get('id') ?? '')), { initialValue: '' });
55
+
56
+ readonly item = computed(() => this.service.find(this.id()));
57
+ readonly editOpen = signal(false);
58
+
59
+ edit(): void {
60
+ this.editOpen.set(true);
61
+ }
62
+
63
+ save(draft: __Name__Draft): void {
64
+ const item = this.item();
65
+ if (item) this.service.update(item.id, draft);
66
+ this.editOpen.set(false);
67
+ }
68
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "en": { "fields": { "id": "ID", "name": "Name", "description": "Description" } },
3
+ "es": { "fields": { "id": "ID", "name": "Nombre", "description": "Descripción" } },
4
+ "pt": { "fields": { "id": "ID", "name": "Nome", "description": "Descrição" } }
5
+ }
@@ -0,0 +1,9 @@
1
+ /** One __name__ record. Replace the fields with the ones your API returns. */
2
+ export interface __Name__ {
3
+ id: string;
4
+ name: string;
5
+ description: string;
6
+ }
7
+
8
+ /** The fields a user edits in the form dialog. */
9
+ export type __Name__Draft = Omit<__Name__, 'id'>;