Add numeric chart panel
This commit is contained in:
61
app/src/reducers/Charts.ts
Normal file
61
app/src/reducers/Charts.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { Action } from 'redux'
|
||||
import { createReducer } from './lib'
|
||||
import { Record, List } from 'immutable'
|
||||
|
||||
export interface ChartParameters {
|
||||
topic: string
|
||||
dotPath?: string
|
||||
}
|
||||
|
||||
export interface ChartsStateModel {
|
||||
charts: List<ChartParameters>
|
||||
}
|
||||
|
||||
export type ChartsState = Record<ChartsStateModel>
|
||||
|
||||
export type Action = AddChart | RemoveChart | SetCharts
|
||||
|
||||
export enum ActionTypes {
|
||||
CHARTS_ADD = 'CHARTS_ADD',
|
||||
CHARTS_REMOVE = 'CHARTS_REMOVE',
|
||||
CHARTS_SET = 'CHARTS_SET',
|
||||
}
|
||||
|
||||
export interface AddChart {
|
||||
type: ActionTypes.CHARTS_ADD
|
||||
chart: ChartParameters
|
||||
}
|
||||
|
||||
export interface RemoveChart {
|
||||
type: ActionTypes.CHARTS_REMOVE
|
||||
chart: ChartParameters
|
||||
}
|
||||
|
||||
export interface SetCharts {
|
||||
type: ActionTypes.CHARTS_SET
|
||||
charts: Array<ChartParameters>
|
||||
}
|
||||
|
||||
const initialState = Record<ChartsStateModel>({
|
||||
charts: List<ChartParameters>(),
|
||||
})
|
||||
|
||||
export const chartsReducer = createReducer(initialState(), {
|
||||
CHARTS_ADD: addChart,
|
||||
CHARTS_REMOVE: removeChart,
|
||||
CHARTS_SET: setCharts,
|
||||
})
|
||||
|
||||
function addChart(state: ChartsState, action: AddChart) {
|
||||
return state.set('charts', state.get('charts').push(action.chart))
|
||||
}
|
||||
|
||||
function removeChart(state: ChartsState, action: RemoveChart) {
|
||||
const charts = state.get('charts')
|
||||
const newCharts = charts.filter(chart => chart.topic !== action.chart.topic || chart.dotPath !== action.chart.dotPath)
|
||||
return state.set('charts', newCharts)
|
||||
}
|
||||
|
||||
function setCharts(state: ChartsState, action: SetCharts) {
|
||||
return state.set('charts', List(action.charts))
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
import * as moment from 'moment'
|
||||
import { createReducer } from './lib'
|
||||
import { Record } from 'immutable'
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { chartsReducer, ChartsState } from './Charts'
|
||||
import { combineReducers } from 'redux'
|
||||
import { connectionManagerReducer, ConnectionManagerState } from './ConnectionManager'
|
||||
import { connectionReducer, ConnectionState } from './Connection'
|
||||
@@ -13,6 +14,7 @@ export interface AppState {
|
||||
tree: TreeState
|
||||
settings: Record<SettingsState>
|
||||
publish: PublishState
|
||||
charts: ChartsState
|
||||
sidebar: SidebarState
|
||||
connection: ConnectionState
|
||||
connectionManager: ConnectionManagerState
|
||||
@@ -20,6 +22,7 @@ export interface AppState {
|
||||
|
||||
export default combineReducers({
|
||||
globalState,
|
||||
charts: chartsReducer,
|
||||
publish: publishReducer,
|
||||
sidebar: sidebarReducer,
|
||||
connection: connectionReducer,
|
||||
|
||||
Reference in New Issue
Block a user