Skip to content

Commit

Permalink
feat: add chart query set to active query
Browse files Browse the repository at this point in the history
  • Loading branch information
nextchamp-saqib committed Dec 9, 2024
1 parent b8207dc commit 507359e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions frontend/src2/workbook/WorkbookSidebar.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
<script setup lang="ts">
import { Braces, LayoutPanelTop, ScrollText, Table2 } from 'lucide-vue-next'
import { inject } from 'vue'
import { computed, inject } from 'vue'
import { useRoute } from 'vue-router'
import ChartIcon from '../charts/components/ChartIcon.vue'
import WorkbookSidebarListSection from './WorkbookSidebarListSection.vue'
import { Workbook, workbookKey } from './workbook'
import { workbookKey } from './workbook'
const workbook = inject(workbookKey) as Workbook
const workbook = inject(workbookKey)!
const route = useRoute()
const activeQueryName = computed(() => {
if (route.name === 'WorkbookQuery') {
const index = parseInt(route.params.index as string)
return workbook?.doc.queries[index].name
}
})
</script>

<template>
Expand Down Expand Up @@ -47,7 +56,7 @@ const workbook = inject(workbookKey) as Workbook
items: workbook.doc.charts,
itemKey: 'name',
isActive: (idx: number) => workbook.isActiveTab('chart', idx),
add: workbook.addChart,
add: () => workbook.addChart(activeQueryName),
remove: (chart) => workbook.removeChart(chart.name),
route: (idx: number) => `/workbook/${workbook.name}/chart/${idx}`,
}"
Expand Down
4 changes: 2 additions & 2 deletions frontend/src2/workbook/workbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ export default function useWorkbook(name: string) {
})
}

function addChart() {
function addChart(query_name?: string) {
const idx = workbook.doc.charts.length
workbook.doc.charts.push({
name: getUniqueId(),
title: `Chart ${idx + 1}`,
query: '',
query: query_name || '',
chart_type: 'Bar',
is_public: false,
config: {} as WorkbookChart['config'],
Expand Down

0 comments on commit 507359e

Please sign in to comment.