diff --git a/src/components/workflows/WorkflowsTable.vue b/src/components/workflows/WorkflowsTable.vue index f42c6f2..56ec905 100644 --- a/src/components/workflows/WorkflowsTable.vue +++ b/src/components/workflows/WorkflowsTable.vue @@ -2,19 +2,29 @@ import { watch, ref, onMounted, computed } from "vue" import { useI18n } from "vue-i18n" import { createReadableMetricValue, getEvalColor, mapGtId } from "@/helpers/utils" -import type { EvaluationRun } from "@/types" +import type { EvalDefinitions, EvaluationResultsDocumentWide, EvaluationRun, GroupedTableData } from "@/types" import Dropdown from 'primevue/dropdown' +import Checkbox from 'primevue/checkbox' import workflowsStore from "@/store/workflows-store" import api from "@/helpers/api" import filtersStore from "@/store/filters-store" import TrendLegend from "@/components/workflows/TrendLegend.vue" +import WorkflowsTableSorter from "@/components/workflows/timeline/WorkflowTableSorter.vue" const { t } = useI18n() -const groupedData = ref({}) -const evals = ref([]) +const groupedData = ref({}) +const sortedData = ref({}) +const evals = ref([]) +const sortBy = ref(null) -const sortOptions = ref([{ +const tableData = computed(() => { + return (sortBy.value === null || Object.keys(sortedData.value).length === 0) ? groupedData.value : sortedData.value +}) + +const keepGroupsWhenSorting = ref(true) + +const groupingOptions = ref([{ value: 'documents', label: t('documents') }, { @@ -22,10 +32,10 @@ const sortOptions = ref([{ label: t('workflows') }]) -const sortBy = ref(sortOptions.value[0]) +const groupBy = ref(groupingOptions.value[0]) const latestRuns = ref([]) const filteredRuns = ref([]) -const evalDefinitions = ref([]) +const evalDefinitions = ref({}) const loading = ref(false) onMounted(async () => { @@ -33,17 +43,17 @@ onMounted(async () => { latestRuns.value = workflowsStore.getLatestRuns() evalDefinitions.value = await api.getEvalDefinitions() setFilteredRuns() - groupRuns(sortBy.value.value) + groupRuns(groupBy.value.value) loading.value = false }) watch(() => filtersStore.gt, () => { setFilteredRuns() - groupRuns(sortBy.value.value) + groupRuns(groupBy.value.value) }) -watch(sortBy, () => { - groupRuns(sortBy.value.value) +watch(groupBy, () => { + groupRuns(groupBy.value.value) }) function setFilteredRuns() { @@ -53,6 +63,7 @@ function setFilteredRuns() { function groupRuns(groupBy: string) { if (groupBy === 'workflows') groupByWorkflows() else if (groupBy === 'documents') groupByDocuments() + sortBy.value = null } const groupByWorkflows = () => { @@ -66,7 +77,7 @@ const groupByWorkflows = () => { label: workflowsStore.getGtById(mapGtId(cur.metadata.gt_workspace.id))?.label, evaluations: Object.keys(cur.evaluation_results.document_wide).map(key => ({ name: key, - value: cur.evaluation_results.document_wide[key] + value: cur.evaluation_results.document_wide[key as keyof EvaluationResultsDocumentWide] })) } if (!acc[ocrWorkflowId]) { @@ -77,12 +88,12 @@ const groupByWorkflows = () => { } else { acc[ocrWorkflowId].subjects.push(subject) acc[ocrWorkflowId].subjects.sort((a, b) => { - if (a.label > b.label) return 1 + if ((a.label && b.label) && a.label > b.label) return 1 else return -1 }) } return acc - }, {}) + }, {} as GroupedTableData) } const groupByDocuments = () => { @@ -94,7 +105,7 @@ const groupByDocuments = () => { label: workflowsStore.getWorkflowById(mapGtId(cur.metadata.ocr_workflow['id']))?.label, evaluations: Object.keys(cur.evaluation_results.document_wide).map(key => ({ name: key, - value: cur.evaluation_results.document_wide[key] + value: cur.evaluation_results.document_wide[key as keyof EvaluationResultsDocumentWide] })) } if (!acc[gtWorkspaceId]) { @@ -105,12 +116,21 @@ const groupByDocuments = () => { } else { acc[gtWorkspaceId].subjects.push(subject) acc[gtWorkspaceId].subjects.sort((a, b) => { - if (a.label > b.label) return 1 + if ((a.label && b.label) && a.label > b.label) return 1 else return -1 }) } return acc - }, {}) + }, {} as GroupedTableData) +} + +const getSortValue = (key: keyof EvaluationResultsDocumentWide) => { + return sortBy.value === key +} + +const setSorted = (event: GroupedTableData, key: keyof EvaluationResultsDocumentWide) => { + sortBy.value = key + sortedData.value = event } @@ -119,21 +139,33 @@ const groupByDocuments = () => { Loading...