2020-03-16 07:45:51 -05:00
|
|
|
import cloneDeep from 'lodash/cloneDeep';
|
2020-06-04 06:44:48 -05:00
|
|
|
import { IntervalVariableModel } from '../types';
|
2020-03-16 07:45:51 -05:00
|
|
|
import { dispatch } from '../../../store/store';
|
|
|
|
import { setOptionAsCurrent, setOptionFromUrl } from '../state/actions';
|
|
|
|
import { VariableAdapter } from '../adapters';
|
|
|
|
import { initialIntervalVariableModelState, intervalVariableReducer } from './reducer';
|
|
|
|
import { OptionsPicker } from '../pickers';
|
|
|
|
import { toVariableIdentifier } from '../state/types';
|
|
|
|
import { IntervalVariableEditor } from './IntervalVariableEditor';
|
|
|
|
import { updateAutoValue, updateIntervalVariableOptions } from './actions';
|
|
|
|
|
|
|
|
export const createIntervalVariableAdapter = (): VariableAdapter<IntervalVariableModel> => {
|
|
|
|
return {
|
2020-03-23 09:33:17 -05:00
|
|
|
id: 'interval',
|
2020-03-16 07:45:51 -05:00
|
|
|
description: 'Define a timespan interval (ex 1m, 1h, 1d)',
|
2020-03-23 09:33:17 -05:00
|
|
|
name: 'Interval',
|
2020-03-16 07:45:51 -05:00
|
|
|
initialState: initialIntervalVariableModelState,
|
|
|
|
reducer: intervalVariableReducer,
|
|
|
|
picker: OptionsPicker,
|
|
|
|
editor: IntervalVariableEditor,
|
|
|
|
dependsOn: () => {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
setValue: async (variable, option, emitChanges = false) => {
|
|
|
|
await dispatch(updateAutoValue(toVariableIdentifier(variable)));
|
|
|
|
await dispatch(setOptionAsCurrent(toVariableIdentifier(variable), option, emitChanges));
|
|
|
|
},
|
|
|
|
setValueFromUrl: async (variable, urlValue) => {
|
|
|
|
await dispatch(updateAutoValue(toVariableIdentifier(variable)));
|
|
|
|
await dispatch(setOptionFromUrl(toVariableIdentifier(variable), urlValue));
|
|
|
|
},
|
|
|
|
updateOptions: async variable => {
|
|
|
|
await dispatch(updateIntervalVariableOptions(toVariableIdentifier(variable)));
|
|
|
|
},
|
|
|
|
getSaveModel: variable => {
|
2020-10-02 00:02:06 -05:00
|
|
|
const { index, id, state, global, ...rest } = cloneDeep(variable);
|
2020-03-16 07:45:51 -05:00
|
|
|
return rest;
|
|
|
|
},
|
|
|
|
getValueForUrl: variable => {
|
|
|
|
return variable.current.value;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|