mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-23 06:56:01 +00:00
toolbar
This commit is contained in:
@@ -304,3 +304,7 @@ export function changeSetInsertNewRow(changeSet: ChangeSet, name?: NamedObjectIn
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function changeSetContainsChanges(changeSet: ChangeSet) {
|
||||||
|
return changeSet.deletes.length > 0 || changeSet.updates.length > 0 || changeSet.inserts.length > 0;
|
||||||
|
}
|
||||||
|
|||||||
@@ -510,6 +510,10 @@ export default function DataGridCore(props) {
|
|||||||
setChangeSet(updatedChangeSet);
|
setChangeSet(updatedChangeSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function revertAllChanges() {
|
||||||
|
setChangeSet(createChangeSet());
|
||||||
|
}
|
||||||
|
|
||||||
function deleteCurrentRow() {
|
function deleteCurrentRow() {
|
||||||
const updatedChangeSet = getSelectedRowDefinitions().reduce((chs, row) => deleteChangeSetRows(chs, row), changeSet);
|
const updatedChangeSet = getSelectedRowDefinitions().reduce((chs, row) => deleteChangeSetRows(chs, row), changeSet);
|
||||||
setChangeSet(updatedChangeSet);
|
setChangeSet(updatedChangeSet);
|
||||||
@@ -910,7 +914,16 @@ export default function DataGridCore(props) {
|
|||||||
/>
|
/>
|
||||||
{props.toolbarPortalRef &&
|
{props.toolbarPortalRef &&
|
||||||
tabVisible &&
|
tabVisible &&
|
||||||
ReactDOM.createPortal(<DataGridToolbar reload={reload} />, props.toolbarPortalRef.current)}
|
ReactDOM.createPortal(
|
||||||
|
<DataGridToolbar
|
||||||
|
reload={reload}
|
||||||
|
save={handleSave}
|
||||||
|
changeSetState={changeSetState}
|
||||||
|
dispatchChangeSet={dispatchChangeSet}
|
||||||
|
revert={revertAllChanges}
|
||||||
|
/>,
|
||||||
|
props.toolbarPortalRef.current
|
||||||
|
)}
|
||||||
</GridContainer>
|
</GridContainer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,19 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { ToolbarButton } from '../widgets/Toolbar';
|
import { ToolbarButton } from '../widgets/Toolbar';
|
||||||
|
import { changeSetContainsChanges } from '@dbgate/datalib';
|
||||||
|
|
||||||
export default function DataGridToolbar({ reload }) {
|
export default function DataGridToolbar({ reload, changeSetState, dispatchChangeSet, save, revert }) {
|
||||||
return <ToolbarButton onClick={reload}>Refresh</ToolbarButton>;
|
return (
|
||||||
|
<>
|
||||||
|
{changeSetState.canUndo && (
|
||||||
|
<ToolbarButton onClick={() => dispatchChangeSet({ type: 'undo' })}>Undo</ToolbarButton>
|
||||||
|
)}
|
||||||
|
{changeSetState.canRedo && (
|
||||||
|
<ToolbarButton onClick={() => dispatchChangeSet({ type: 'redo' })}>Redo</ToolbarButton>
|
||||||
|
)}
|
||||||
|
{changeSetContainsChanges(changeSetState.value) && <ToolbarButton onClick={save}>Save</ToolbarButton>}
|
||||||
|
{changeSetContainsChanges(changeSetState.value) && <ToolbarButton onClick={revert}>Revert</ToolbarButton>}
|
||||||
|
<ToolbarButton onClick={reload}>Refresh</ToolbarButton>
|
||||||
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ function reducer(state, action) {
|
|||||||
history: [...state.history.slice(0, state.current + 1), action.value],
|
history: [...state.history.slice(0, state.current + 1), action.value],
|
||||||
current: state.current + 1,
|
current: state.current + 1,
|
||||||
value: action.value,
|
value: action.value,
|
||||||
|
canUndo: true,
|
||||||
|
canRedo: false,
|
||||||
};
|
};
|
||||||
case 'undo':
|
case 'undo':
|
||||||
if (state.current > 0)
|
if (state.current > 0)
|
||||||
@@ -15,6 +17,8 @@ function reducer(state, action) {
|
|||||||
history: state.history,
|
history: state.history,
|
||||||
current: state.current - 1,
|
current: state.current - 1,
|
||||||
value: state.history[state.current - 1],
|
value: state.history[state.current - 1],
|
||||||
|
canUndo: state.current > 1,
|
||||||
|
canRedo: true,
|
||||||
};
|
};
|
||||||
return state;
|
return state;
|
||||||
case 'redo':
|
case 'redo':
|
||||||
@@ -23,6 +27,8 @@ function reducer(state, action) {
|
|||||||
history: state.history,
|
history: state.history,
|
||||||
current: state.current + 1,
|
current: state.current + 1,
|
||||||
value: state.history[state.current + 1],
|
value: state.history[state.current + 1],
|
||||||
|
canUndo: true,
|
||||||
|
canRedo: state.current < state.history.length - 2,
|
||||||
};
|
};
|
||||||
return state;
|
return state;
|
||||||
case 'reset':
|
case 'reset':
|
||||||
|
|||||||
Reference in New Issue
Block a user