-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
784d572
commit df84790
Showing
14 changed files
with
299 additions
and
57 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,30 @@ | ||
<script setup lang="ts"> | ||
import { useMagicKeys, whenever } from '@vueuse/core' | ||
import { onBeforeUnmount, provide } from 'vue' | ||
import { WorkbookQuery } from '../types/workbook.types' | ||
import NativeQueryEditor from './components/NativeQueryEditor.vue' | ||
import useQuery from './query' | ||
import QueryBuilder from './components/QueryBuilder.vue' | ||
const props = defineProps<{ query: WorkbookQuery }>() | ||
const query = useQuery(props.query) | ||
provide('query', query) | ||
window.query = query | ||
query.execute() | ||
const keys = useMagicKeys() | ||
const cmdZ = keys['Meta+Z'] | ||
const cmdShiftZ = keys['Meta+Shift+Z'] | ||
const stopUndoWatcher = whenever(cmdZ, () => query.canUndo() && query.history.undo()) | ||
const stopRedoWatcher = whenever(cmdShiftZ, () => query.canRedo() && query.history.redo()) | ||
onBeforeUnmount(() => { | ||
stopUndoWatcher() | ||
stopRedoWatcher() | ||
}) | ||
</script> | ||
|
||
<template> | ||
<QueryBuilder v-if="query.doc.is_builder_query" /> | ||
<NativeQueryEditor v-else-if="query.doc.is_native_query" /> | ||
</template> |
This file was deleted.
Oops, something went wrong.
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,81 @@ | ||
<script setup lang="ts"> | ||
import { useTimeAgo } from '@vueuse/core' | ||
import { LoadingIndicator } from 'frappe-ui' | ||
import { Play, RefreshCw } from 'lucide-vue-next' | ||
import { computed, inject, ref } from 'vue' | ||
import Code from '../../components/Code.vue' | ||
import DataTable from '../../components/DataTable.vue' | ||
import { Query } from '../query' | ||
const query = inject<Query>('query')! | ||
const sql = ref<string>(query.getSQLQuery()) | ||
function execute() { | ||
query.setSQLQuery(sql.value, 'demo_data') | ||
} | ||
const columns = computed(() => query.result.columns) | ||
const rows = computed(() => query.result.formattedRows) | ||
const previewRowCount = computed(() => query.result.rows.length.toLocaleString()) | ||
const totalRowCount = computed(() => | ||
query.result.totalRowCount ? query.result.totalRowCount.toLocaleString() : '' | ||
) | ||
</script> | ||
|
||
<template> | ||
<div class="flex flex-1 flex-col gap-4 overflow-hidden p-4"> | ||
<div class="relative flex h-[55%] w-full flex-col rounded border"> | ||
<div class="flex-1"> | ||
<Code v-model="sql" /> | ||
</div> | ||
|
||
<div class="absolute bottom-2 left-10"> | ||
<Button class="h-8 w-8 bg-white shadow" variant="ghost" @click="execute"> | ||
<template #icon> | ||
<Play class="h-4 w-4 text-gray-700" stroke-width="1.5" /> | ||
</template> | ||
</Button> | ||
</div> | ||
</div> | ||
<div | ||
v-show="query.result.executedSQL" | ||
class="tnum flex flex-shrink-0 items-center gap-2 text-sm text-gray-600" | ||
> | ||
<div class="h-2 w-2 rounded-full bg-green-500"></div> | ||
<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 class="relative flex w-full flex-1 flex-col overflow-hidden rounded border"> | ||
<div | ||
v-if="query.executing" | ||
class="absolute top-10 z-10 flex w-full items-center justify-center rounded bg-gray-50/30 backdrop-blur-sm" | ||
> | ||
<LoadingIndicator class="h-8 w-8 text-gray-700" /> | ||
</div> | ||
|
||
<DataTable :columns="columns" :rows="rows" :on-export="query.downloadResults"> | ||
<template #footer-left> | ||
<div class="tnum flex items-center gap-2 text-sm text-gray-600"> | ||
<span> Showing {{ previewRowCount }} of </span> | ||
<span v-if="!totalRowCount" class="inline-block"> | ||
<Tooltip text="Load Count"> | ||
<RefreshCw | ||
v-if="!query.fetchingCount" | ||
class="h-3.5 w-3.5 cursor-pointer transition-all hover:text-gray-800" | ||
stroke-width="1.5" | ||
@click="query.fetchResultCount" | ||
/> | ||
<LoadingIndicator v-else class="h-3.5 w-3.5 text-gray-600" /> | ||
</Tooltip> | ||
</span> | ||
<span v-else> {{ totalRowCount }} </span> | ||
rows | ||
</div> | ||
</template> | ||
</DataTable> | ||
</div> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<script setup lang="ts"> | ||
import { inject } from 'vue' | ||
import { Query } from '../query' | ||
import QueryBuilderSourceSelector from './QueryBuilderSourceSelector.vue' | ||
import QueryBuilderTable from './QueryBuilderTable.vue' | ||
import QueryBuilderToolbar from './QueryBuilderToolbar.vue' | ||
import QueryInfo from './QueryInfo.vue' | ||
import QueryOperations from './QueryOperations.vue' | ||
const query = inject<Query>('query')! | ||
</script> | ||
|
||
<template> | ||
<div class="flex flex-1 overflow-hidden"> | ||
<div class="relative flex h-full flex-1 flex-col gap-3 overflow-hidden p-4"> | ||
<QueryBuilderSourceSelector v-if="!query.doc.operations.length" /> | ||
<template v-else> | ||
<QueryBuilderToolbar></QueryBuilderToolbar> | ||
<QueryBuilderTable></QueryBuilderTable> | ||
</template> | ||
</div> | ||
<div | ||
class="relative z-[1] flex h-full w-[19rem] flex-shrink-0 flex-col overflow-y-auto bg-white" | ||
> | ||
<QueryInfo /> | ||
<QueryOperations /> | ||
</div> | ||
</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
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 |
---|---|---|
@@ -1,14 +1,30 @@ | ||
<script setup lang="ts"> | ||
import { computed, inject } from 'vue' | ||
import QueryBuilder from '../query/QueryBuilder.vue' | ||
import Query from '../query/Query.vue' | ||
import { Workbook, workbookKey } from './workbook' | ||
import WorkbookQueryEmptyState from './WorkbookQueryEmptyState.vue' | ||
const props = defineProps<{ name?: string; index: number | string }>() | ||
const workbook = inject<Workbook>(workbookKey) | ||
const activeQuery = computed(() => workbook?.doc.queries[Number(props.index)]) | ||
const typeIsSet = computed( | ||
() => | ||
activeQuery.value?.is_native_query || | ||
activeQuery.value?.is_script_query || | ||
activeQuery.value?.is_builder_query | ||
) | ||
function setQueryType(interfaceType: 'query-builder' | 'sql-editor' | 'script-editor') { | ||
if (!activeQuery.value) return | ||
activeQuery.value.is_native_query = interfaceType === 'sql-editor' | ||
activeQuery.value.is_script_query = interfaceType === 'script-editor' | ||
activeQuery.value.is_builder_query = interfaceType === 'query-builder' | ||
} | ||
</script> | ||
|
||
<template> | ||
<QueryBuilder v-if="activeQuery" :key="activeQuery.name" :query="activeQuery" /> | ||
<WorkbookQueryEmptyState v-if="activeQuery && !typeIsSet" @select="setQueryType" /> | ||
<Query v-if="activeQuery && typeIsSet" :key="activeQuery.name" :query="activeQuery" /> | ||
</template> |
Oops, something went wrong.