mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-22 01:45:59 +00:00
save chart to editor data
This commit is contained in:
@@ -5,6 +5,14 @@ const FormContext = React.createContext(null);
|
||||
|
||||
export function FormProvider({ children, initialValues = {} }) {
|
||||
const [values, setValues] = React.useState(initialValues);
|
||||
return (
|
||||
<FormProviderCore values={values} setValues={setValues}>
|
||||
{children}
|
||||
</FormProviderCore>
|
||||
);
|
||||
}
|
||||
|
||||
export function FormProviderCore({ children, values, setValues }) {
|
||||
const [submitAction, setSubmitAction] = React.useState(null);
|
||||
const handleEnter = React.useCallback(
|
||||
(e) => {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import _ from 'lodash';
|
||||
import React from 'react';
|
||||
|
||||
function reducer(state, action) {
|
||||
switch (action.type) {
|
||||
case 'set':
|
||||
// console.log('SET', state.history, action.value);
|
||||
return {
|
||||
history: [...state.history.slice(0, state.current + 1), action.value],
|
||||
current: state.current + 1,
|
||||
@@ -11,6 +11,16 @@ function reducer(state, action) {
|
||||
canUndo: true,
|
||||
canRedo: false,
|
||||
};
|
||||
case 'compute': {
|
||||
const newValue = action.compute(state.history[state.current]);
|
||||
return {
|
||||
history: [...state.history.slice(0, state.current + 1), newValue],
|
||||
current: state.current + 1,
|
||||
value: newValue,
|
||||
canUndo: true,
|
||||
canRedo: false,
|
||||
};
|
||||
}
|
||||
case 'undo':
|
||||
if (state.current > 0)
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user