|
@@ -101,10 +101,11 @@ function WidgetQueryFields({
|
|
|
(['line', 'area', 'stacked_area', 'bar'].includes(displayType) &&
|
|
|
fields.length === 3);
|
|
|
|
|
|
- // Any column choice for World Map and Big Number widgets is legal since the
|
|
|
+ // Any function/field choice for Big Number widgets is legal since the
|
|
|
// data source is from an endpoint that is not timeseries-based.
|
|
|
+ // The function/field choice for World Map widget will need to be numeric-like.
|
|
|
// Column builder for Table widget is already handled above.
|
|
|
- const doNotValidateYAxis = ['world_map', 'big_number'].includes(displayType);
|
|
|
+ const doNotValidateYAxis = displayType === 'big_number';
|
|
|
|
|
|
return (
|
|
|
<Field
|
|
@@ -117,53 +118,74 @@ function WidgetQueryFields({
|
|
|
required
|
|
|
stacked
|
|
|
>
|
|
|
- {fields.map((field, i) => (
|
|
|
- <QueryFieldWrapper key={`${field}:${i}`}>
|
|
|
- <QueryField
|
|
|
- fieldValue={explodeField({field})}
|
|
|
- fieldOptions={fieldOptions}
|
|
|
- onChange={value => handleChangeField(value, i)}
|
|
|
- filterPrimaryOptions={option => {
|
|
|
- // Only validate functions for timeseries widgets.
|
|
|
- if (!doNotValidateYAxis && option.value.kind === FieldValueKind.FUNCTION) {
|
|
|
+ {fields.map((field, i) => {
|
|
|
+ const fieldValue = explodeField({field});
|
|
|
+ return (
|
|
|
+ <QueryFieldWrapper key={`${field}:${i}`}>
|
|
|
+ <QueryField
|
|
|
+ fieldValue={fieldValue}
|
|
|
+ fieldOptions={fieldOptions}
|
|
|
+ onChange={value => handleChangeField(value, i)}
|
|
|
+ filterPrimaryOptions={option => {
|
|
|
+ // Only validate function names for timeseries widgets and
|
|
|
+ // world map widgets.
|
|
|
+ if (
|
|
|
+ !doNotValidateYAxis &&
|
|
|
+ option.value.kind === FieldValueKind.FUNCTION
|
|
|
+ ) {
|
|
|
+ const primaryOutput = aggregateFunctionOutputType(
|
|
|
+ option.value.meta.name,
|
|
|
+ undefined
|
|
|
+ );
|
|
|
+ if (primaryOutput) {
|
|
|
+ // If a function returns a specific type, then validate it.
|
|
|
+ return isLegalYAxisType(primaryOutput);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return option.value.kind === FieldValueKind.FUNCTION;
|
|
|
+ }}
|
|
|
+ filterAggregateParameters={option => {
|
|
|
+ // Only validate function parameters for timeseries widgets and
|
|
|
+ // world map widgets.
|
|
|
+ if (doNotValidateYAxis) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fieldValue.kind !== 'function') {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ const functionName = fieldValue.function[0];
|
|
|
const primaryOutput = aggregateFunctionOutputType(
|
|
|
- option.value.meta.name,
|
|
|
- undefined
|
|
|
+ functionName as string,
|
|
|
+ option.value.meta.name
|
|
|
);
|
|
|
if (primaryOutput) {
|
|
|
- // If a function returns a specific type, then validate it.
|
|
|
return isLegalYAxisType(primaryOutput);
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- return option.value.kind === FieldValueKind.FUNCTION;
|
|
|
- }}
|
|
|
- filterAggregateParameters={option => {
|
|
|
- // Only validate function parameters for timeseries widgets.
|
|
|
- if (doNotValidateYAxis) {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- if (option.value.kind === FieldValueKind.FUNCTION) {
|
|
|
- // Functions are not legal options as an aggregate/function parameter.
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- return isLegalYAxisType(option.value.meta.dataType);
|
|
|
- }}
|
|
|
- />
|
|
|
- {fields.length > 1 && (
|
|
|
- <Button
|
|
|
- size="zero"
|
|
|
- borderless
|
|
|
- onClick={event => handleRemove(event, i)}
|
|
|
- icon={<IconDelete />}
|
|
|
- title={t('Remove this Y-Axis')}
|
|
|
- label={t('Remove this Y-Axis')}
|
|
|
+
|
|
|
+ if (option.value.kind === FieldValueKind.FUNCTION) {
|
|
|
+ // Functions are not legal options as an aggregate/function parameter.
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ return isLegalYAxisType(option.value.meta.dataType);
|
|
|
+ }}
|
|
|
/>
|
|
|
- )}
|
|
|
- </QueryFieldWrapper>
|
|
|
- ))}
|
|
|
+ {fields.length > 1 && (
|
|
|
+ <Button
|
|
|
+ size="zero"
|
|
|
+ borderless
|
|
|
+ onClick={event => handleRemove(event, i)}
|
|
|
+ icon={<IconDelete />}
|
|
|
+ title={t('Remove this Y-Axis')}
|
|
|
+ label={t('Remove this Y-Axis')}
|
|
|
+ />
|
|
|
+ )}
|
|
|
+ </QueryFieldWrapper>
|
|
|
+ );
|
|
|
+ })}
|
|
|
{!hideAddYAxisButton && (
|
|
|
<div>
|
|
|
<Button size="small" icon={<IconAdd isCircled />} onClick={handleAdd}>
|