-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add filtering by workflow, processor and date range to timeline…
… view (#85) * feat: filter by workflow and processor * feat: filter by date range * feat: implement multi-selectable workflow steps filtering * fix: make only related workflows visible while filtering by processors * fix: set all checkboxes of processor filter to selected on page load * ref: highlight selected processors * fix: refactor to own component and prepare visual filtering * fix: show filter also when no data is selected * fix: workflow filter label * feat: hide workflow when neither workflow or processor in workflow are selected * refactor: remove unused imports/vars, style * fix: remove search from workflow filter * feat: change date range dropdown to multiselect * refactor: change order * feat: add i18n translations * fix: adjust filter position for smaller screens * fix: changed faulty imported that failed build * fix: workflow filter not working --------- Co-authored-by: amtul.noor <[email protected]> Co-authored-by: noornoorie <[email protected]> Co-authored-by: jfrer <[email protected]>
- Loading branch information
1 parent
a4bbdac
commit 084933b
Showing
9 changed files
with
261 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
<script setup lang="ts"> | ||
import filtersStore from "@/store/filters-store" | ||
import workflowsStore from "@/store/workflows-store" | ||
import { computed, onMounted, ref } from "vue" | ||
import MultiSelect from "primevue/multiselect" | ||
import type { DropdownOption, GroundTruth } from "@/types" | ||
import { deduplicateStepIds, mapGtId } from '@/helpers/utils' | ||
import { useI18n } from "vue-i18n" | ||
const { t } = useI18n() | ||
const dateRangeOptions = computed(() => { | ||
const values = workflowsStore.gt.reduce((acc, cur) => { | ||
acc.add(`${cur.metadata.time.notBefore}-${cur.metadata.time.notAfter}`) | ||
return acc | ||
}, new Set<string>()) | ||
return Array.from(values).sort().map(value => ({ value, label: value })) | ||
}) | ||
const selectedDateRange = ref<DropdownOption[]>([]) | ||
const workflowOptions = computed(() => workflowsStore.workflows.map(({ id, label }) => ({ value: id, label }))) | ||
const selectedWorkflows = ref<DropdownOption[]>([]) | ||
const workflowStepOptions = ref<DropdownOption[]>([]) | ||
const selectedWorkflowSteps = ref<DropdownOption[]>([]) | ||
const dateRangeDropdownLabel = computed(() => { | ||
if (dateRangeOptions.value.length === selectedDateRange.value.length) { | ||
return t('filter_by_date_range') | ||
} | ||
return null | ||
}) | ||
const workflowDropdownLabel = computed(() => { | ||
if (workflowOptions.value.length === selectedWorkflows.value.length) { | ||
return t('filter_by_workflow') | ||
} | ||
return null | ||
}) | ||
const workflowStepDropdownLabel = computed(() => { | ||
if (workflowStepOptions.value.length === selectedWorkflowSteps.value.length) { | ||
return t('filter_by_processor') | ||
} | ||
return null | ||
}) | ||
const onDateRangeChange = (event: any) => { | ||
selectedDateRange.value = event | ||
selectGTs() | ||
} | ||
const onWorkflowChange = (event: any) => { | ||
selectedWorkflows.value = event | ||
selectGTs() | ||
selectWorkflows() | ||
} | ||
const onWorkflowStepChange = (event: any) => { | ||
selectedWorkflowSteps.value = event | ||
selectGTs() | ||
selectWorkflows() | ||
} | ||
const selectGTs = () => { | ||
filtersStore.gtTimeline = filtersStore.gt.filter(({ value }) => { | ||
const gt = workflowsStore.getGtById(value) | ||
if(!gt) return false | ||
return hasSomeSelectedProcessor(gt) && hasSomeSelectedDateRange(gt) && hasSomeSelectedWorkflow(gt) | ||
}) | ||
} | ||
const selectWorkflows = () => { | ||
filtersStore.workflow = selectedWorkflows.value.filter(({ value }) => (workflowhasSomeSelectedWorkflowStep(value))) | ||
} | ||
const hasSomeSelectedProcessor = (gt: GroundTruth) => { | ||
const gtRuns = workflowsStore.getRuns(gt.id) | ||
return selectedWorkflowSteps.value.some((selectedStep) => { | ||
return gtRuns.some((gtRun) => { | ||
return gtRun.metadata.workflow_steps.findIndex(({ id }) => id === selectedStep.value) > -1 | ||
}) | ||
}) | ||
} | ||
const hasSomeSelectedDateRange = (gt: GroundTruth) => { | ||
return selectedDateRange.value.some(({ value }) => { | ||
const splitDateRange = value.split('-') | ||
const from = splitDateRange[0] | ||
const to = splitDateRange[1] | ||
return gt.metadata.time.notBefore === from && gt.metadata.time.notAfter === to | ||
}) | ||
} | ||
const hasSomeSelectedWorkflow = (gt: GroundTruth) => { | ||
const gtRuns = workflowsStore.getRuns(gt.id) | ||
return gtRuns.some((gtRun) => { | ||
return selectedWorkflows.value.findIndex(({ value }) => (value === mapGtId(gtRun.metadata.ocr_workflow.id))) > -1 | ||
}) | ||
} | ||
const workflowhasSomeSelectedWorkflowStep = (workflowId: string) => { | ||
const workflow = workflowsStore.getWorkflowById(workflowId) | ||
if (workflow == null) return false | ||
return workflow.steps.some((step) => selectedWorkflowSteps.value.findIndex(({ value }) => (value === step.id)) > -1) | ||
} | ||
onMounted(() => { | ||
workflowStepOptions.value = deduplicateStepIds(workflowsStore.workflows).map(id => ({ value: id, label: t(id) })) | ||
selectedDateRange.value = dateRangeOptions.value | ||
selectedWorkflows.value = workflowOptions.value | ||
selectedWorkflowSteps.value = workflowStepOptions.value | ||
selectGTs() | ||
selectWorkflows() | ||
}) | ||
</script> | ||
|
||
<template> | ||
<div class="flex flex-wrap mb-4 justify-start lg:justify-end"> | ||
<MultiSelect | ||
v-model="selectedDateRange" | ||
@update:model-value="onDateRangeChange($event)" | ||
:max-selected-labels="1" | ||
:options="dateRangeOptions" | ||
optionLabel="label" | ||
:placeholder="t('select_a_date_range')" | ||
:selected-items-label="dateRangeDropdownLabel" | ||
class="mr-4 mb-2 lg:m-0 lg:ml-auto md:w-14rem" | ||
/> | ||
<MultiSelect | ||
v-model="selectedWorkflows" | ||
@update:model-value="onWorkflowChange($event)" | ||
:max-selected-labels="1" | ||
:options="workflowOptions" | ||
optionLabel="label" | ||
:placeholder="t('select_a_workflow')" | ||
:selected-items-label="workflowDropdownLabel" | ||
class="mr-4 mb-2 lg:m-0 lg:ml-4 md:w-14rem" | ||
/> | ||
<MultiSelect | ||
v-model="selectedWorkflowSteps" | ||
@update:model-value="onWorkflowStepChange($event)" | ||
filter | ||
:max-selected-labels="1" | ||
:options="workflowStepOptions" | ||
optionLabel="label" | ||
:placeholder="t('select_a_processor')" | ||
:selected-items-label="workflowStepDropdownLabel" | ||
class="lg:ml-4 md:w-14rem" | ||
/> | ||
</div> | ||
|
||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.