reducer.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 { Tmode } from 'app/components/SharePanel/types'
  23. interface IState {
  24. loading: boolean,
  25. logged: boolean,
  26. loginUser: object
  27. shareType: Tmode
  28. vizType: 'dashboard' | 'widget' | 'display' | ''
  29. permissionLoading: boolean
  30. download: boolean
  31. oauth2Enabled: boolean
  32. externalAuthProviders: any[]
  33. }
  34. export const initialState: IState = {
  35. loading: false,
  36. logged: false,
  37. loginUser: null,
  38. shareType: '',
  39. vizType: '',
  40. permissionLoading: false,
  41. download: false,
  42. oauth2Enabled: false,
  43. externalAuthProviders: []
  44. }
  45. const appReducer = (state = initialState, action) =>
  46. produce(state, (draft) => {
  47. switch (action.type) {
  48. case ActionTypes.GET_EXTERNAL_AUTH_PROVIDERS_SUCESS:
  49. draft.externalAuthProviders = action.payload.externalAuthProviders
  50. break
  51. case ActionTypes.LOGIN:
  52. draft.loading = true
  53. break
  54. case ActionTypes.LOGGED:
  55. draft.loading = false
  56. draft.logged = true
  57. draft.loginUser = action.payload.user
  58. break
  59. case ActionTypes.LOGON_FAILURE:
  60. draft.loading = false
  61. break
  62. case ActionTypes.LOGOUT:
  63. draft.logged = false
  64. draft.loginUser = null
  65. break
  66. case ActionTypes.GET_SERVER_CONFIGURATIONS_SUCCESS:
  67. draft.oauth2Enabled =
  68. action.payload.configurations.security.oauth2.enable
  69. break
  70. case ActionTypes.INTERCEPTOR_PREFLIGHT_SUCCESS:
  71. draft.shareType = action.payload.shareType
  72. draft.vizType = action.payload.vizType
  73. break
  74. case ActionTypes.GET_PERMISSIONS:
  75. draft.permissionLoading = true
  76. break
  77. case ActionTypes.GET_PERMISSIONS_SUCCESS:
  78. draft.permissionLoading = false
  79. draft.download = action.payload.download
  80. break
  81. case ActionTypes.GET_PERMISSIONS_FAIL:
  82. draft.permissionLoading = false
  83. }
  84. })
  85. export default appReducer