mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-30 04:33:57 +00:00
open selection in free table editor
This commit is contained in:
@@ -33,6 +33,10 @@ const menus = {
|
|||||||
label: 'Export',
|
label: 'Export',
|
||||||
isExport: true,
|
isExport: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Open in free table editor',
|
||||||
|
isOpenFreeTable: true,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
views: [
|
views: [
|
||||||
{
|
{
|
||||||
@@ -51,6 +55,10 @@ const menus = {
|
|||||||
label: 'Export',
|
label: 'Export',
|
||||||
isExport: true,
|
isExport: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Open in free table editor',
|
||||||
|
isOpenFreeTable: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'Open structure',
|
label: 'Open structure',
|
||||||
tab: 'TableStructureTab',
|
tab: 'TableStructureTab',
|
||||||
@@ -113,7 +121,7 @@ function Menu({ data, makeAppObj, setOpenedTabs, showModal }) {
|
|||||||
{menus[data.objectTypeField].map((menu) => (
|
{menus[data.objectTypeField].map((menu) => (
|
||||||
<DropDownMenuItem
|
<DropDownMenuItem
|
||||||
key={menu.label}
|
key={menu.label}
|
||||||
onClick={() => {
|
onClick={async () => {
|
||||||
if (menu.isExport) {
|
if (menu.isExport) {
|
||||||
showModal((modalState) => (
|
showModal((modalState) => (
|
||||||
<ImportExportModal
|
<ImportExportModal
|
||||||
@@ -127,6 +135,26 @@ function Menu({ data, makeAppObj, setOpenedTabs, showModal }) {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
} else if (menu.isOpenFreeTable) {
|
||||||
|
const coninfo = await getConnectionInfo(data);
|
||||||
|
openNewTab(setOpenedTabs, {
|
||||||
|
title: data.pureName,
|
||||||
|
icon: 'freetable.svg',
|
||||||
|
tabComponent: 'FreeTableTab',
|
||||||
|
props: {
|
||||||
|
initialData: {
|
||||||
|
functionName: 'tableReader',
|
||||||
|
props: {
|
||||||
|
connection: {
|
||||||
|
...coninfo,
|
||||||
|
database: data.database,
|
||||||
|
},
|
||||||
|
schemaName: data.schemaName,
|
||||||
|
pureName: data.pureName,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
openDatabaseObjectDetail(setOpenedTabs, menu.tab, menu.sqlTemplate, data);
|
openDatabaseObjectDetail(setOpenedTabs, menu.tab, menu.sqlTemplate, data);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ export default function DataGridContextMenu({
|
|||||||
exportGrid,
|
exportGrid,
|
||||||
filterSelectedValue,
|
filterSelectedValue,
|
||||||
openQuery,
|
openQuery,
|
||||||
|
openFreeTable,
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -34,11 +35,12 @@ export default function DataGridContextMenu({
|
|||||||
<DropDownMenuItem onClick={setNull} keyText="Ctrl+0">
|
<DropDownMenuItem onClick={setNull} keyText="Ctrl+0">
|
||||||
Set NULL
|
Set NULL
|
||||||
</DropDownMenuItem>
|
</DropDownMenuItem>
|
||||||
<DropDownMenuItem onClick={exportGrid}>Export</DropDownMenuItem>
|
{exportGrid && <DropDownMenuItem onClick={exportGrid}>Export</DropDownMenuItem>}
|
||||||
<DropDownMenuItem onClick={filterSelectedValue} keyText="Ctrl+F">
|
<DropDownMenuItem onClick={filterSelectedValue} keyText="Ctrl+F">
|
||||||
Filter selected value
|
Filter selected value
|
||||||
</DropDownMenuItem>
|
</DropDownMenuItem>
|
||||||
{openQuery && <DropDownMenuItem onClick={openQuery}>Open query</DropDownMenuItem>}
|
{openQuery && <DropDownMenuItem onClick={openQuery}>Open query</DropDownMenuItem>}
|
||||||
|
<DropDownMenuItem onClick={openFreeTable}>Open selection in free table editor</DropDownMenuItem>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ import { showMenu } from '../modals/DropDownMenu';
|
|||||||
import DataGridContextMenu from './DataGridContextMenu';
|
import DataGridContextMenu from './DataGridContextMenu';
|
||||||
import LoadingInfo from '../widgets/LoadingInfo';
|
import LoadingInfo from '../widgets/LoadingInfo';
|
||||||
import ErrorInfo from '../widgets/ErrorInfo';
|
import ErrorInfo from '../widgets/ErrorInfo';
|
||||||
|
import { openNewTab } from '../utility/common';
|
||||||
|
import { useSetOpenedTabs } from '../utility/globalState';
|
||||||
|
|
||||||
const GridContainer = styled.div`
|
const GridContainer = styled.div`
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@@ -110,6 +112,7 @@ export default function DataGridCore(props) {
|
|||||||
} = props;
|
} = props;
|
||||||
// console.log('RENDER GRID', display.baseTable.pureName);
|
// console.log('RENDER GRID', display.baseTable.pureName);
|
||||||
const columns = React.useMemo(() => display.allColumns, [display]);
|
const columns = React.useMemo(() => display.allColumns, [display]);
|
||||||
|
const setOpenedTabs = useSetOpenedTabs();
|
||||||
|
|
||||||
// usePropsCompare(props);
|
// usePropsCompare(props);
|
||||||
|
|
||||||
@@ -294,6 +297,24 @@ export default function DataGridCore(props) {
|
|||||||
setFirstVisibleColumnScrollIndex(value);
|
setFirstVisibleColumnScrollIndex(value);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleOpenFreeTable = () => {
|
||||||
|
const columns = getSelectedColumns();
|
||||||
|
const rows = getSelectedRowData().map((row) => _.pickBy(row, (v, col) => columns.find((x) => x.columnName == col)));
|
||||||
|
openNewTab(setOpenedTabs, {
|
||||||
|
title: 'selection',
|
||||||
|
icon: 'freetable.svg',
|
||||||
|
tabComponent: 'FreeTableTab',
|
||||||
|
props: {
|
||||||
|
initialData: {
|
||||||
|
structure: {
|
||||||
|
columns,
|
||||||
|
},
|
||||||
|
rows,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
const handleContextMenu = (event) => {
|
const handleContextMenu = (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
showMenu(
|
showMenu(
|
||||||
@@ -309,6 +330,7 @@ export default function DataGridCore(props) {
|
|||||||
exportGrid={exportGrid}
|
exportGrid={exportGrid}
|
||||||
filterSelectedValue={filterSelectedValue}
|
filterSelectedValue={filterSelectedValue}
|
||||||
openQuery={openQuery}
|
openQuery={openQuery}
|
||||||
|
openFreeTable={handleOpenFreeTable}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
@@ -499,13 +521,27 @@ export default function DataGridCore(props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getSelectedRowIndexes() {
|
function getSelectedRowIndexes() {
|
||||||
return _.uniq((selectedCells || []).map((x) => x[0]));
|
if (selectedCells.find((x) => x[0] == 'header')) return _.range(0, grider.rowCount);
|
||||||
|
return _.uniq((selectedCells || []).map((x) => x[0])).filter((x) => _.isNumber(x));
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSelectedColumnIndexes() {
|
||||||
|
if (selectedCells.find((x) => x[1] == 'header')) return _.range(0, realColumnUniqueNames.length);
|
||||||
|
return _.uniq((selectedCells || []).map((x) => x[1])).filter((x) => _.isNumber(x));
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSelectedRowData() {
|
function getSelectedRowData() {
|
||||||
return _.compact(getSelectedRowIndexes().map((index) => grider.getRowData(index)));
|
return _.compact(getSelectedRowIndexes().map((index) => grider.getRowData(index)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSelectedColumns() {
|
||||||
|
return _.compact(
|
||||||
|
getSelectedColumnIndexes().map((index) => ({
|
||||||
|
columnName: realColumnUniqueNames[index],
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function revertRowChanges() {
|
function revertRowChanges() {
|
||||||
grider.beginUpdate();
|
grider.beginUpdate();
|
||||||
for (const index of getSelectedRowIndexes()) {
|
for (const index of getSelectedRowIndexes()) {
|
||||||
|
|||||||
@@ -44,7 +44,9 @@ export default function FreeDataTab({ archiveFolder, archiveFile, tabVisible, to
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
dispatchModel({ type: 'reset', value });
|
dispatchModel({ type: 'reset', value });
|
||||||
} else if (initialData) {
|
} else if (initialData) {
|
||||||
handleLoadInitialData();
|
if (initialData.functionName) handleLoadInitialData();
|
||||||
|
// @ts-ignore
|
||||||
|
else dispatchModel({ type: 'reset', value: initialData });
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user