github.com/wfusion/gofusion@v1.1.14/common/infra/asynq/asynqmon/ui/src/reducers/metricsReducer.ts (about)

     1  import {
     2    GET_METRICS_BEGIN,
     3    GET_METRICS_ERROR,
     4    GET_METRICS_SUCCESS,
     5    MetricsActionTypes,
     6  } from "../actions/metricsActions";
     7  import { MetricsResponse } from "../api";
     8  
     9  interface MetricsState {
    10    loading: boolean;
    11    error: string;
    12    data: MetricsResponse | null;
    13  }
    14  
    15  const initialState: MetricsState = {
    16    loading: false,
    17    error: "",
    18    data: null,
    19  };
    20  
    21  export default function metricsReducer(
    22    state = initialState,
    23    action: MetricsActionTypes
    24  ): MetricsState {
    25    switch (action.type) {
    26      case GET_METRICS_BEGIN:
    27        return {
    28          ...state,
    29          loading: true,
    30        };
    31  
    32      case GET_METRICS_ERROR:
    33        return {
    34          ...state,
    35          loading: false,
    36          error: action.error,
    37        };
    38  
    39      case GET_METRICS_SUCCESS:
    40        return {
    41          loading: false,
    42          error: "",
    43          data: action.payload,
    44        };
    45  
    46      default:
    47        return state;
    48    }
    49  }