Skip to content

Commit

Permalink
chore: merge develop into version-3
Browse files Browse the repository at this point in the history
  • Loading branch information
nextchamp-saqib committed Nov 10, 2024
2 parents 5346e14 + a6ec1e6 commit 7b3c73c
Show file tree
Hide file tree
Showing 21 changed files with 137 additions and 78 deletions.
13 changes: 9 additions & 4 deletions frontend/src2/charts/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,15 @@ function getSerie(config: AxisChartConfig, number_column: string): Series {
)
}
}
if (!serie) {
throw new Error(`Cannot find series for column ${number_column}`)
}
return serie

return (
serie ||
({
measure: {
measure_name: number_column,
},
} as Series)
)
}

type XAxisCustomizeOptions = {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src2/components/Autocomplete.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
v-if="groups.length == 0"
class="rounded-md px-2.5 py-1.5 text-base text-gray-600"
>
No results found
No options available
</li>
</ComboboxOptions>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src2/components/DraggableList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function onChange(e) {
</Draggable>
<template v-if="showEmptyState && !items?.length">
<div
class="flex h-12 flex-col items-center justify-center rounded border border-dashed border-gray-300 py-2"
class="flex h-full flex-col items-center justify-center rounded border border-dashed border-gray-300 py-2"
>
<div class="text-xs text-gray-500">{{ props.emptyText }}</div>
</div>
Expand Down
10 changes: 7 additions & 3 deletions frontend/src2/components/Navbar.vue
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<script setup lang="ts"></script>
<script setup lang="ts">
import { useRouter } from 'vue-router'
const router = useRouter()
</script>

<template>
<div
Expand All @@ -7,9 +11,9 @@
<div class="relative flex flex-1 items-center">
<div class="absolute left-0">
<slot name="left">
<router-link :to="{ path: '/' }">
<button @click="router.back()" class="flex items-center gap-1">
<img src="../assets/insights-logo-new.svg" alt="logo" class="h-7 rounded" />
</router-link>
</button>
</slot>
</div>
<div class="flex flex-1 items-center justify-center">
Expand Down
23 changes: 13 additions & 10 deletions frontend/src2/data_source/DataSourceTableList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import useTableStore, { DataSourceTable } from './tables'
const props = defineProps<{ name: string }>()
const dataSource = useDataSourceStore().getSource(props.name)
const tableStore = useTableStore()
const searchQuery = ref('')
Expand Down Expand Up @@ -61,7 +62,7 @@ watchEffect(() => {
<Breadcrumbs
:items="[
{ label: 'Data Sources', route: '/data-source' },
{ label: props.name, route: `/data-source/${props.name}` },
{ label: dataSource?.title || props.name, route: `/data-source/${props.name}` },
]"
/>
<div class="flex items-center gap-2"></div>
Expand All @@ -88,15 +89,17 @@ watchEffect(() => {
'stroke-width': '1.5',
}),
},
{
label: 'Update Table Links',
onClick: () => tableStore.updateTableLinks(props.name),
icon: () =>
h(RefreshCcw, {
class: 'h-4 w-4 text-gray-700',
'stroke-width': '1.5',
}),
},
dataSource?.is_frappe_db
? {
label: 'Update Table Links',
onClick: () => tableStore.updateTableLinks(props.name),
icon: () =>
h(RefreshCcw, {
class: 'h-4 w-4 text-gray-700',
'stroke-width': '1.5',
}),
}
: null,
]"
>
<Button>
Expand Down
2 changes: 2 additions & 0 deletions frontend/src2/data_source/data_source.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export type DataSourceListItem = {
owner: string
status: 'Active' | 'Inactive'
database_type: DatabaseType
is_frappe_db: boolean
is_site_db: boolean
creation: string
modified: string
created_from_now: string
Expand Down
27 changes: 19 additions & 8 deletions frontend/src2/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,15 @@ export function store<T>(key: string, value: () => T) {
}

export function getErrorMessage(err: any) {
return err.exc?.split('\n').filter(Boolean).at(-1)
const lastLine = err.exc
?.split('\n')
.filter(Boolean)
.at(-1)
?.trim()
.split(': ')
.slice(1)
.join(': ')
return lastLine || err.message || err.toString()
}

export function showErrorToast(err: Error, raise = true) {
Expand Down Expand Up @@ -251,6 +259,7 @@ export function ellipsis(value: string, length: number) {
export function flattenOptions(
options: DropdownOption[] | GroupedDropdownOption[]
): DropdownOption[] {
if (!options.length) return []
return 'group' in options[0]
? (options as GroupedDropdownOption[]).map((c) => c.items).flat()
: (options as DropdownOption[])
Expand All @@ -273,11 +282,13 @@ export function toOptions(arr: any[], map: Record<OptionKey, string>) {

export function sanitizeColumnName(name: string) {
return name
.replace(' ', '_')
.replace('-', '_')
.replace('.', '_')
.replace('/', '_')
.replace('(', '_')
.replace(')', '_')
.toLowerCase()
? name
.replace(' ', '_')
.replace('-', '_')
.replace('.', '_')
.replace('/', '_')
.replace('(', '_')
.replace(')', '_')
.toLowerCase()
: name
}
65 changes: 37 additions & 28 deletions frontend/src2/query/components/ColumnsSelectorDialog.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { SearchIcon } from 'lucide-vue-next'
import { ChevronDown, SearchIcon } from 'lucide-vue-next'
import { computed, inject, ref } from 'vue'
import DraggableList from '../../components/DraggableList.vue'
import { QueryResultColumn, SelectArgs } from '../../types/query.types'
Expand All @@ -21,20 +21,18 @@ query.getColumnsForSelection().then((cols: ColumnOption[]) => {
})
const columns = ref<HTMLElement | null>(null)
function addColumn(column: ColumnOption) {
if (!column?.value) return
if (!selectedColumns.value.find((c) => c.name === column.value)) {
selectedColumns.value.push({
name: column.value,
type: column.data_type,
function addColumns(options: ColumnOption[]) {
selectedColumns.value = options.map((o) => ({
name: o.value,
type: o.data_type,
}))
setTimeout(() => {
columns.value?.scrollTo({
top: columns.value.scrollHeight,
behavior: 'smooth',
})
setTimeout(() => {
columns.value?.scrollTo({
top: columns.value.scrollHeight,
behavior: 'smooth',
})
}, 100)
}
}, 100)
}
const confirmDisabled = computed(
Expand Down Expand Up @@ -75,26 +73,37 @@ function confirmSelection() {
}"
>
<template #body-content>
<div class="-mb-7 flex max-h-[22rem] flex-col gap-4 p-0.5 text-base">
<div class="-mb-7 flex h-[22rem] flex-col p-0.5 text-base">
<Autocomplete
:options="
columnOptions.filter(
(c) => !selectedColumns.find((sc) => sc.name === c.value)
)
"
class="flex-shrink-0"
:multiple="true"
:options="columnOptions"
placeholder="Add column"
@update:modelValue="addColumn"
:modelValue="selectedColumns.map((c) => c.name)"
@update:modelValue="addColumns"
>
<template #prefix>
<SearchIcon class="h-4 w-4 text-gray-500" stroke-width="1.5" />
<template #target="{ togglePopover }">
<Button class="w-full !justify-start" @click="togglePopover">
<template #prefix>
<SearchIcon class="h-4 w-4 text-gray-500" stroke-width="1.5" />
</template>
<span class="flex-1 text-gray-500">Add column</span>
<template #suffix>
<ChevronDown
class="ml-auto h-4 w-4 text-gray-500"
stroke-width="1.5"
/>
</template>
</Button>
</template>
</Autocomplete>

<div ref="columns" class="relative overflow-y-scroll">
<div ref="columns" class="relative mt-4 flex-1 overflow-y-scroll">
<DraggableList
v-model:items="selectedColumns"
:item-key="'name'"
group="columns"
empty-text="No columns selected"
>
<template #item-content="{ item }">
<div class="flex items-center gap-1.5">
Expand All @@ -103,11 +112,11 @@ function confirmSelection() {
</div>
</template>
</DraggableList>

<p class="sticky bottom-0 bg-white pt-1.5 text-sm text-gray-500">
{{ selectedColumns.length }} columns selected
</p>
</div>

<p class="flex-shrink-0 bg-white pt-1.5 text-sm text-gray-500">
{{ selectedColumns.length }} columns selected
</p>
</div>
</template>
</Dialog>
Expand Down
8 changes: 6 additions & 2 deletions frontend/src2/query/components/QueryBuilderToolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { PlayIcon, Scroll } from 'lucide-vue-next'
import { inject, ref } from 'vue'
import { Query } from '../query'
import ViewSQLDialog from './ViewSQLDialog.vue'
import { useTimeAgo } from '@vueuse/core'
const query = inject('query') as Query
Expand Down Expand Up @@ -34,8 +35,11 @@ const actions = [
class="tnum flex items-center gap-2 text-sm text-gray-600"
>
<div class="h-2 w-2 rounded-full bg-green-500"></div>
<span v-if="query.result.timeTaken == -1"> Fetched from cache </span>
<span v-else> Fetched in {{ query.result.timeTaken }} ms </span>
<div>
<span v-if="query.result.timeTaken == -1"> Fetched from cache </span>
<span v-else> Fetched in {{ query.result.timeTaken }}s </span>
<span> {{ useTimeAgo(query.result.lastExecutedAt).value }} </span>
</div>
</div>
</div>
<div class="flex items-center gap-2">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ wheneverChanges(
dataSourceStore.getSources().then(() => {
tabGroups.value[0].tabs = dataSourceStore.sources
.map((source) => ({
label: source.name,
label: source.title,
icon: DatabaseIcon,
component: () => (
<DataSourceTableList
Expand Down
2 changes: 2 additions & 0 deletions frontend/src2/query/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ export function makeQuery(workbookQuery: WorkbookQuery) {
data_type: column.type,
}))
query.result.timeTaken = response.time_taken
query.result.lastExecutedAt = new Date()
})
.catch((e: Error) => {
query.result = { ...EMPTY_RESULT }
Expand Down Expand Up @@ -737,6 +738,7 @@ const EMPTY_RESULT = {
columns: [],
columnOptions: [],
timeTaken: 0,
lastExecutedAt: new Date(),
} as QueryResult

export type Query = ReturnType<typeof makeQuery>
2 changes: 1 addition & 1 deletion frontend/src2/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const routes = [
{
path: '/',
name: 'Home',
redirect: '/workbook',
redirect: '/dashboards',
component: () => import('./home/Home.vue'),
},
{
Expand Down
1 change: 1 addition & 0 deletions frontend/src2/types/query.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,5 @@ export type QueryResult = {
columns: QueryResultColumn[]
columnOptions: ColumnOption[]
timeTaken: number
lastExecutedAt: Date
}
5 changes: 3 additions & 2 deletions frontend/src2/workbook/workbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ import type {
export default function useWorkbook(name: string) {
const workbook = getWorkbookResource(name)

const router = useRouter()
workbook.onAfterInsert(() => {
window.location.href = window.location.href.replace(name, workbook.doc.name)
const href = window.location.href.replace(name, workbook.doc.name)
window.location.replace(href)
})
workbook.onAfterSave(() => createToast({ title: 'Saved', variant: 'success' }))

Expand All @@ -41,6 +41,7 @@ export default function useWorkbook(name: string) {
}
)

const router = useRouter()
function setActiveTab(type: 'query' | 'chart' | 'dashboard' | '', idx: number) {
router.replace(
type ? `/workbook/${workbook.name}/${type}/${idx}` : `/workbook/${workbook.name}`
Expand Down
2 changes: 2 additions & 0 deletions insights/api/data_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ def get_all_data_sources():
"status",
"title",
"owner",
"is_frappe_db",
"is_site_db",
"creation",
"modified",
"database_type",
Expand Down
2 changes: 2 additions & 0 deletions insights/fixtures/insights_data_source_v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
"title": "Site DB",
"status": "Active",
"database_type": "MariaDB",
"owner": "Administrator",
"modified_by": "Administrator",
"modified": "2022-01-01 00:01:00.000000",
"creation": "2022-01-01 00:01:00.000000"
}
Expand Down
2 changes: 1 addition & 1 deletion insights/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
},
{
"dt": "Insights Data Source v3",
"filters": {"name": ("in", ["Site DB"])},
"filters": {"name": "Site DB"},
},
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
f_group_concat = lambda column, *args, **kwargs: column.group_concat(*args, **kwargs)
f_is_in = lambda column, *values: column.isin(values)
f_is_not_in = lambda column, *values: column.notin(values)
f_is_set = lambda column: f_coalesce(column, "") != ""
f_is_not_set = lambda column: f_coalesce(column, "") == ""
f_is_set = lambda column: column.notnull()
f_is_not_set = lambda column: column.isnull()
f_is_between = lambda column, start, end: column.between(start, end)
f_is_not_between = lambda column, start, end: ~column.between(start, end)
f_distinct_count = lambda column: column.nunique()
Expand Down
Loading

0 comments on commit 7b3c73c

Please sign in to comment.