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

@ -13,7 +13,7 @@ module.exports = {
},
emitChanged(key) {
console.log('EMIT_CHANGED:', key);
socket.emit(key);
socket.emit('clean-cache', key);
}
socket.emit(key);
},
};

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, {});
}

View File

@ -2,7 +2,6 @@ import React from 'react';
import styled from 'styled-components';
import _ from 'lodash';
import useFetch from '../utility/useFetch';
import { AppObjectList } from '../appobj/AppObjectList';
import connectionAppObject from '../appobj/connectionAppObject';
import databaseAppObject from '../appobj/databaseAppObject';
@ -11,6 +10,7 @@ import tableAppObject from '../appobj/tableAppObject';
import theme from '../theme';
import InlineButton from './InlineButton';
import databaseObjectAppObject from '../appobj/databaseObjectAppObject';
import { useSqlObjectList, useDatabaseList, useConnectionList } from '../utility/metadataLoaders';
const SearchBoxWrapper = styled.div`
display: flex;
@ -55,10 +55,7 @@ function SubDatabaseList({ data }) {
});
};
const { _id } = data;
const databases = useFetch({
url: `server-connections/list-databases?conid=${_id}`,
reloadTrigger: `database-list-changed-${_id}`,
});
const databases = useDatabaseList({ conid: _id });
return (
<AppObjectList
list={(databases || []).map((db) => ({ ...db, connection: data }))}
@ -69,10 +66,8 @@ function SubDatabaseList({ data }) {
}
function ConnectionList() {
const connections = useFetch({
url: 'connections/list',
reloadTrigger: 'connection-list-changed',
});
const connections = useConnectionList();
const [filter, setFilter] = React.useState('');
return (
<>
@ -94,10 +89,7 @@ function ConnectionList() {
}
function SqlObjectList({ conid, database }) {
const objects = useFetch({
url: `metadata/list-objects?conid=${conid}&database=${database}`,
reloadTrigger: `database-structure-changed-${conid}-${database}`,
});
const objects = useSqlObjectList({ conid, database });
const [filter, setFilter] = React.useState('');
const objectList = _.flatten(