Fix defaults rendering in list, add defaults to metric

This commit is contained in:
rijkvanzanten
2021-06-18 13:56:14 -04:00
parent 9b3627d5d9
commit c35b469b0a
6 changed files with 43 additions and 11 deletions

View File

@@ -217,7 +217,7 @@ export default defineComponent({
function emitValue(event: InputEvent) {
let value = (event.target as HTMLInputElement).value;
if (props.nullable === true && !value) {
if (props.nullable === true && value === '') {
emit('update:modelValue', null);
return;
}

View File

@@ -15,7 +15,7 @@
<template #item="{ element, index }">
<v-list-item :dense="value.length > 4" block @click="active = index">
<v-icon name="drag_handle" class="drag-handle" left @click.stop="() => {}" />
<render-template :fields="fields" :item="element" :template="templateWithDefaults" />
<render-template :fields="fields" :item="{ ...defaults, ...element }" :template="templateWithDefaults" />
<div class="spacer" />
<v-icon v-if="!disabled" name="close" @click.stop="removeItem(element)" />
</v-list-item>
@@ -119,6 +119,18 @@ export default defineComponent({
const { displayValue } = renderStringTemplate(templateWithDefaults, activeItem);
const defaults = computed(() => {
const values: Record<string, any> = {};
for (const field of props.fields) {
if (field.schema?.default_value !== undefined && field.schema?.default_value !== null) {
values[field.field!] = field.schema.default_value;
}
}
return values;
});
return {
t,
updateValues,
@@ -133,6 +145,7 @@ export default defineComponent({
closeDrawer,
onSort,
templateWithDefaults,
defaults,
};
function updateValues(index: number, updatedValues: any) {

View File

@@ -185,6 +185,9 @@ export default definePanel({
field: 'operator',
name: '$t:operator',
type: 'string',
schema: {
default_value: '>=',
},
meta: {
interface: 'select-dropdown',
options: {
@@ -222,6 +225,9 @@ export default definePanel({
field: 'value',
name: '$t:value',
type: 'integer',
schema: {
default_value: 0,
},
meta: {
interface: 'input',
width: 'half',

View File

@@ -74,24 +74,33 @@ export default defineComponent({
const color = computed(() => {
if (!metric.value) return null;
const matchingFormat = (props.options.conditionalFormatting || []).find(matchesOperator);
let matchingFormat: MetricOptions['conditionalFormatting'][number] | null = null;
for (const format of props.options.conditionalFormatting || []) {
if (matchesOperator(format)) {
matchingFormat = format;
}
}
return matchingFormat?.color || null;
function matchesOperator(format: MetricOptions['conditionalFormatting'][number]) {
switch (format.operator) {
const value = Number(metric.value);
const compareValue = Number(format.value ?? 0);
switch (format.operator || '>=') {
case '=':
return metric.value === format.value;
return value === compareValue;
case '!=':
return metric.value !== format.value;
return value !== compareValue;
case '>':
return metric.value > format.value;
return value > compareValue;
case '>=':
return metric.value >= format.value;
return value >= compareValue;
case '<':
return metric.value < format.value;
return value < compareValue;
case '<=':
return metric.value < format.value;
return value < compareValue;
}
}
});

View File

@@ -85,6 +85,7 @@ export default defineComponent({
// Try getting the value from the item, return some question marks if it doesn't exist
const value = get(props.item, fieldKey);
if (value === undefined) return null;
if (!field) return value;
@@ -116,7 +117,7 @@ export default defineComponent({
field: field.field,
};
})
.map((p) => p || null)
.map((p) => p ?? null)
);
return { parts, templateEl };

3
package-lock.json generated
View File

@@ -497,7 +497,10 @@
"mitt": "2.1.0",
"nanoid": "3.1.23",
"pinia": "2.0.0-beta.3",
"prettier": "2.3.1",
"pretty-ms": "7.0.1",
"qrcode": "1.4.4",
"rimraf": "3.0.2",
"sass": "1.35.1",
"tinymce": "5.8.1",
"typescript": "4.3.4",