actions.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 { ActionTypes } from './constants'
  21. import { returnType } from 'utils/redux'
  22. import { IWidgetRaw, IWidgetBase, IWidgetFormed } from './types'
  23. export const WidgetActions = {
  24. loadWidgets(projectId: number) {
  25. return {
  26. type: ActionTypes.LOAD_WIDGETS,
  27. payload: {
  28. projectId
  29. }
  30. }
  31. },
  32. widgetsLoaded(widgets: IWidgetFormed[]) {
  33. return {
  34. type: ActionTypes.LOAD_WIDGETS_SUCCESS,
  35. payload: {
  36. widgets
  37. }
  38. }
  39. },
  40. widgetsLoadedFail() {
  41. return {
  42. type: ActionTypes.LOAD_WIDGETS_FAILURE,
  43. payload: {}
  44. }
  45. },
  46. addWidget(widget: Omit<IWidgetRaw, 'id'>, resolve) {
  47. return {
  48. type: ActionTypes.ADD_WIDGET,
  49. payload: {
  50. widget,
  51. resolve
  52. }
  53. }
  54. },
  55. widgetAdded(result: IWidgetFormed) {
  56. return {
  57. type: ActionTypes.ADD_WIDGET_SUCCESS,
  58. payload: {
  59. result
  60. }
  61. }
  62. },
  63. addWidgetFail() {
  64. return {
  65. type: ActionTypes.ADD_WIDGET_FAILURE,
  66. payload: {}
  67. }
  68. },
  69. loadWidgetDetail(id: number) {
  70. return {
  71. type: ActionTypes.LOAD_WIDGET_DETAIL,
  72. payload: {
  73. id
  74. }
  75. }
  76. },
  77. widgetDetailLoaded(detail, view) {
  78. return {
  79. type: ActionTypes.LOAD_WIDGET_DETAIL_SUCCESS,
  80. payload: {
  81. detail,
  82. view
  83. }
  84. }
  85. },
  86. loadWidgetDetailFail(error) {
  87. return {
  88. type: ActionTypes.LOAD_WIDGET_DETAIL_FAILURE,
  89. payload: {
  90. error
  91. }
  92. }
  93. },
  94. editWidget(widget, resolve) {
  95. return {
  96. type: ActionTypes.EDIT_WIDGET,
  97. payload: {
  98. widget,
  99. resolve
  100. }
  101. }
  102. },
  103. widgetEdited() {
  104. return {
  105. type: ActionTypes.EDIT_WIDGET_SUCCESS,
  106. payload: {}
  107. }
  108. },
  109. editWidgetFail() {
  110. return {
  111. type: ActionTypes.EDIT_WIDGET_FAILURE,
  112. payload: {}
  113. }
  114. },
  115. copyWidget(widget: IWidgetBase, resolve: () => void) {
  116. return {
  117. type: ActionTypes.COPY_WIDGET,
  118. payload: {
  119. widget,
  120. resolve
  121. }
  122. }
  123. },
  124. widgetCopied(fromWidgetId: number, result: IWidgetFormed) {
  125. return {
  126. type: ActionTypes.COPY_WIDGET_SUCCESS,
  127. payload: {
  128. fromWidgetId,
  129. result
  130. }
  131. }
  132. },
  133. copyWidgetFail() {
  134. return {
  135. type: ActionTypes.COPY_WIDGET_FAILURE,
  136. payload: {}
  137. }
  138. },
  139. deleteWidget(id) {
  140. return {
  141. type: ActionTypes.DELETE_WIDGET,
  142. payload: {
  143. id
  144. }
  145. }
  146. },
  147. widgetDeleted(id: number) {
  148. return {
  149. type: ActionTypes.DELETE_WIDGET_SUCCESS,
  150. payload: {
  151. id
  152. }
  153. }
  154. },
  155. deleteWidgetFail() {
  156. return {
  157. type: ActionTypes.DELETE_WIDGET_FAILURE,
  158. payload: {}
  159. }
  160. },
  161. clearCurrentWidget() {
  162. return {
  163. type: ActionTypes.CLEAR_CURRENT_WIDGET,
  164. payload: {}
  165. }
  166. },
  167. executeComputed(sql) {
  168. return {
  169. type: ActionTypes.EXECUTE_COMPUTED_SQL,
  170. payload: {
  171. sql
  172. }
  173. }
  174. }
  175. }
  176. const mockAction = returnType(WidgetActions)
  177. export type WidgetActionType = typeof mockAction
  178. export default WidgetActions