Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix filters on dashboard load and column sort #381

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions frontend/src2/dashboard/DashboardItem.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<script setup lang="ts">
import { watchDebounced } from '@vueuse/core'
import { AlertTriangle } from 'lucide-vue-next'
import { computed, inject, ref } from 'vue'
import { Chart, getCachedChart } from '../charts/chart'
import ChartRenderer from '../charts/components/ChartRenderer.vue'
import { WorkbookDashboardChart, WorkbookDashboardItem } from '../types/workbook.types'
import { Dashboard } from './dashboard'
import DashboardItemActions from './DashboardItemActions.vue'
import { watchDebounced } from '@vueuse/core'
import { AlertTriangle } from 'lucide-vue-next'

const props = defineProps<{
index: number
Expand All @@ -23,7 +23,7 @@ const chart = computed(() => {

watchDebounced(
() => chart.value?.doc.config.order_by,
() => chart.value?.refresh(),
() => dashboard.refreshChart(props.item.chart),
{
deep: true,
debounce: 500,
Expand Down
35 changes: 17 additions & 18 deletions frontend/src2/dashboard/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ import { getCachedChart } from '../charts/chart'
import { getUniqueId, store } from '../helpers'
import { getCachedQuery } from '../query/query'
import { FilterArgs } from '../types/query.types'
import {
WorkbookChart,
WorkbookDashboard
} from '../types/workbook.types'
import { WorkbookChart, WorkbookDashboard } from '../types/workbook.types'

const dashboards = new Map<string, Dashboard>()

Expand Down Expand Up @@ -72,21 +69,23 @@ function makeDashboard(workbookDashboard: WorkbookDashboard) {
refresh() {
dashboard.doc.items
.filter((item) => item.type === 'chart')
.forEach((chartItem) => {
const chart = getCachedChart(chartItem.chart)
if (!chart || !chart.doc.query) return

Object.keys(dashboard.filters).forEach((query) => {
const _query = getCachedQuery(query)
if (!_query) return
_query.dashboardFilters = {
logical_operator: 'And',
filters: dashboard.filters[query],
}
})
.forEach((item) => dashboard.refreshChart(item.chart))
},

refreshChart(chart_name: string) {
const chart = getCachedChart(chart_name)
if (!chart || !chart.doc.query) return

Object.keys(dashboard.filters).forEach((query) => {
const _query = getCachedQuery(query)
if (!_query) return
_query.dashboardFilters = {
logical_operator: 'And',
filters: dashboard.filters[query],
}
})

chart.refresh()
})
chart.refresh()
},

getShareLink() {
Expand Down