metadata loaders extended

This commit is contained in:
Jan Prochazka
2020-04-13 08:40:13 +02:00
parent 0eb4ce121e
commit fcbf8c0293
5 changed files with 45 additions and 38 deletions

View File

@@ -1,10 +1,7 @@
import React from 'react';
import useFetch from '../utility/useFetch';
import styled from 'styled-components';
import theme from '../theme';
import TableControl, { TableColumn } from './TableControl';
import { AppObjectControl } from '../appobj/AppObjects';
import columnAppObject from '../appobj/columnAppObject';
const ObjectListWrapper = styled.div`
margin-bottom: 20px;

View File

@@ -1,8 +1,6 @@
import React from 'react';
import _ from 'lodash';
import useFetch from '../utility/useFetch';
import styled from 'styled-components';
import theme from '../theme';
const Table = styled.table`
border-collapse: collapse;

View File

@@ -21,6 +21,24 @@ const connectionInfoLoader = ({ conid }) => ({
reloadTrigger: 'connection-list-changed',
});
const sqlObjectListLoader = ({ conid, database }) => ({
url: 'metadata/list-objects',
params: { conid, database },
reloadTrigger: `database-structure-changed-${conid}-${database}`,
});
const databaseListLoader = ({ conid }) => ({
url: 'server-connections/list-databases',
params: { conid },
reloadTrigger: `database-list-changed-${conid}`,
});
const connectionListLoader = () => ({
url: 'connections/list',
params: {},
reloadTrigger: `connection-list-changed`,
});
async function getCore(loader, args) {
const { url, params, reloadTrigger } = loader(args);
const key = stableStringify({ url, ...params });
@@ -86,21 +104,23 @@ export function useConnectionInfo(args) {
return useCore(connectionInfoLoader, args);
}
// 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;
// }
export function getSqlObjectList(args) {
return getCore(sqlObjectListLoader, args);
}
export function useSqlObjectList(args) {
return useCore(sqlObjectListLoader, args);
}
export function getDatabaseList(args) {
return getCore(databaseListLoader, args);
}
export function useDatabaseList(args) {
return useCore(databaseListLoader, args);
}
export function getConnectionList() {
return getCore(connectionListLoader, {});
}
export function useConnectionList() {
return useCore(connectionListLoader, {});
}