Skip to content

Commit 0dcaacb

Browse files
fix: display metrics in SchemaToHtml (#469)
closes kestra-io/kestra#8792
1 parent 6a88bf6 commit 0dcaacb

File tree

3 files changed

+61
-28
lines changed

3 files changed

+61
-28
lines changed

src/components/plugins/PropertyDetail.vue

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
</span>
77
<a v-if="subtype.startsWith('#')" :href="subtype" @click.stop>
88
<button class="d-flex fw-bold type-box rounded fs-7 px-2 py-1">
9-
<span class="ref-type">{{ className(subtype) }}</span><eye-outline />
9+
<span class="ref-type">{{ className(subtype) }}</span>
10+
<EyeOutline />
1011
</button>
1112
</a>
1213
<span v-else class="type-box rounded fs-7 px-2 py-1">
@@ -41,6 +42,15 @@
4142
</code>
4243
</div>
4344

45+
<div v-if="property.unit !== undefined && property.unit.trim().length > 0">
46+
<span>
47+
Unit
48+
</span>
49+
<code class="border rounded px-2 py-1">
50+
{{ property.unit }}
51+
</code>
52+
</div>
53+
4454
<div v-if="property.minLength !== undefined">
4555
<span>
4656
Min length
@@ -138,9 +148,9 @@
138148
<slot v-if="property.title !== undefined" :content="codeSanitizer(property.title)" name="markdown" />
139149
<slot v-if="property.description !== undefined" :content="codeSanitizer(property.description)" name="markdown" />
140150
<div v-if="property['$internalStorageURI']">
141-
<Alert type="info">
142-
<slot content="Pebble expression referencing an Internal Storage URI e.g. `{{ outputs.mytask.uri }}`." name="markdown"/>
143-
</Alert>
151+
<Alert type="info">
152+
<slot content="Pebble expression referencing an Internal Storage URI e.g. `{{ outputs.mytask.uri }}`." name="markdown" />
153+
</Alert>
144154
</div>
145155
</div>
146156
</div>
@@ -151,6 +161,7 @@
151161
import {className, extractEnumValues, extractTypeInfo, type JSONProperty} from "../../utils/schemaUtils.ts";
152162
import {ref} from "vue";
153163
import EyeOutline from "vue-material-design-icons/EyeOutline.vue";
164+
import Alert from "../content/Alert.vue";
154165
155166
const props = withDefaults(
156167
defineProps<{
@@ -213,4 +224,4 @@
213224
width: fit-content;
214225
}
215226
}
216-
</style>
227+
</style>

src/components/plugins/SchemaToHtml.vue

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@
7373
</template>
7474
</CollapsibleProperties>
7575

76+
<CollapsibleProperties
77+
v-if="schema.properties?.$metrics"
78+
class="plugin-section"
79+
:properties="metrics"
80+
section-name="Metrics"
81+
href="metrics"
82+
:show-dynamic="false"
83+
>
84+
<template #markdown="{content}">
85+
<div class="markdown">
86+
<slot name="markdown" :content="content" />
87+
</div>
88+
</template>
89+
</CollapsibleProperties>
90+
7691
<Collapsible v-if="schema.definitions && Object.keys(schema.definitions).length > 0" class="plugin-section" clickable-text="Definitions" href="definitions" :initially-expanded="definitionsExpanded">
7792
<template #content>
7893
<div class="d-flex flex-column gap-7 ps-3">
@@ -103,7 +118,7 @@
103118
import {computed, onUnmounted, ref} from "vue";
104119
import type {HighlighterCore} from "shiki/core";
105120
import SchemaToCode from "./SchemaToCode.vue";
106-
import type {JSONSchema} from "../../utils/schemaUtils.ts";
121+
import type {JSONProperty, JSONSchema} from "../../utils/schemaUtils.ts";
107122
import Collapsible from "../misc/Collapsible.vue";
108123
import CollapsibleProperties from "./CollapsibleProperties.vue";
109124
@@ -130,7 +145,11 @@
130145
131146
const highlighter = ref<HighlighterCore | null>(null);
132147
133-
const examples = computed(() => props.schema.properties?.["$examples"])
148+
const examples = computed(() => props.schema.properties?.["$examples"]);
149+
150+
const metrics = computed(() => Object.fromEntries(
151+
props.schema.properties?.["$metrics"]?.map(metric => ([metric.name, {...metric, name: undefined}])) as [string, JSONProperty][]
152+
));
134153
135154
const {
136155
githubLight,
@@ -200,11 +219,11 @@
200219
:deep(.type-box) {
201220
color: buttontext;
202221
203-
& .material-design-icon{
222+
& .material-design-icon {
204223
&, & * {
205224
height: 1rem;
206225
width: 1rem;
207226
}
208227
}
209228
}
210-
</style>
229+
</style>

src/utils/schemaUtils.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
11
import Utils from "./Utils.ts";
22

33
export interface JSONProperty {
4-
type:string;
4+
type: string;
5+
name?: string;
6+
unit?: string;
57
$dynamic?: boolean;
6-
$ref?:string;
7-
$required?:boolean;
8+
$ref?: string;
9+
$required?: boolean;
810
$beta?: boolean;
911
$deprecated?: boolean;
1012
$internalStorageURI?: boolean;
11-
allOf?:JSONProperty[];
12-
anyOf?:JSONProperty[];
13+
allOf?: JSONProperty[];
14+
anyOf?: JSONProperty[];
1315
items?: JSONProperty;
14-
additionalProperties?:JSONProperty;
15-
title?:string;
16-
description?:string;
17-
default?:string;
18-
pattern?:string;
19-
minLength?:number;
20-
maxLength?:number;
21-
minItems?:number;
22-
maxItems?:number;
23-
minimum?:number;
24-
exclusiveMinimum?:number;
25-
maximum?:number;
26-
exclusiveMaximum?:number;
27-
format?:string;
16+
additionalProperties?: JSONProperty;
17+
title?: string;
18+
description?: string;
19+
default?: string;
20+
pattern?: string;
21+
minLength?: number;
22+
maxLength?: number;
23+
minItems?: number;
24+
maxItems?: number;
25+
minimum?: number;
26+
exclusiveMinimum?: number;
27+
maximum?: number;
28+
exclusiveMaximum?: number;
29+
format?: string;
2830
enum?: string[];
2931
}
3032

@@ -47,6 +49,7 @@ export interface JSONSchema {
4749
lang?: string
4850
full?: boolean
4951
}[]
52+
$metrics?: JSONProperty[];
5053
}
5154
}
5255

0 commit comments

Comments
 (0)