dbgate/packages/web/src/perspectives/PerspectiveView.svelte

99 lines
2.9 KiB
Svelte
Raw Normal View History

2022-06-12 17:30:54 +00:00
<script lang="ts">
2022-06-20 20:14:48 +00:00
import {
getTableChildPerspectiveNodes,
PerspectiveDataLoadProps,
PerspectiveDataProvider,
2022-06-20 20:14:48 +00:00
PerspectiveTableColumnNode,
PerspectiveTableNode,
} from 'dbgate-datalib';
2022-06-16 15:05:42 +00:00
2022-06-12 17:30:54 +00:00
import _ from 'lodash';
import HorizontalSplitter from '../elements/HorizontalSplitter.svelte';
2022-06-17 20:30:10 +00:00
import { useDatabaseInfo, useTableInfo, useViewInfo } from '../utility/metadataLoaders';
2022-07-21 10:33:29 +00:00
import debug from 'debug';
2022-06-12 17:30:54 +00:00
import { getLocalStorage, setLocalStorage } from '../utility/storageCache';
import WidgetColumnBar from '../widgets/WidgetColumnBar.svelte';
import WidgetColumnBarItem from '../widgets/WidgetColumnBarItem.svelte';
2022-06-18 06:46:40 +00:00
import PerspectiveTree from './PerspectiveTree.svelte';
2022-06-20 20:14:48 +00:00
import PerspectiveTable from './PerspectiveTable.svelte';
import { apiCall } from '../utility/api';
import { Select } from 'dbgate-sqltree';
import ManagerInnerContainer from '../elements/ManagerInnerContainer.svelte';
2022-07-21 10:33:29 +00:00
import { PerspectiveDataLoader } from 'dbgate-datalib/lib/PerspectiveDataLoader';
2022-07-21 13:43:17 +00:00
import stableStringify from 'json-stable-stringify';
import createRef from '../utility/createRef';
import { tick } from 'svelte';
2022-07-21 10:33:29 +00:00
const dbg = debug('dbgate:PerspectiveView');
2022-06-12 17:30:54 +00:00
export let conid;
export let database;
export let schemaName;
export let pureName;
2022-06-16 15:05:42 +00:00
export let config;
export let setConfig;
2022-07-21 15:05:07 +00:00
export let loadedCounts;
2022-06-16 15:05:42 +00:00
export let cache;
2022-06-12 17:30:54 +00:00
let managerSize;
2022-07-21 13:43:17 +00:00
let nextCacheRef = createRef(null);
2022-06-12 17:30:54 +00:00
$: if (managerSize) setLocalStorage('perspectiveManagerWidth', managerSize);
function getInitialManagerSize() {
const width = getLocalStorage('perspectiveManagerWidth');
if (_.isNumber(width) && width > 30 && width < 500) {
return `${width}px`;
}
return '300px';
}
2022-06-17 20:30:10 +00:00
const dbInfo = useDatabaseInfo({ conid, database });
2022-06-12 17:30:54 +00:00
const tableInfo = useTableInfo({ conid, database, schemaName, pureName });
const viewInfo = useViewInfo({ conid, database, schemaName, pureName });
2022-07-21 13:43:17 +00:00
$: dataProvider = new PerspectiveDataProvider(cache, loader);
$: loader = new PerspectiveDataLoader(apiCall);
2022-07-21 10:33:29 +00:00
$: root = $tableInfo
2022-07-21 15:05:07 +00:00
? new PerspectiveTableNode(
$tableInfo,
$dbInfo,
config,
setConfig,
dataProvider,
{ conid, database },
null
)
2022-07-21 10:33:29 +00:00
: null;
2022-06-12 17:30:54 +00:00
</script>
<HorizontalSplitter initialValue={getInitialManagerSize()} bind:size={managerSize}>
<div class="left" slot="1">
<WidgetColumnBar>
2022-06-18 06:46:40 +00:00
<WidgetColumnBarItem title="Choose data" name="perspectiveTree" height="45%">
2022-06-30 19:14:56 +00:00
<ManagerInnerContainer width={managerSize}>
{#if root}
<PerspectiveTree {root} />
{/if}
</ManagerInnerContainer>
2022-06-12 17:30:54 +00:00
</WidgetColumnBarItem>
</WidgetColumnBar>
</div>
<svelte:fragment slot="2">
<PerspectiveTable {root} {loadedCounts} {setConfig} />
2022-06-12 17:30:54 +00:00
</svelte:fragment>
</HorizontalSplitter>
<style>
.left {
display: flex;
flex: 1;
background-color: var(--theme-bg-0);
}
</style>