mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-26 21:25:59 +00:00
metadata loaders refactor
This commit is contained in:
@@ -2,7 +2,7 @@ import React from 'react';
|
|||||||
import { TableIcon } from '../icons';
|
import { TableIcon } from '../icons';
|
||||||
import { DropDownMenuItem } from '../modals/DropDownMenu';
|
import { DropDownMenuItem } from '../modals/DropDownMenu';
|
||||||
import { openNewTab } from '../utility/common';
|
import { openNewTab } from '../utility/common';
|
||||||
import getConnectionInfo from '../utility/getConnectionInfo';
|
import { getConnectionInfo } from '../utility/metadataLoaders';
|
||||||
import fullDisplayName from '../utility/fullDisplayName';
|
import fullDisplayName from '../utility/fullDisplayName';
|
||||||
import { filterName } from '@dbgate/datalib';
|
import { filterName } from '@dbgate/datalib';
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React from 'react';
|
|||||||
import { ViewIcon } from '../icons';
|
import { ViewIcon } from '../icons';
|
||||||
import { DropDownMenuItem } from '../modals/DropDownMenu';
|
import { DropDownMenuItem } from '../modals/DropDownMenu';
|
||||||
import { openNewTab } from '../utility/common';
|
import { openNewTab } from '../utility/common';
|
||||||
import getConnectionInfo from '../utility/getConnectionInfo';
|
import { getConnectionInfo } from '../utility/metadataLoaders';
|
||||||
import fullDisplayName from '../utility/fullDisplayName';
|
import fullDisplayName from '../utility/fullDisplayName';
|
||||||
import { filterName } from '@dbgate/datalib';
|
import { filterName } from '@dbgate/datalib';
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import React from 'react';
|
|||||||
import ReactDOM from 'react-dom';
|
import ReactDOM from 'react-dom';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import axios from '../utility/axios';
|
import axios from '../utility/axios';
|
||||||
import useConnectionInfo from '../utility/useConnectionInfo';
|
import { useConnectionInfo } from '../utility/metadataLoaders';
|
||||||
import SqlEditor from '../sqleditor/SqlEditor';
|
import SqlEditor from '../sqleditor/SqlEditor';
|
||||||
import { useUpdateDatabaseForTab } from '../utility/globalState';
|
import { useUpdateDatabaseForTab } from '../utility/globalState';
|
||||||
import QueryToolbar from '../query/QueryToolbar';
|
import QueryToolbar from '../query/QueryToolbar';
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import engines from '@dbgate/engines';
|
import engines from '@dbgate/engines';
|
||||||
import useTableInfo from '../utility/useTableInfo';
|
import { useTableInfo, useConnectionInfo } from '../utility/metadataLoaders';
|
||||||
import useConnectionInfo from '../utility/useConnectionInfo';
|
|
||||||
import SqlEditor from '../sqleditor/SqlEditor';
|
import SqlEditor from '../sqleditor/SqlEditor';
|
||||||
|
|
||||||
export default function TableCreateScriptTab({ conid, database, schemaName, pureName }) {
|
export default function TableCreateScriptTab({ conid, database, schemaName, pureName }) {
|
||||||
|
|||||||
@@ -4,10 +4,8 @@ import styled from 'styled-components';
|
|||||||
import theme from '../theme';
|
import theme from '../theme';
|
||||||
import DataGrid from '../datagrid/DataGrid';
|
import DataGrid from '../datagrid/DataGrid';
|
||||||
import { TableGridDisplay, createGridConfig, createGridCache, createChangeSet } from '@dbgate/datalib';
|
import { TableGridDisplay, createGridConfig, createGridCache, createChangeSet } from '@dbgate/datalib';
|
||||||
import useTableInfo from '../utility/useTableInfo';
|
import { useTableInfo, useConnectionInfo, getTableInfo } from '../utility/metadataLoaders';
|
||||||
import useConnectionInfo from '../utility/useConnectionInfo';
|
|
||||||
import engines from '@dbgate/engines';
|
import engines from '@dbgate/engines';
|
||||||
import getTableInfo from '../utility/getTableInfo';
|
|
||||||
import useUndoReducer from '../utility/useUndoReducer';
|
import useUndoReducer from '../utility/useUndoReducer';
|
||||||
import usePropsCompare from '../utility/usePropsCompare';
|
import usePropsCompare from '../utility/usePropsCompare';
|
||||||
import { useUpdateDatabaseForTab } from '../utility/globalState';
|
import { useUpdateDatabaseForTab } from '../utility/globalState';
|
||||||
@@ -26,7 +24,7 @@ export default function TableDataTab({ conid, database, schemaName, pureName, ta
|
|||||||
const display = React.useMemo(
|
const display = React.useMemo(
|
||||||
() =>
|
() =>
|
||||||
tableInfo && connection
|
tableInfo && connection
|
||||||
? new TableGridDisplay(tableInfo, engines(connection), config, setConfig, cache, setCache, name =>
|
? new TableGridDisplay(tableInfo, engines(connection), config, setConfig, cache, setCache, (name) =>
|
||||||
getTableInfo({ conid, database, ...name })
|
getTableInfo({ conid, database, ...name })
|
||||||
)
|
)
|
||||||
: null,
|
: null,
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import theme from '../theme';
|
|
||||||
import useFetch from '../utility/useFetch';
|
|
||||||
import ObjectListControl from '../utility/ObjectListControl';
|
import ObjectListControl from '../utility/ObjectListControl';
|
||||||
import { TableColumn } from '../utility/TableControl';
|
import { TableColumn } from '../utility/TableControl';
|
||||||
import columnAppObject from '../appobj/columnAppObject';
|
import columnAppObject from '../appobj/columnAppObject';
|
||||||
import constraintAppObject from '../appobj/constraintAppObject';
|
import constraintAppObject from '../appobj/constraintAppObject';
|
||||||
import useTableInfo from '../utility/useTableInfo';
|
import { useTableInfo } from '../utility/metadataLoaders';
|
||||||
|
|
||||||
const WhitePage = styled.div`
|
const WhitePage = styled.div`
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@@ -33,7 +31,7 @@ export default function TableStructureTab({ conid, database, schemaName, pureNam
|
|||||||
fieldName="notNull"
|
fieldName="notNull"
|
||||||
header="Not NULL"
|
header="Not NULL"
|
||||||
sortable={true}
|
sortable={true}
|
||||||
formatter={row => (row.notNull ? 'YES' : 'NO')}
|
formatter={(row) => (row.notNull ? 'YES' : 'NO')}
|
||||||
/>
|
/>
|
||||||
<TableColumn fieldName="dataType" header="Data Type" sortable={true} />
|
<TableColumn fieldName="dataType" header="Data Type" sortable={true} />
|
||||||
<TableColumn fieldName="defaultValue" header="Default value" sortable={true} />
|
<TableColumn fieldName="defaultValue" header="Default value" sortable={true} />
|
||||||
@@ -41,14 +39,14 @@ export default function TableStructureTab({ conid, database, schemaName, pureNam
|
|||||||
fieldName="isSparse"
|
fieldName="isSparse"
|
||||||
header="Is Sparse"
|
header="Is Sparse"
|
||||||
sortable={true}
|
sortable={true}
|
||||||
formatter={row => (row.isSparse ? 'YES' : 'NO')}
|
formatter={(row) => (row.isSparse ? 'YES' : 'NO')}
|
||||||
/>
|
/>
|
||||||
<TableColumn fieldName="computedExpression" header="Computed Expression" sortable={true} />
|
<TableColumn fieldName="computedExpression" header="Computed Expression" sortable={true} />
|
||||||
<TableColumn
|
<TableColumn
|
||||||
fieldName="isPersisted"
|
fieldName="isPersisted"
|
||||||
header="Is Persisted"
|
header="Is Persisted"
|
||||||
sortable={true}
|
sortable={true}
|
||||||
formatter={row => (row.isPersisted ? 'YES' : 'NO')}
|
formatter={(row) => (row.isPersisted ? 'YES' : 'NO')}
|
||||||
/>
|
/>
|
||||||
{/* {_.includes(dbCaps.columnListOptionalColumns, 'referencedTableNamesFormatted') && (
|
{/* {_.includes(dbCaps.columnListOptionalColumns, 'referencedTableNamesFormatted') && (
|
||||||
<TableColumn fieldName="referencedTableNamesFormatted" header="References" sortable={true} />
|
<TableColumn fieldName="referencedTableNamesFormatted" header="References" sortable={true} />
|
||||||
@@ -80,7 +78,7 @@ export default function TableStructureTab({ conid, database, schemaName, pureNam
|
|||||||
<TableColumn
|
<TableColumn
|
||||||
fieldName="columns"
|
fieldName="columns"
|
||||||
header="Columns"
|
header="Columns"
|
||||||
formatter={row => row.columns.map(x => x.columnName).join(', ')}
|
formatter={(row) => row.columns.map((x) => x.columnName).join(', ')}
|
||||||
/>
|
/>
|
||||||
</ObjectListControl>
|
</ObjectListControl>
|
||||||
|
|
||||||
@@ -88,13 +86,13 @@ export default function TableStructureTab({ conid, database, schemaName, pureNam
|
|||||||
<TableColumn
|
<TableColumn
|
||||||
fieldName="baseColumns"
|
fieldName="baseColumns"
|
||||||
header="Base columns"
|
header="Base columns"
|
||||||
formatter={row => row.columns.map(x => x.columnName).join(', ')}
|
formatter={(row) => row.columns.map((x) => x.columnName).join(', ')}
|
||||||
/>
|
/>
|
||||||
<TableColumn fieldName="refTable" header="Referenced table" formatter={row => row.refTableName} />
|
<TableColumn fieldName="refTable" header="Referenced table" formatter={(row) => row.refTableName} />
|
||||||
<TableColumn
|
<TableColumn
|
||||||
fieldName="refColumns"
|
fieldName="refColumns"
|
||||||
header="Referenced columns"
|
header="Referenced columns"
|
||||||
formatter={row => row.columns.map(x => x.refColumnName).join(', ')}
|
formatter={(row) => row.columns.map((x) => x.refColumnName).join(', ')}
|
||||||
/>
|
/>
|
||||||
<TableColumn fieldName="updateAction" header="ON UPDATE" />
|
<TableColumn fieldName="updateAction" header="ON UPDATE" />
|
||||||
<TableColumn fieldName="deleteAction" header="ON DELETE" />
|
<TableColumn fieldName="deleteAction" header="ON DELETE" />
|
||||||
@@ -104,13 +102,13 @@ export default function TableStructureTab({ conid, database, schemaName, pureNam
|
|||||||
<TableColumn
|
<TableColumn
|
||||||
fieldName="baseColumns"
|
fieldName="baseColumns"
|
||||||
header="Base columns"
|
header="Base columns"
|
||||||
formatter={row => row.columns.map(x => x.columnName).join(', ')}
|
formatter={(row) => row.columns.map((x) => x.columnName).join(', ')}
|
||||||
/>
|
/>
|
||||||
<TableColumn fieldName="baseTable" header="Base table" formatter={row => row.pureName} />
|
<TableColumn fieldName="baseTable" header="Base table" formatter={(row) => row.pureName} />
|
||||||
<TableColumn
|
<TableColumn
|
||||||
fieldName="refColumns"
|
fieldName="refColumns"
|
||||||
header="Referenced columns"
|
header="Referenced columns"
|
||||||
formatter={row => row.columns.map(x => x.refColumnName).join(', ')}
|
formatter={(row) => row.columns.map((x) => x.refColumnName).join(', ')}
|
||||||
/>
|
/>
|
||||||
<TableColumn fieldName="updateAction" header="ON UPDATE" />
|
<TableColumn fieldName="updateAction" header="ON UPDATE" />
|
||||||
<TableColumn fieldName="deleteAction" header="ON DELETE" />
|
<TableColumn fieldName="deleteAction" header="ON DELETE" />
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import useConnectionInfo from '../utility/useConnectionInfo';
|
import { useConnectionInfo, useViewInfo } from '../utility/metadataLoaders';
|
||||||
import SqlEditor from '../sqleditor/SqlEditor';
|
import SqlEditor from '../sqleditor/SqlEditor';
|
||||||
import useViewInfo from '../utility/useViewInfo';
|
|
||||||
|
|
||||||
export default function ViewCreateScriptTab({ conid, database, schemaName, pureName }) {
|
export default function ViewCreateScriptTab({ conid, database, schemaName, pureName }) {
|
||||||
const viewInfo = useViewInfo({ conid, database, schemaName, pureName });
|
const viewInfo = useViewInfo({ conid, database, schemaName, pureName });
|
||||||
|
|||||||
@@ -4,14 +4,11 @@ import styled from 'styled-components';
|
|||||||
import theme from '../theme';
|
import theme from '../theme';
|
||||||
import DataGrid from '../datagrid/DataGrid';
|
import DataGrid from '../datagrid/DataGrid';
|
||||||
import { ViewGridDisplay, createGridConfig, createGridCache, createChangeSet } from '@dbgate/datalib';
|
import { ViewGridDisplay, createGridConfig, createGridCache, createChangeSet } from '@dbgate/datalib';
|
||||||
import useTableInfo from '../utility/useTableInfo';
|
import { useConnectionInfo, useViewInfo } from '../utility/metadataLoaders';
|
||||||
import useConnectionInfo from '../utility/useConnectionInfo';
|
|
||||||
import engines from '@dbgate/engines';
|
import engines from '@dbgate/engines';
|
||||||
import getTableInfo from '../utility/getTableInfo';
|
|
||||||
import useUndoReducer from '../utility/useUndoReducer';
|
import useUndoReducer from '../utility/useUndoReducer';
|
||||||
import usePropsCompare from '../utility/usePropsCompare';
|
import usePropsCompare from '../utility/usePropsCompare';
|
||||||
import { useUpdateDatabaseForTab } from '../utility/globalState';
|
import { useUpdateDatabaseForTab } from '../utility/globalState';
|
||||||
import useViewInfo from '../utility/useViewInfo';
|
|
||||||
|
|
||||||
export default function ViewDataTab({ conid, database, schemaName, pureName, tabVisible, toolbarPortalRef }) {
|
export default function ViewDataTab({ conid, database, schemaName, pureName, tabVisible, toolbarPortalRef }) {
|
||||||
const viewInfo = useViewInfo({ conid, database, schemaName, pureName });
|
const viewInfo = useViewInfo({ conid, database, schemaName, pureName });
|
||||||
@@ -27,8 +24,7 @@ export default function ViewDataTab({ conid, database, schemaName, pureName, tab
|
|||||||
const display = React.useMemo(
|
const display = React.useMemo(
|
||||||
() =>
|
() =>
|
||||||
viewInfo && connection
|
viewInfo && connection
|
||||||
? new ViewGridDisplay(viewInfo, engines(connection), config, setConfig, cache, setCache,
|
? new ViewGridDisplay(viewInfo, engines(connection), config, setConfig, cache, setCache)
|
||||||
)
|
|
||||||
: null,
|
: null,
|
||||||
[viewInfo, connection, config, cache]
|
[viewInfo, connection, config, cache]
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
import axios from './axios';
|
|
||||||
|
|
||||||
export default async function getConnectionInfo(conid) {
|
|
||||||
const resp = await axios.request({
|
|
||||||
method: 'get',
|
|
||||||
params: { conid },
|
|
||||||
url: 'connections/get',
|
|
||||||
});
|
|
||||||
/** @type {import('@dbgate/types').StoredConnection} */
|
|
||||||
const res = resp.data;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import axios from './axios';
|
|
||||||
|
|
||||||
export default async function getTableInfo({ conid, database, schemaName, pureName }) {
|
|
||||||
const resp = await axios.request({
|
|
||||||
method: 'get',
|
|
||||||
url: 'metadata/table-info',
|
|
||||||
params: { conid, database, schemaName, pureName },
|
|
||||||
});
|
|
||||||
/** @type {import('@dbgate/types').TableInfo} */
|
|
||||||
const res = resp.data;
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import useStorage from './useStorage';
|
import useStorage from './useStorage';
|
||||||
import useConnectionInfo from './useConnectionInfo';
|
import { useConnectionInfo } from './metadataLoaders';
|
||||||
import usePrevious from './usePrevious';
|
import usePrevious from './usePrevious';
|
||||||
|
|
||||||
function createGlobalState(defaultValue) {
|
function createGlobalState(defaultValue) {
|
||||||
@@ -50,7 +50,7 @@ const [CurrentDatabaseProvider, useCurrentDatabase, useSetCurrentDatabaseCore] =
|
|||||||
function useSetCurrentDatabase() {
|
function useSetCurrentDatabase() {
|
||||||
const setDb = useSetCurrentDatabaseCore();
|
const setDb = useSetCurrentDatabaseCore();
|
||||||
const db = useCurrentDatabase();
|
const db = useCurrentDatabase();
|
||||||
return value => {
|
return (value) => {
|
||||||
if (_.get(db, 'name') !== _.get(value, 'name') || _.get(db, 'connection._id') != _.get(value, 'connection._id')) {
|
if (_.get(db, 'name') !== _.get(value, 'name') || _.get(db, 'connection._id') != _.get(value, 'connection._id')) {
|
||||||
setDb(value);
|
setDb(value);
|
||||||
}
|
}
|
||||||
|
|||||||
93
packages/web/src/utility/metadataLoaders.js
Normal file
93
packages/web/src/utility/metadataLoaders.js
Normal file
@@ -0,0 +1,93 @@
|
|||||||
|
import useFetch from './useFetch';
|
||||||
|
import axios from './axios';
|
||||||
|
|
||||||
|
// /** @returns {import('@dbgate/types').TableInfo} */
|
||||||
|
// function makeTableInfo(x) {
|
||||||
|
// return x;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// const tableInfoLoader = ({ conid, database, schemaName, pureName }) => ({
|
||||||
|
// url: 'metadata/table-info',
|
||||||
|
// params: { conid, database, schemaName, pureName },
|
||||||
|
// reloadTrigger: `database-structure-changed-${conid}-${database}`,
|
||||||
|
// type: makeTableInfo,
|
||||||
|
// });
|
||||||
|
|
||||||
|
// function createGet(loader) {
|
||||||
|
// return async (args) => {
|
||||||
|
// const { url, params, reloadTrigger, type } = loader(args);
|
||||||
|
// const resp = await axios.request({
|
||||||
|
// method: 'get',
|
||||||
|
// url,
|
||||||
|
// params,
|
||||||
|
// });
|
||||||
|
// return type(resp.data);
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
|
||||||
|
// function createUse(loader) {
|
||||||
|
// return async (args) => {
|
||||||
|
// const { url, params, reloadTrigger, type } = loader(args);
|
||||||
|
|
||||||
|
// const res = useFetch({
|
||||||
|
// url,
|
||||||
|
// params,
|
||||||
|
// reloadTrigger,
|
||||||
|
// });
|
||||||
|
// return type(res);
|
||||||
|
// };
|
||||||
|
// }
|
||||||
|
|
||||||
|
// export const getTableInfo = createGet(tableInfoLoader);
|
||||||
|
// export const useTableInfo = createUse(tableInfoLoader);
|
||||||
|
|
||||||
|
export async function getTableInfo({ conid, database, schemaName, pureName }) {
|
||||||
|
const resp = await axios.request({
|
||||||
|
method: 'get',
|
||||||
|
url: 'metadata/table-info',
|
||||||
|
params: { conid, database, schemaName, pureName },
|
||||||
|
});
|
||||||
|
/** @type {import('@dbgate/types').TableInfo} */
|
||||||
|
const res = resp.data;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useTableInfo({ conid, database, schemaName, pureName }) {
|
||||||
|
/** @type {import('@dbgate/types').TableInfo} */
|
||||||
|
const tableInfo = useFetch({
|
||||||
|
url: 'metadata/table-info',
|
||||||
|
params: { conid, database, schemaName, pureName },
|
||||||
|
reloadTrigger: `database-structure-changed-${conid}-${database}`,
|
||||||
|
});
|
||||||
|
return tableInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useViewInfo({ conid, database, schemaName, pureName }) {
|
||||||
|
/** @type {import('@dbgate/types').ViewInfo} */
|
||||||
|
const viewInfo = useFetch({
|
||||||
|
url: 'metadata/view-info',
|
||||||
|
params: { conid, database, schemaName, pureName },
|
||||||
|
reloadTrigger: `database-structure-changed-${conid}-${database}`,
|
||||||
|
});
|
||||||
|
return viewInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useConnectionInfo(conid) {
|
||||||
|
/** @type {import('@dbgate/types').StoredConnection} */
|
||||||
|
const connection = useFetch({
|
||||||
|
params: { conid },
|
||||||
|
url: 'connections/get',
|
||||||
|
});
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getConnectionInfo(conid) {
|
||||||
|
const resp = await axios.request({
|
||||||
|
method: 'get',
|
||||||
|
params: { conid },
|
||||||
|
url: 'connections/get',
|
||||||
|
});
|
||||||
|
/** @type {import('@dbgate/types').StoredConnection} */
|
||||||
|
const res = resp.data;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
import useFetch from './useFetch';
|
|
||||||
|
|
||||||
export default function useConnectionInfo(conid) {
|
|
||||||
/** @type {import('@dbgate/types').StoredConnection} */
|
|
||||||
const connection = useFetch({
|
|
||||||
params: { conid },
|
|
||||||
url: 'connections/get',
|
|
||||||
});
|
|
||||||
return connection;
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import useFetch from './useFetch';
|
|
||||||
|
|
||||||
export default function useTableInfo({ conid, database, schemaName, pureName }) {
|
|
||||||
/** @type {import('@dbgate/types').TableInfo} */
|
|
||||||
const tableInfo = useFetch({
|
|
||||||
url: 'metadata/table-info',
|
|
||||||
params: { conid, database, schemaName, pureName },
|
|
||||||
reloadTrigger: `database-structure-changed-${conid}-${database}`,
|
|
||||||
});
|
|
||||||
return tableInfo;
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
import useFetch from './useFetch';
|
|
||||||
|
|
||||||
export default function useViewInfo({ conid, database, schemaName, pureName }) {
|
|
||||||
/** @type {import('@dbgate/types').ViewInfo} */
|
|
||||||
const viewInfo = useFetch({
|
|
||||||
url: 'metadata/view-info',
|
|
||||||
params: { conid, database, schemaName, pureName },
|
|
||||||
reloadTrigger: `database-structure-changed-${conid}-${database}`,
|
|
||||||
});
|
|
||||||
return viewInfo;
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user