Allow empty field for metric

This commit is contained in:
rijkvanzanten
2021-06-20 16:35:43 -04:00
parent 3e1cae16af
commit 9f26b413df
2 changed files with 7 additions and 2 deletions

View File

@@ -27,6 +27,7 @@ export default definePanel({
collectionField: 'collection',
typeAllowList: ['integer', 'bigInteger', 'float', 'decimal'],
allowPrimaryKey: true,
allowNone: true,
},
width: 'half',
},

View File

@@ -122,14 +122,18 @@ export default defineComponent({
const res = await api.get(`/items/${props.options.collection}`, {
params: {
aggregate: {
[props.options.function]: [props.options.field],
[props.options.function]: [props.options.field || '*'],
},
filter: props.options.filter,
sort: sort,
},
});
metric.value = Number(res.data.data[0][`${props.options.field}_${props.options.function}`]);
if (props.options.field) {
metric.value = Number(res.data.data[0][`${props.options.field}_${props.options.function}`]);
} else {
metric.value = Number(res.data.data[0][props.options.function]);
}
} catch (err) {
// oh no
} finally {