forked from frappe/insights
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move data source selector in the sidebar
- Loading branch information
1 parent
35f54a8
commit 9056ccc
Showing
3 changed files
with
63 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<script setup> | ||
import useDataSourceStore from '@/stores/dataSourceStore' | ||
import { ChevronDown, Database } from 'lucide-vue-next' | ||
import { computed, inject } from 'vue' | ||
const $notify = inject('$notify') | ||
const query = inject('query') | ||
const sources = useDataSourceStore() | ||
const currentSource = computed(() => { | ||
return sources.list.find((source) => source.name === query.doc.data_source) | ||
}) | ||
const dataSourceOptions = computed(() => { | ||
return sources.list.map((source) => ({ | ||
label: source.title, | ||
value: source.name, | ||
})) | ||
}) | ||
function changeDataSource(sourceName) { | ||
query.changeDataSource(sourceName).then(() => { | ||
$notify({ | ||
title: 'Data source updated', | ||
variant: 'success', | ||
}) | ||
}) | ||
} | ||
</script> | ||
|
||
<template> | ||
<Autocomplete | ||
:options="dataSourceOptions" | ||
:modelValue="query.doc.data_source" | ||
@update:modelValue="changeDataSource($event.value)" | ||
> | ||
<template #target="{ togglePopover }"> | ||
<Button variant="outline" @click="togglePopover"> | ||
<div class="flex items-center gap-2"> | ||
<Database class="h-4 w-4 text-gray-600" /> | ||
<span class="truncate"> | ||
{{ currentSource?.title || 'Select data source' }} | ||
</span> | ||
<ChevronDown class="h-4 w-4 text-gray-600" /> | ||
</div> | ||
</Button> | ||
</template> | ||
</Autocomplete> | ||
</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