Skip to content

Commit 5b29ebd

Browse files
committed
feat(models): add optional table title
1 parent 6005d6b commit 5b29ebd

File tree

3 files changed

+79
-28
lines changed

3 files changed

+79
-28
lines changed

packages/models/docs/models-reference.md

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ Detailed information
66

77
_Object containing the following properties:_
88

9-
| Property | Description | Type |
10-
| :------- | :------------------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
11-
| `issues` | List of findings | _Array of [Issue](#issue) items_ |
12-
| `table` | Table of related findings | _Object with properties:_<ul><li>`headings`: _Array of [TableHeading](#tableheading) items_</li><li>`alignment`: `Array<'l' \| 'c' \| 'r'>`</li><li>`rows`: `Array<Array<string \| number> \| Record<string, string \| number>>`</li></ul> |
9+
| Property | Description | Type |
10+
| :------- | :------------------------ | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
11+
| `issues` | List of findings | _Array of [Issue](#issue) items_ |
12+
| `table` | Table of related findings | _Object with properties:_<ul><li>`title`: `string` - Display title for table</li><li>`columns`: _Array of [TableAlignment](#tablealignment) items_</li><li>`rows`: _Array of [TableRowPrimitive](#tablerowprimitive) items_</li></ul> _or_ _Object with properties:_<ul><li>`title`: `string` - Display title for table</li><li>`columns`: _Array of [TableAlignment](#tablealignment) items_ _or_ _Array of [TableColumnObject](#tablecolumnobject) items_</li><li>`rows`: _Array of [TableRowObject](#tablerowobject) items_</li></ul> |
1313

1414
_All properties are optional._
1515

@@ -1193,6 +1193,13 @@ _Object containing the following properties:_
11931193

11941194
_(\*) Required._
11951195

1196+
## PrimitiveValue
1197+
1198+
_Union of the following possible types:_
1199+
1200+
- `string`
1201+
- `number`
1202+
11961203
## Report
11971204

11981205
_Object containing the following properties:_
@@ -1253,19 +1260,53 @@ _Returns:_
12531260

12541261
- [AuditOutputs](#auditoutputs) _or_ _Promise of_ [AuditOutputs](#auditoutputs)
12551262

1256-
## TableHeading
1263+
## TableAlignment
1264+
1265+
Cell alignment
1266+
1267+
_Enum string, one of the following possible values:_
1268+
1269+
- `'left'`
1270+
- `'center'`
1271+
- `'right'`
12571272

1258-
Source file location
1273+
## TableColumnObject
12591274

12601275
_Object containing the following properties:_
12611276

1262-
| Property | Type |
1263-
| :------------- | :------- |
1264-
| **`key`** (\*) | `string` |
1265-
| `label` | `string` |
1277+
| Property | Description | Type |
1278+
| :------------- | :------------- | :-------------------------------- |
1279+
| **`key`** (\*) | | `string` |
1280+
| `label` | | `string` |
1281+
| `align` | Cell alignment | [TableAlignment](#tablealignment) |
12661282

12671283
_(\*) Required._
12681284

1285+
## TableColumnPrimitive
1286+
1287+
Cell alignment
1288+
1289+
_Enum string, one of the following possible values:_
1290+
1291+
- `'left'`
1292+
- `'center'`
1293+
- `'right'`
1294+
1295+
## TableRowObject
1296+
1297+
Object row
1298+
1299+
_Object record with dynamic keys:_
1300+
1301+
- _keys of type_ `string`
1302+
- _values of type_ [PrimitiveValue](#primitivevalue)
1303+
1304+
## TableRowPrimitive
1305+
1306+
Primitive row
1307+
1308+
_Array of [PrimitiveValue](#primitivevalue) items._
1309+
12691310
## UploadConfig
12701311

12711312
_Object containing the following properties:_

packages/models/src/lib/table.ts

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,34 @@ export const tableRowPrimitiveSchema = z.array(primitiveValueSchema, {
2626
});
2727
export type TableRowPrimitive = z.infer<typeof tableRowPrimitiveSchema>;
2828

29-
const tablePrimitiveSchema = z.object(
30-
{
31-
columns: z.array(tableAlignmentSchema).optional(),
32-
rows: z.array(tableRowPrimitiveSchema),
33-
},
34-
{ description: 'Table with primitive rows and optional alignment columns' },
29+
const tableSharedSchema = z.object({
30+
title: z.string().optional().describe('Display title for table'),
31+
});
32+
const tablePrimitiveSchema = tableSharedSchema.merge(
33+
z.object(
34+
{
35+
columns: z.array(tableAlignmentSchema).optional(),
36+
rows: z.array(tableRowPrimitiveSchema),
37+
},
38+
{ description: 'Table with primitive rows and optional alignment columns' },
39+
),
3540
);
36-
37-
const tableObjectSchema = z.object(
38-
{
39-
columns: z
40-
.union([z.array(tableAlignmentSchema), z.array(tableColumnObjectSchema)])
41-
.optional(),
42-
rows: z.array(tableRowObjectSchema),
43-
},
44-
{
45-
description:
46-
'Table with object rows and optional alignment or object columns',
47-
},
41+
const tableObjectSchema = tableSharedSchema.merge(
42+
z.object(
43+
{
44+
columns: z
45+
.union([
46+
z.array(tableAlignmentSchema),
47+
z.array(tableColumnObjectSchema),
48+
])
49+
.optional(),
50+
rows: z.array(tableRowObjectSchema),
51+
},
52+
{
53+
description:
54+
'Table with object rows and optional alignment or object columns',
55+
},
56+
),
4857
);
4958

5059
export const tableSchema = (description = 'Table information') =>

packages/models/src/lib/table.unit.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ describe('tableSchema', () => {
163163

164164
it('should parse complete table', () => {
165165
const fullTable: Table = {
166+
title: 'Largest Contentful Paint element',
166167
columns: [
167168
// center is often the default when rendering in MD or HTML
168169
{ key: 'phase', label: 'Phase' },

0 commit comments

Comments
 (0)