util.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 {
  21. getInitialPaginationAndNativeQuery,
  22. getLocalControlInitialValues
  23. } from 'app/containers/Dashboard/util'
  24. import { IShareDashboardItemInfo } from './types'
  25. import { DashboardItemStatus } from './constants'
  26. import { IControl } from 'app/components/Control/types'
  27. import { ControlDefaultValueTypes } from 'app/components/Control/constants'
  28. import { IWidgetFormed } from 'app/containers/Widget/types'
  29. import { IShareFormedViews } from 'app/containers/View/types'
  30. export function initDefaultValuesFromShareParams(
  31. controls: IControl[],
  32. shareParams: object
  33. ) {
  34. controls.forEach((control) => {
  35. const { name, type } = control
  36. if (shareParams) {
  37. const defaultValue = shareParams[name]
  38. if (defaultValue && defaultValue.length) {
  39. control.defaultValueType = ControlDefaultValueTypes.Fixed
  40. control.defaultValue =
  41. Array.isArray(defaultValue) && defaultValue.length
  42. ? defaultValue.map((val) => decodeURI(val))
  43. : decodeURI(defaultValue)
  44. }
  45. }
  46. })
  47. }
  48. export function getShareInitialItemInfo(
  49. widget: IWidgetFormed,
  50. formedViews: IShareFormedViews
  51. ): IShareDashboardItemInfo {
  52. return {
  53. status: DashboardItemStatus.Pending,
  54. datasource: {
  55. columns: [],
  56. pageNo: 0,
  57. pageSize: 0,
  58. totalCount: 0,
  59. resultList: []
  60. },
  61. loading: false,
  62. queryConditions: {
  63. linkageFilters: [],
  64. globalFilters: [],
  65. linkageVariables: [],
  66. globalVariables: [],
  67. drillpathInstance: [],
  68. ...getLocalControlInitialValues(widget.config.controls, formedViews),
  69. ...getInitialPaginationAndNativeQuery(widget)
  70. },
  71. downloadCsvLoading: false,
  72. interactId: '',
  73. renderType: 'rerender',
  74. selectedItems: [],
  75. errorMessage: ''
  76. }
  77. }