actions.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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 {
  23. ISourceBase,
  24. ISource,
  25. SourceResetConnectionProperties,
  26. ITableColumns,
  27. ISourceDatabases,
  28. ICSVMetaInfo,
  29. IDatabaseTables,
  30. IDatasourceInfo
  31. } from './types'
  32. export const SourceActions = {
  33. loadSources(projectId: number) {
  34. return {
  35. type: ActionTypes.LOAD_SOURCES,
  36. payload: {
  37. projectId
  38. }
  39. }
  40. },
  41. sourcesLoaded(sources: ISourceBase[]) {
  42. return {
  43. type: ActionTypes.LOAD_SOURCES_SUCCESS,
  44. payload: {
  45. sources
  46. }
  47. }
  48. },
  49. loadSourcesFail() {
  50. return {
  51. type: ActionTypes.LOAD_SOURCES_FAILURE
  52. }
  53. },
  54. loadSourceDetail(sourceId: number, resolve?: (source: ISource) => void) {
  55. return {
  56. type: ActionTypes.LOAD_SOURCE_DETAIL,
  57. payload: {
  58. sourceId,
  59. resolve
  60. }
  61. }
  62. },
  63. sourceDetailLoaded(source: ISource) {
  64. return {
  65. type: ActionTypes.LOAD_SOURCE_DETAIL_SUCCESS,
  66. payload: {
  67. source
  68. }
  69. }
  70. },
  71. loadSourceDetailFail() {
  72. return {
  73. type: ActionTypes.LOAD_SOURCE_DETAIL_FAIL,
  74. payload: {}
  75. }
  76. },
  77. addSource(source: ISource, resolve: () => void) {
  78. return {
  79. type: ActionTypes.ADD_SOURCE,
  80. payload: {
  81. source,
  82. resolve
  83. }
  84. }
  85. },
  86. sourceAdded(result: ISourceBase) {
  87. return {
  88. type: ActionTypes.ADD_SOURCE_SUCCESS,
  89. payload: {
  90. result
  91. }
  92. }
  93. },
  94. addSourceFail() {
  95. return {
  96. type: ActionTypes.ADD_SOURCE_FAILURE,
  97. payload: {}
  98. }
  99. },
  100. deleteSource(id: number) {
  101. return {
  102. type: ActionTypes.DELETE_SOURCE,
  103. payload: {
  104. id
  105. }
  106. }
  107. },
  108. sourceDeleted(id: number) {
  109. return {
  110. type: ActionTypes.DELETE_SOURCE_SUCCESS,
  111. payload: {
  112. id
  113. }
  114. }
  115. },
  116. deleteSourceFail() {
  117. return {
  118. type: ActionTypes.DELETE_SOURCE_FAILURE,
  119. payload: {}
  120. }
  121. },
  122. editSource(source: ISource, resolve: () => void) {
  123. return {
  124. type: ActionTypes.EDIT_SOURCE,
  125. payload: {
  126. source,
  127. resolve
  128. }
  129. }
  130. },
  131. sourceEdited(result: ISourceBase) {
  132. return {
  133. type: ActionTypes.EDIT_SOURCE_SUCCESS,
  134. payload: {
  135. result
  136. }
  137. }
  138. },
  139. editSourceFail() {
  140. return {
  141. type: ActionTypes.EDIT_SOURCE_FAILURE,
  142. payload: {}
  143. }
  144. },
  145. testSourceConnection(testSource) {
  146. return {
  147. type: ActionTypes.TEST_SOURCE_CONNECTION,
  148. payload: {
  149. testSource
  150. }
  151. }
  152. },
  153. sourceConnected() {
  154. return {
  155. type: ActionTypes.TEST_SOURCE_CONNECTION_SUCCESS,
  156. payload: {}
  157. }
  158. },
  159. testSourceConnectionFail() {
  160. return {
  161. type: ActionTypes.TEST_SOURCE_CONNECTION_FAILURE,
  162. payload: {}
  163. }
  164. },
  165. resetSourceConnection(
  166. properties: SourceResetConnectionProperties,
  167. resolve: () => void
  168. ) {
  169. return {
  170. type: ActionTypes.RESET_SOURCE_CONNECTION,
  171. payload: {
  172. properties,
  173. resolve
  174. }
  175. }
  176. },
  177. sourceReset() {
  178. return {
  179. type: ActionTypes.RESET_SOURCE_CONNECTION_SUCCESS,
  180. payload: {}
  181. }
  182. },
  183. resetSourceConnectionFail() {
  184. return {
  185. type: ActionTypes.RESET_SOURCE_CONNECTION_FAILURE,
  186. payload: {}
  187. }
  188. },
  189. validateCsvTableName(
  190. csvMeta: Pick<ICSVMetaInfo, 'sourceId' | 'tableName' | 'mode'>,
  191. callback: (errMsg?: string) => void
  192. ) {
  193. return {
  194. type: ActionTypes.VALIDATE_CSV_TABLE_NAME,
  195. payload: {
  196. csvMeta,
  197. callback
  198. }
  199. }
  200. },
  201. uploadCsvFile(csvMeta: ICSVMetaInfo, resolve: () => void, reject: () => void) {
  202. return {
  203. type: ActionTypes.UPLOAD_CSV_FILE,
  204. payload: {
  205. csvMeta,
  206. resolve,
  207. reject
  208. }
  209. }
  210. },
  211. loadSourceDatabases(sourceId: number) {
  212. return {
  213. type: ActionTypes.LOAD_SOURCE_DATABASES,
  214. payload: {
  215. sourceId
  216. }
  217. }
  218. },
  219. sourceDatabasesLoaded(sourceDatabases: ISourceDatabases) {
  220. return {
  221. type: ActionTypes.LOAD_SOURCE_DATABASES_SUCCESS,
  222. payload: {
  223. sourceDatabases
  224. }
  225. }
  226. },
  227. loadSourceDatabasesFail(err) {
  228. return {
  229. type: ActionTypes.LOAD_SOURCE_DATABASES_FAILURE,
  230. payload: {
  231. err
  232. }
  233. }
  234. },
  235. loadDatabaseTables(sourceId: number, databaseName: string, resolve?) {
  236. return {
  237. type: ActionTypes.LOAD_SOURCE_DATABASE_TABLES,
  238. payload: {
  239. sourceId,
  240. databaseName,
  241. resolve
  242. }
  243. }
  244. },
  245. databaseTablesLoaded(databaseTables: IDatabaseTables) {
  246. return {
  247. type: ActionTypes.LOAD_SOURCE_DATABASE_TABLES_SUCCESS,
  248. payload: {
  249. databaseTables
  250. }
  251. }
  252. },
  253. loadDatabaseTablesFail(err) {
  254. return {
  255. type: ActionTypes.LOAD_SOURCE_DATABASE_TABLES_FAILURE,
  256. payload: {
  257. err
  258. }
  259. }
  260. },
  261. loadTableColumns(
  262. sourceId: number,
  263. databaseName: string,
  264. tableName: string,
  265. resolve?
  266. ) {
  267. return {
  268. type: ActionTypes.LOAD_SOURCE_TABLE_COLUMNS,
  269. payload: {
  270. sourceId,
  271. databaseName,
  272. tableName,
  273. resolve
  274. }
  275. }
  276. },
  277. tableColumnsLoaded(databaseName: string, tableColumns: ITableColumns) {
  278. return {
  279. type: ActionTypes.LOAD_SOURCE_TABLE_COLUMNS_SUCCESS,
  280. payload: {
  281. databaseName,
  282. tableColumns
  283. }
  284. }
  285. },
  286. loadTableColumnsFail(err) {
  287. return {
  288. type: ActionTypes.LOAD_SOURCE_TABLE_COLUMNS_FAILURE,
  289. payload: {
  290. err
  291. }
  292. }
  293. },
  294. loadDatasourcesInfo() {
  295. return {
  296. type: ActionTypes.LOAD_DATASOURCES_INFO
  297. }
  298. },
  299. datasourcesInfoLoaded(info: IDatasourceInfo[]) {
  300. return {
  301. type: ActionTypes.LOAD_DATASOURCES_INFO_SUCCESS,
  302. payload: {
  303. info
  304. }
  305. }
  306. },
  307. loadDatasourcesInfoFail(err) {
  308. return {
  309. type: ActionTypes.LOAD_DATASOURCES_INFO_FAILURE,
  310. payload: {
  311. err
  312. }
  313. }
  314. }
  315. }
  316. const mockAction = returnType(SourceActions)
  317. export type SourceActionType = typeof mockAction
  318. export default SourceActions