mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-27 19:36:00 +00:00
basic updates again working
This commit is contained in:
@@ -56,7 +56,9 @@ export default class ChangeSetGrider extends Grider {
|
|||||||
if (insertedRowIndex != null) status = 'inserted';
|
if (insertedRowIndex != null) status = 'inserted';
|
||||||
const rowStatus = {
|
const rowStatus = {
|
||||||
status,
|
status,
|
||||||
modifiedFields: new Set(matchedChangeSetItem ? Object.keys(matchedChangeSetItem.fields) : []),
|
modifiedFields: new Set(
|
||||||
|
matchedChangeSetItem && matchedChangeSetItem.fields ? Object.keys(matchedChangeSetItem.fields) : []
|
||||||
|
),
|
||||||
};
|
};
|
||||||
this.rowDataCache[index] = rowUpdated;
|
this.rowDataCache[index] = rowUpdated;
|
||||||
this.rowStatusCache[index] = rowStatus;
|
this.rowStatusCache[index] = rowStatus;
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ export default function DataGridCore(props) {
|
|||||||
exportGrid,
|
exportGrid,
|
||||||
allRowCount,
|
allRowCount,
|
||||||
openQuery,
|
openQuery,
|
||||||
|
onSave,
|
||||||
insertedRowCount,
|
insertedRowCount,
|
||||||
isLoading,
|
isLoading,
|
||||||
grider,
|
grider,
|
||||||
@@ -201,8 +202,6 @@ export default function DataGridCore(props) {
|
|||||||
const [tableBodyRef] = useDimensions();
|
const [tableBodyRef] = useDimensions();
|
||||||
const [containerRef, { height: containerHeight, width: containerWidth }] = useDimensions();
|
const [containerRef, { height: containerHeight, width: containerWidth }] = useDimensions();
|
||||||
// const [tableRef, { height: tableHeight, width: tableWidth }] = useDimensions();
|
// const [tableRef, { height: tableHeight, width: tableWidth }] = useDimensions();
|
||||||
const confirmSqlModalState = useModalState();
|
|
||||||
const [confirmSql, setConfirmSql] = React.useState('');
|
|
||||||
|
|
||||||
const changeSet = changeSetState && changeSetState.value;
|
const changeSet = changeSetState && changeSetState.value;
|
||||||
const setChangeSet = React.useCallback((value) => dispatchChangeSet({ type: 'set', value }), [dispatchChangeSet]);
|
const setChangeSet = React.useCallback((value) => dispatchChangeSet({ type: 'set', value }), [dispatchChangeSet]);
|
||||||
@@ -660,8 +659,13 @@ export default function DataGridCore(props) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function deleteSelectedRows() {
|
function deleteSelectedRows() {
|
||||||
const updatedChangeSet = getSelectedRowDefinitions().reduce((chs, row) => deleteChangeSetRows(chs, row), changeSet);
|
grider.beginUpdate();
|
||||||
setChangeSet(updatedChangeSet);
|
for (const index of getSelectedRowIndexes()) {
|
||||||
|
if (_.isNumber(index)) grider.deleteRow(index);
|
||||||
|
}
|
||||||
|
grider.endUpdate();
|
||||||
|
// const updatedChangeSet = getSelectedRowDefinitions().reduce((chs, row) => deleteChangeSetRows(chs, row), changeSet);
|
||||||
|
// setChangeSet(updatedChangeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleGridWheel(event) {
|
function handleGridWheel(event) {
|
||||||
@@ -698,33 +702,13 @@ export default function DataGridCore(props) {
|
|||||||
dispatchInsplaceEditor({ type: 'shouldSave' });
|
dispatchInsplaceEditor({ type: 'shouldSave' });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (onSave) onSave();
|
||||||
// const script = changeSetToSql(changeSetRef.current, display.dbinfo);
|
// const script = changeSetToSql(changeSetRef.current, display.dbinfo);
|
||||||
// const sql = scriptToSql(display.driver, script);
|
// const sql = scriptToSql(display.driver, script);
|
||||||
// setConfirmSql(sql);
|
// setConfirmSql(sql);
|
||||||
// confirmSqlModalState.open();
|
// confirmSqlModalState.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleConfirmSql() {
|
|
||||||
// const resp = await axios.request({
|
|
||||||
// url: 'database-connections/query-data',
|
|
||||||
// method: 'post',
|
|
||||||
// params: {
|
|
||||||
// conid,
|
|
||||||
// database,
|
|
||||||
// },
|
|
||||||
// data: { sql: confirmSql },
|
|
||||||
// });
|
|
||||||
// const { errorMessage } = resp.data || {};
|
|
||||||
// if (errorMessage) {
|
|
||||||
// showModal((modalState) => (
|
|
||||||
// <ErrorMessageModal modalState={modalState} message={errorMessage} title="Error when saving" />
|
|
||||||
// ));
|
|
||||||
// } else {
|
|
||||||
// dispatchChangeSet({ type: 'reset', value: createChangeSet() });
|
|
||||||
// setConfirmSql(null);
|
|
||||||
// display.reload();
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
const insertNewRow = () => {
|
const insertNewRow = () => {
|
||||||
if (display.baseTable) {
|
if (display.baseTable) {
|
||||||
@@ -1110,12 +1094,6 @@ export default function DataGridCore(props) {
|
|||||||
onScroll={handleRowScroll}
|
onScroll={handleRowScroll}
|
||||||
viewportRatio={visibleRowCountUpperBound / grider.rowCount}
|
viewportRatio={visibleRowCountUpperBound / grider.rowCount}
|
||||||
/>
|
/>
|
||||||
<ConfirmSqlModal
|
|
||||||
modalState={confirmSqlModalState}
|
|
||||||
sql={confirmSql}
|
|
||||||
engine={display.engine}
|
|
||||||
onConfirm={handleConfirmSql}
|
|
||||||
/>
|
|
||||||
{allRowCount && <RowCountLabel>{rowCountInfo}</RowCountLabel>}
|
{allRowCount && <RowCountLabel>{rowCountInfo}</RowCountLabel>}
|
||||||
{props.toolbarPortalRef &&
|
{props.toolbarPortalRef &&
|
||||||
tabVisible &&
|
tabVisible &&
|
||||||
|
|||||||
@@ -171,10 +171,10 @@ function DataGridRow(props) {
|
|||||||
inplaceEditorState,
|
inplaceEditorState,
|
||||||
dispatchInsplaceEditor,
|
dispatchInsplaceEditor,
|
||||||
// row,
|
// row,
|
||||||
display,
|
// display,
|
||||||
// changeSet,
|
// changeSet,
|
||||||
// setChangeSet,
|
// setChangeSet,
|
||||||
insertedRowIndex,
|
// insertedRowIndex,
|
||||||
autofillMarkerCell,
|
autofillMarkerCell,
|
||||||
selectedCells,
|
selectedCells,
|
||||||
autofillSelectedCells,
|
autofillSelectedCells,
|
||||||
@@ -236,7 +236,7 @@ function DataGridRow(props) {
|
|||||||
isModifiedRow={rowStatus.status == 'updated'}
|
isModifiedRow={rowStatus.status == 'updated'}
|
||||||
isFocusedColumn={col.uniqueName == focusedColumn}
|
isFocusedColumn={col.uniqueName == focusedColumn}
|
||||||
isModifiedCell={rowStatus.status == 'updated' && rowStatus.modifiedFields.has(col.uniqueName)}
|
isModifiedCell={rowStatus.status == 'updated' && rowStatus.modifiedFields.has(col.uniqueName)}
|
||||||
isInsertedRow={insertedRowIndex != null}
|
isInsertedRow={rowStatus.status == 'inserted'}
|
||||||
isDeletedRow={rowStatus.status == 'deleted'}
|
isDeletedRow={rowStatus.status == 'deleted'}
|
||||||
>
|
>
|
||||||
{inplaceEditorState.cell &&
|
{inplaceEditorState.cell &&
|
||||||
|
|||||||
@@ -5,10 +5,14 @@ import DataGridCore from './DataGridCore';
|
|||||||
import useSocket from '../utility/SocketProvider';
|
import useSocket from '../utility/SocketProvider';
|
||||||
import useShowModal from '../modals/showModal';
|
import useShowModal from '../modals/showModal';
|
||||||
import ImportExportModal from '../modals/ImportExportModal';
|
import ImportExportModal from '../modals/ImportExportModal';
|
||||||
import { getChangeSetInsertedRows } from '@dbgate/datalib';
|
import { changeSetToSql, createChangeSet, getChangeSetInsertedRows } from '@dbgate/datalib';
|
||||||
import { openNewTab } from '../utility/common';
|
import { openNewTab } from '../utility/common';
|
||||||
import LoadingDataGridCore from './LoadingDataGridCore';
|
import LoadingDataGridCore from './LoadingDataGridCore';
|
||||||
import ChangeSetGrider from './ChangeSetGrider';
|
import ChangeSetGrider from './ChangeSetGrider';
|
||||||
|
import { scriptToSql } from '@dbgate/sqltree';
|
||||||
|
import useModalState from '../modals/useModalState';
|
||||||
|
import ConfirmSqlModal from '../modals/ConfirmSqlModal';
|
||||||
|
import ErrorMessageModal from '../modals/ErrorMessageModal';
|
||||||
|
|
||||||
/** @param props {import('./types').DataGridProps} */
|
/** @param props {import('./types').DataGridProps} */
|
||||||
async function loadDataPage(props, offset, limit) {
|
async function loadDataPage(props, offset, limit) {
|
||||||
@@ -60,6 +64,13 @@ export default function SqlDataGridCore(props) {
|
|||||||
const showModal = useShowModal();
|
const showModal = useShowModal();
|
||||||
const setOpenedTabs = useSetOpenedTabs();
|
const setOpenedTabs = useSetOpenedTabs();
|
||||||
|
|
||||||
|
const confirmSqlModalState = useModalState();
|
||||||
|
const [confirmSql, setConfirmSql] = React.useState('');
|
||||||
|
|
||||||
|
const changeSet = changeSetState && changeSetState.value;
|
||||||
|
const changeSetRef = React.useRef(changeSet);
|
||||||
|
changeSetRef.current = changeSet;
|
||||||
|
|
||||||
function exportGrid() {
|
function exportGrid() {
|
||||||
const initialValues = {};
|
const initialValues = {};
|
||||||
initialValues.sourceStorageType = 'query';
|
initialValues.sourceStorageType = 'query';
|
||||||
@@ -84,18 +95,57 @@ export default function SqlDataGridCore(props) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleSave() {
|
||||||
|
const script = changeSetToSql(changeSetRef.current, display.dbinfo);
|
||||||
|
const sql = scriptToSql(display.driver, script);
|
||||||
|
setConfirmSql(sql);
|
||||||
|
confirmSqlModalState.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
async function handleConfirmSql() {
|
||||||
|
const resp = await axios.request({
|
||||||
|
url: 'database-connections/query-data',
|
||||||
|
method: 'post',
|
||||||
|
params: {
|
||||||
|
conid,
|
||||||
|
database,
|
||||||
|
},
|
||||||
|
data: { sql: confirmSql },
|
||||||
|
});
|
||||||
|
const { errorMessage } = resp.data || {};
|
||||||
|
if (errorMessage) {
|
||||||
|
showModal((modalState) => (
|
||||||
|
<ErrorMessageModal modalState={modalState} message={errorMessage} title="Error when saving" />
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
dispatchChangeSet({ type: 'reset', value: createChangeSet() });
|
||||||
|
setConfirmSql(null);
|
||||||
|
display.reload();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// const grider = React.useMemo(()=>new ChangeSetGrider())
|
// const grider = React.useMemo(()=>new ChangeSetGrider())
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<LoadingDataGridCore
|
<>
|
||||||
{...props}
|
<LoadingDataGridCore
|
||||||
exportGrid={exportGrid}
|
{...props}
|
||||||
openQuery={openQuery}
|
exportGrid={exportGrid}
|
||||||
loadDataPage={loadDataPage}
|
openQuery={openQuery}
|
||||||
dataPageAvailable={dataPageAvailable}
|
loadDataPage={loadDataPage}
|
||||||
loadRowCount={loadRowCount}
|
dataPageAvailable={dataPageAvailable}
|
||||||
griderFactory={ChangeSetGrider.factory}
|
loadRowCount={loadRowCount}
|
||||||
griderFactoryDeps={ChangeSetGrider.factoryDeps}
|
griderFactory={ChangeSetGrider.factory}
|
||||||
/>
|
griderFactoryDeps={ChangeSetGrider.factoryDeps}
|
||||||
|
changeSet={changeSetState && changeSetState.value}
|
||||||
|
onSave={handleSave}
|
||||||
|
/>
|
||||||
|
<ConfirmSqlModal
|
||||||
|
modalState={confirmSqlModalState}
|
||||||
|
sql={confirmSql}
|
||||||
|
engine={display.engine}
|
||||||
|
onConfirm={handleConfirmSql}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user