|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the "Elastic License |
| 4 | + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side |
| 5 | + * Public License v 1"; you may not use this file except in compliance with, at |
| 6 | + * your election, the "Elastic License 2.0", the "GNU Affero General Public |
| 7 | + * License v3.0 only", or the "Server Side Public License, v 1". |
| 8 | + */ |
| 9 | + |
| 10 | +import type { TypeOf } from '@kbn/config-schema'; |
| 11 | +import { schema } from '@kbn/config-schema'; |
| 12 | +import { |
| 13 | + countMetricOperationSchema, |
| 14 | + counterRateOperationSchema, |
| 15 | + cumulativeSumOperationSchema, |
| 16 | + differencesOperationSchema, |
| 17 | + formulaOperationDefinitionSchema, |
| 18 | + lastValueOperationSchema, |
| 19 | + metricOperationSchema, |
| 20 | + movingAverageOperationSchema, |
| 21 | + percentileOperationSchema, |
| 22 | + percentileRanksOperationSchema, |
| 23 | + staticOperationDefinitionSchema, |
| 24 | + uniqueCountMetricOperationSchema, |
| 25 | + sumMetricOperationSchema, |
| 26 | + esqlColumnSchema, |
| 27 | + genericOperationOptionsSchema, |
| 28 | +} from '../metric_ops'; |
| 29 | +import { colorByValueSchema, colorMappingSchema, staticColorSchema } from '../color'; |
| 30 | +import { datasetSchema, datasetEsqlTableSchema } from '../dataset'; |
| 31 | +import { |
| 32 | + bucketDateHistogramOperationSchema, |
| 33 | + bucketTermsOperationSchema, |
| 34 | + bucketHistogramOperationSchema, |
| 35 | + bucketRangesOperationSchema, |
| 36 | + bucketFiltersOperationSchema, |
| 37 | +} from '../bucket_ops'; |
| 38 | +import { collapseBySchema, layerSettingsSchema, sharedPanelInfoSchema } from '../shared'; |
| 39 | +import { |
| 40 | + legendNestedSchema, |
| 41 | + legendTruncateAfterLinesSchema, |
| 42 | + legendVisibleSchema, |
| 43 | + legendSizeSchema, |
| 44 | + valueDisplaySchema, |
| 45 | +} from './partition_shared'; |
| 46 | + |
| 47 | +const mosaicStateSharedSchema = { |
| 48 | + legend: schema.maybe( |
| 49 | + schema.object({ |
| 50 | + nested: legendNestedSchema, |
| 51 | + truncate_after_lines: legendTruncateAfterLinesSchema, |
| 52 | + visible: legendVisibleSchema, |
| 53 | + size: legendSizeSchema, |
| 54 | + }) |
| 55 | + ), |
| 56 | + value_display: valueDisplaySchema, |
| 57 | +}; |
| 58 | + |
| 59 | +const partitionStatePrimaryMetricOptionsSchema = schema.object({ |
| 60 | + /** |
| 61 | + * Color configuration |
| 62 | + */ |
| 63 | + color: schema.maybe(staticColorSchema), |
| 64 | +}); |
| 65 | + |
| 66 | +const partitionStateBreakdownByOptionsSchema = schema.object({ |
| 67 | + /** |
| 68 | + * Color configuration |
| 69 | + */ |
| 70 | + color: schema.maybe(schema.oneOf([colorByValueSchema, colorMappingSchema])), |
| 71 | + /** |
| 72 | + * Collapse by function. This parameter is used to collapse the |
| 73 | + * metric chart when the number of columns is bigger than the |
| 74 | + * number of columns specified in the columns parameter. |
| 75 | + * Possible values: |
| 76 | + * - 'avg': Collapse by average |
| 77 | + * - 'sum': Collapse by sum |
| 78 | + * - 'max': Collapse by max |
| 79 | + * - 'min': Collapse by min |
| 80 | + * - 'none': Do not collapse |
| 81 | + */ |
| 82 | + collapse_by: schema.maybe(collapseBySchema), |
| 83 | +}); |
| 84 | + |
| 85 | +export const mosaicStateSchemaNoESQL = schema.object({ |
| 86 | + type: schema.literal('mosaic'), |
| 87 | + ...sharedPanelInfoSchema, |
| 88 | + ...layerSettingsSchema, |
| 89 | + ...datasetSchema, |
| 90 | + ...mosaicStateSharedSchema, |
| 91 | + /** |
| 92 | + * Primary value configuration, must define operation. |
| 93 | + */ |
| 94 | + metrics: schema.arrayOf( |
| 95 | + schema.oneOf([ |
| 96 | + // oneOf allows only 12 items |
| 97 | + // so break down metrics based on the type: field-based, reference-based, formula-like |
| 98 | + schema.oneOf([ |
| 99 | + schema.allOf([partitionStatePrimaryMetricOptionsSchema, countMetricOperationSchema]), |
| 100 | + schema.allOf([partitionStatePrimaryMetricOptionsSchema, uniqueCountMetricOperationSchema]), |
| 101 | + schema.allOf([partitionStatePrimaryMetricOptionsSchema, metricOperationSchema]), |
| 102 | + schema.allOf([partitionStatePrimaryMetricOptionsSchema, sumMetricOperationSchema]), |
| 103 | + schema.allOf([partitionStatePrimaryMetricOptionsSchema, lastValueOperationSchema]), |
| 104 | + schema.allOf([partitionStatePrimaryMetricOptionsSchema, percentileOperationSchema]), |
| 105 | + schema.allOf([partitionStatePrimaryMetricOptionsSchema, percentileRanksOperationSchema]), |
| 106 | + ]), |
| 107 | + schema.oneOf([ |
| 108 | + schema.allOf([partitionStatePrimaryMetricOptionsSchema, differencesOperationSchema]), |
| 109 | + schema.allOf([partitionStatePrimaryMetricOptionsSchema, movingAverageOperationSchema]), |
| 110 | + schema.allOf([partitionStatePrimaryMetricOptionsSchema, cumulativeSumOperationSchema]), |
| 111 | + schema.allOf([partitionStatePrimaryMetricOptionsSchema, counterRateOperationSchema]), |
| 112 | + ]), |
| 113 | + schema.oneOf([ |
| 114 | + schema.allOf([partitionStatePrimaryMetricOptionsSchema, staticOperationDefinitionSchema]), |
| 115 | + schema.allOf([partitionStatePrimaryMetricOptionsSchema, formulaOperationDefinitionSchema]), |
| 116 | + ]), |
| 117 | + ]), |
| 118 | + { minSize: 1 } |
| 119 | + ), |
| 120 | + /** |
| 121 | + * Configure how to break down the metric (e.g. show one metric per term). |
| 122 | + */ |
| 123 | + group_by: schema.arrayOf( |
| 124 | + schema.maybe( |
| 125 | + schema.oneOf([ |
| 126 | + schema.allOf([partitionStateBreakdownByOptionsSchema, bucketDateHistogramOperationSchema]), |
| 127 | + schema.allOf([partitionStateBreakdownByOptionsSchema, bucketTermsOperationSchema]), |
| 128 | + schema.allOf([partitionStateBreakdownByOptionsSchema, bucketHistogramOperationSchema]), |
| 129 | + schema.allOf([partitionStateBreakdownByOptionsSchema, bucketRangesOperationSchema]), |
| 130 | + schema.allOf([partitionStateBreakdownByOptionsSchema, bucketFiltersOperationSchema]), |
| 131 | + ]) |
| 132 | + ), |
| 133 | + { minSize: 1 } |
| 134 | + ), |
| 135 | +}); |
| 136 | + |
| 137 | +const mosaicStateSchemaESQL = schema.object({ |
| 138 | + type: schema.literal('mosaic'), |
| 139 | + ...sharedPanelInfoSchema, |
| 140 | + ...layerSettingsSchema, |
| 141 | + ...datasetEsqlTableSchema, |
| 142 | + ...mosaicStateSharedSchema, |
| 143 | + /** |
| 144 | + * Primary value configuration, must define operation. |
| 145 | + */ |
| 146 | + metrics: schema.allOf([ |
| 147 | + schema.object(genericOperationOptionsSchema), |
| 148 | + partitionStatePrimaryMetricOptionsSchema, |
| 149 | + esqlColumnSchema, |
| 150 | + ]), |
| 151 | + /** |
| 152 | + * Configure how to break down the metric (e.g. show one metric per term). |
| 153 | + */ |
| 154 | + group_by: schema.maybe(schema.allOf([partitionStateBreakdownByOptionsSchema, esqlColumnSchema])), |
| 155 | +}); |
| 156 | + |
| 157 | +export const mosaicStateSchema = schema.oneOf([mosaicStateSchemaNoESQL, mosaicStateSchemaESQL]); |
| 158 | + |
| 159 | +export type MosaicState = TypeOf<typeof mosaicStateSchema>; |
| 160 | +export type MosaicStateNoESQL = TypeOf<typeof mosaicStateSchemaNoESQL>; |
| 161 | +export type MosaicStateESQL = TypeOf<typeof mosaicStateSchemaESQL>; |
0 commit comments