reducer.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * <<
  3. * Davinci
  4. * ==
  5. * Copyright (C) 2016 - 2017 EDP
  6. * ==
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * >>
  19. */
  20. import produce from 'immer'
  21. import { ActionTypes } from './constants'
  22. import { GraphTypes } from 'containers/Display/constants'
  23. import { fieldGroupedSort } from 'containers/Widget/components/Config/Sort'
  24. import { DashboardItemStatus } from '../Dashboard/constants'
  25. export const initialState = {
  26. title: '',
  27. display: null,
  28. slidesLayers: [],
  29. slideLayersInfo: {},
  30. widgets: {},
  31. formedViews: {}
  32. }
  33. const displayReducer = (state = initialState, action) =>
  34. produce(state, (draft) => {
  35. switch (action.type) {
  36. case ActionTypes.LOAD_SHARE_DISPLAY_SUCCESS:
  37. draft.title = action.payload.display.name
  38. draft.display = action.payload.display
  39. draft.slidesLayers = action.payload.slides
  40. draft.widgets = action.payload.widgets.reduce((obj, w) => {
  41. obj[w.id] = w
  42. return obj
  43. }, {})
  44. draft.formedViews = action.payload.formedViews
  45. draft.slideLayersInfo = action.payload.slides.reduce(
  46. (obj, slide, idx) => {
  47. obj[idx + 1] = slide.relations.reduce((info, layer) => {
  48. info[layer.id] =
  49. layer.type === GraphTypes.Chart
  50. ? {
  51. status: DashboardItemStatus.Pending,
  52. datasource: { resultList: [] },
  53. loading: false,
  54. queryConditions: {
  55. tempFilters: [], // @TODO combine widget static filters with local filters
  56. linkageFilters: [],
  57. globalFilters: [],
  58. variables: [],
  59. linkageVariables: [],
  60. globalVariables: []
  61. },
  62. interactId: '',
  63. renderType: 'rerender'
  64. }
  65. : {
  66. loading: false
  67. }
  68. return info
  69. }, {})
  70. return obj
  71. },
  72. {}
  73. )
  74. break
  75. case ActionTypes.LOAD_SHARE_DISPLAY_FAILURE:
  76. draft.display = null
  77. draft.slidesLayers = null
  78. draft.widgets = {}
  79. draft.slideLayersInfo = {}
  80. break
  81. case ActionTypes.LOAD_LAYER_DATA:
  82. draft.slideLayersInfo[action.payload.slideNumber][
  83. action.payload.layerId
  84. ].loading = true
  85. break
  86. case ActionTypes.LOAD_LAYER_DATA_SUCCESS:
  87. fieldGroupedSort(
  88. action.payload.data.resultList,
  89. action.payload.requestParams.customOrders
  90. )
  91. draft.slideLayersInfo[action.payload.slideNumber][
  92. action.payload.layerId
  93. ] = {
  94. ...draft.slideLayersInfo[action.payload.slideNumber][
  95. action.payload.layerId
  96. ],
  97. status: DashboardItemStatus.Fulfilled,
  98. loading: false,
  99. datasource: action.payload.data,
  100. renderType: action.payload.renderType
  101. }
  102. break
  103. case ActionTypes.LOAD_LAYER_DATA_FAILURE:
  104. draft.slideLayersInfo[action.payload.slideNumber][
  105. action.payload.layerId
  106. ] = {
  107. ...draft.slideLayersInfo[action.payload.slideNumber][
  108. action.payload.layerId
  109. ],
  110. status: DashboardItemStatus.Error,
  111. loading: false
  112. }
  113. break
  114. }
  115. })
  116. export default displayReducer