transformProps.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. export default function transformProps(chartProps) {
  20. const {
  21. height,
  22. datasource,
  23. initialValues,
  24. formData,
  25. hooks,
  26. queryData
  27. } = chartProps;
  28. const {
  29. onAddFilter = () => {}
  30. } = hooks;
  31. const {
  32. alignPn,
  33. colorPn,
  34. includeSearch,
  35. metrics,
  36. orderDesc,
  37. pageLength,
  38. percentMetrics,
  39. tableFilter,
  40. tableTimestampFormat,
  41. timeseriesLimitMetric
  42. } = formData;
  43. const {
  44. columnFormats,
  45. verboseMap
  46. } = datasource;
  47. const {
  48. records,
  49. columns
  50. } = queryData.data;
  51. const processedColumns = columns.map(key => {
  52. let label = verboseMap[key]; // Handle verbose names for percents
  53. if (!label) {
  54. if (key[0] === '%') {
  55. const cleanedKey = key.slice(1);
  56. label = "% " + (verboseMap[cleanedKey] || cleanedKey);
  57. } else {
  58. label = key;
  59. }
  60. }
  61. return {
  62. key,
  63. label,
  64. format: columnFormats && columnFormats[key]
  65. };
  66. });
  67. return {
  68. height,
  69. data: records,
  70. alignPositiveNegative: alignPn,
  71. colorPositiveNegative: colorPn,
  72. columns: processedColumns,
  73. filters: initialValues,
  74. includeSearch,
  75. metrics,
  76. onAddFilter,
  77. orderDesc,
  78. pageLength: pageLength && parseInt(pageLength, 10),
  79. percentMetrics,
  80. tableFilter,
  81. tableTimestampFormat,
  82. timeseriesLimitMetric
  83. };
  84. }