transformProps.js 2.2 KB

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