mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-18 00:56:02 +00:00
metadata loaders extended
This commit is contained in:
@@ -13,7 +13,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
emitChanged(key) {
|
emitChanged(key) {
|
||||||
console.log('EMIT_CHANGED:', key);
|
console.log('EMIT_CHANGED:', key);
|
||||||
socket.emit(key);
|
|
||||||
socket.emit('clean-cache', key);
|
socket.emit('clean-cache', key);
|
||||||
}
|
socket.emit(key);
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,10 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import useFetch from '../utility/useFetch';
|
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import theme from '../theme';
|
|
||||||
import TableControl, { TableColumn } from './TableControl';
|
import TableControl, { TableColumn } from './TableControl';
|
||||||
import { AppObjectControl } from '../appobj/AppObjects';
|
import { AppObjectControl } from '../appobj/AppObjects';
|
||||||
import columnAppObject from '../appobj/columnAppObject';
|
|
||||||
|
|
||||||
const ObjectListWrapper = styled.div`
|
const ObjectListWrapper = styled.div`
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import useFetch from '../utility/useFetch';
|
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import theme from '../theme';
|
|
||||||
|
|
||||||
const Table = styled.table`
|
const Table = styled.table`
|
||||||
border-collapse: collapse;
|
border-collapse: collapse;
|
||||||
|
|||||||
@@ -21,6 +21,24 @@ const connectionInfoLoader = ({ conid }) => ({
|
|||||||
reloadTrigger: 'connection-list-changed',
|
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) {
|
async function getCore(loader, args) {
|
||||||
const { url, params, reloadTrigger } = loader(args);
|
const { url, params, reloadTrigger } = loader(args);
|
||||||
const key = stableStringify({ url, ...params });
|
const key = stableStringify({ url, ...params });
|
||||||
@@ -86,21 +104,23 @@ export function useConnectionInfo(args) {
|
|||||||
return useCore(connectionInfoLoader, args);
|
return useCore(connectionInfoLoader, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
// export function useConnectionInfo(conid) {
|
export function getSqlObjectList(args) {
|
||||||
// /** @type {import('@dbgate/types').StoredConnection} */
|
return getCore(sqlObjectListLoader, args);
|
||||||
// const connection = useFetch({
|
}
|
||||||
// params: { conid },
|
export function useSqlObjectList(args) {
|
||||||
// url: 'connections/get',
|
return useCore(sqlObjectListLoader, args);
|
||||||
// });
|
}
|
||||||
// return connection;
|
|
||||||
// }
|
export function getDatabaseList(args) {
|
||||||
// export async function getConnectionInfo(conid) {
|
return getCore(databaseListLoader, args);
|
||||||
// const resp = await axios.request({
|
}
|
||||||
// method: 'get',
|
export function useDatabaseList(args) {
|
||||||
// params: { conid },
|
return useCore(databaseListLoader, args);
|
||||||
// url: 'connections/get',
|
}
|
||||||
// });
|
|
||||||
// /** @type {import('@dbgate/types').StoredConnection} */
|
export function getConnectionList() {
|
||||||
// const res = resp.data;
|
return getCore(connectionListLoader, {});
|
||||||
// return res;
|
}
|
||||||
// }
|
export function useConnectionList() {
|
||||||
|
return useCore(connectionListLoader, {});
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import React from 'react';
|
|||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
import useFetch from '../utility/useFetch';
|
|
||||||
import { AppObjectList } from '../appobj/AppObjectList';
|
import { AppObjectList } from '../appobj/AppObjectList';
|
||||||
import connectionAppObject from '../appobj/connectionAppObject';
|
import connectionAppObject from '../appobj/connectionAppObject';
|
||||||
import databaseAppObject from '../appobj/databaseAppObject';
|
import databaseAppObject from '../appobj/databaseAppObject';
|
||||||
@@ -11,6 +10,7 @@ import tableAppObject from '../appobj/tableAppObject';
|
|||||||
import theme from '../theme';
|
import theme from '../theme';
|
||||||
import InlineButton from './InlineButton';
|
import InlineButton from './InlineButton';
|
||||||
import databaseObjectAppObject from '../appobj/databaseObjectAppObject';
|
import databaseObjectAppObject from '../appobj/databaseObjectAppObject';
|
||||||
|
import { useSqlObjectList, useDatabaseList, useConnectionList } from '../utility/metadataLoaders';
|
||||||
|
|
||||||
const SearchBoxWrapper = styled.div`
|
const SearchBoxWrapper = styled.div`
|
||||||
display: flex;
|
display: flex;
|
||||||
@@ -55,10 +55,7 @@ function SubDatabaseList({ data }) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
const { _id } = data;
|
const { _id } = data;
|
||||||
const databases = useFetch({
|
const databases = useDatabaseList({ conid: _id });
|
||||||
url: `server-connections/list-databases?conid=${_id}`,
|
|
||||||
reloadTrigger: `database-list-changed-${_id}`,
|
|
||||||
});
|
|
||||||
return (
|
return (
|
||||||
<AppObjectList
|
<AppObjectList
|
||||||
list={(databases || []).map((db) => ({ ...db, connection: data }))}
|
list={(databases || []).map((db) => ({ ...db, connection: data }))}
|
||||||
@@ -69,10 +66,8 @@ function SubDatabaseList({ data }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function ConnectionList() {
|
function ConnectionList() {
|
||||||
const connections = useFetch({
|
const connections = useConnectionList();
|
||||||
url: 'connections/list',
|
|
||||||
reloadTrigger: 'connection-list-changed',
|
|
||||||
});
|
|
||||||
const [filter, setFilter] = React.useState('');
|
const [filter, setFilter] = React.useState('');
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -94,10 +89,7 @@ function ConnectionList() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function SqlObjectList({ conid, database }) {
|
function SqlObjectList({ conid, database }) {
|
||||||
const objects = useFetch({
|
const objects = useSqlObjectList({ conid, database });
|
||||||
url: `metadata/list-objects?conid=${conid}&database=${database}`,
|
|
||||||
reloadTrigger: `database-structure-changed-${conid}-${database}`,
|
|
||||||
});
|
|
||||||
|
|
||||||
const [filter, setFilter] = React.useState('');
|
const [filter, setFilter] = React.useState('');
|
||||||
const objectList = _.flatten(
|
const objectList = _.flatten(
|
||||||
|
|||||||
Reference in New Issue
Block a user