Fix Metrics type panel creation (#11454)

* Fix Metrics type panel creation

* clean up
This commit is contained in:
Azri Kahar
2022-02-08 04:52:06 +08:00
committed by GitHub
parent b8c4317cb1
commit 8912735e93

View File

@@ -1,7 +1,6 @@
import { computed } from 'vue';
import { useFieldsStore } from '@/stores';
import { definePanel } from '@directus/shared/utils';
import { Panel } from '@directus/shared/types';
import PanelMetric from './metric.vue';
export default definePanel({
@@ -10,17 +9,17 @@ export default definePanel({
description: '$t:panels.metric.description',
icon: 'functions',
component: PanelMetric,
options: (edits) => {
options: ({ options }) => {
const fieldsStore = useFieldsStore();
const fieldType = computed(() => {
const fieldStore = useFieldsStore();
const field = fieldStore.getField(edits.options?.collection, edits.options?.field);
return field?.type ?? null;
return options?.collection && options?.field
? fieldsStore.getField(options.collection, options.field)?.type
: null;
});
const supportsAggregate = computed(
() => fieldType.value && ['integer', 'bigInteger', 'float', 'decimal'].includes(fieldType.value)
const supportsAggregate = computed(() =>
fieldType.value ? ['integer', 'bigInteger', 'float', 'decimal'].includes(fieldType.value) : false
);
return [