Skip to content
Snippets Groups Projects
Unverified Commit bc6b7567 authored by Paul Rosenzweig's avatar Paul Rosenzweig Committed by GitHub
Browse files

Don't use ParameterFieldWidget if any targets are variables not dimensions (#12012)

* don't use ParameterFieldWidget if any targets are variables not dimensions

* fix tests, avoid flatMap for flow's sake

* add padding, expand message

* add negative margin on bottom
parent 5b837aad
No related branches found
No related tags found
No related merge requests found
......@@ -114,6 +114,17 @@ export default class DashCardCardParameterMapper extends Component {
mapping.overlapMax === 1
);
let selectedFieldWarning = null;
if (
// variable targets can't accept an list of values like dimension targets
target &&
target[0] === "variable" &&
// date parameters only accept a single value anyways, so hide the warning
!parameter.type.startsWith("date/")
) {
selectedFieldWarning = t`This field only accepts a single value because it's used in a SQL query.`;
}
return (
<div className="mx1 flex flex-column align-center drag-disabled">
{dashcard.series && dashcard.series.length > 0 && (
......@@ -185,6 +196,11 @@ export default class DashCardCardParameterMapper extends Component {
</Tooltip>
)}
</ParameterTargetWidget>
{selectedFieldWarning && (
<span style={{ height: 0 }} className="mt1 mbn1 px4 text-centered">
{selectedFieldWarning}
</span>
)}
</div>
);
}
......
......@@ -196,10 +196,15 @@ export const getParameters = createSelector(
[getMetadata, getDashboard, getMappingsByParameter],
(metadata, dashboard, mappingsByParameter) =>
((dashboard && dashboard.parameters) || []).map(parameter => {
const mappings = _.flatten(
_.map(mappingsByParameter[parameter.id] || {}, _.values),
);
// we change out widgets if a parameter is connected to non-field targets
const hasOnlyFieldTargets = mappings.every(x => x.field_id != null);
// get the unique list of field IDs these mappings reference
const fieldIds = _.chain(mappingsByParameter[parameter.id])
.map(_.values)
.flatten()
const fieldIds = _.chain(mappings)
.map(m => m.field_id)
.uniq()
.filter(fieldId => fieldId != null)
......@@ -219,6 +224,7 @@ export const getParameters = createSelector(
fieldIdsWithFKResolved.length === 1
? fieldIdsWithFKResolved[0]
: null,
hasOnlyFieldTargets,
};
}),
);
......
......@@ -145,6 +145,7 @@ export function getParametersWithExtras(
if (fieldId != null) {
parameter = assoc(parameter, "field_id", fieldId);
}
parameter = assoc(parameter, "hasOnlyFieldTargets", fieldId != null);
return parameter;
});
}
......
......@@ -95,7 +95,7 @@ export default class ParameterValueWidget extends Component {
const { parameter } = this.props;
if (DATE_WIDGETS[parameter.type]) {
return DATE_WIDGETS[parameter.type];
} else if (this.getFields().length > 0) {
} else if (this.getFields().length > 0 && parameter.hasOnlyFieldTargets) {
return ParameterFieldWidget;
} else {
return TextWidget;
......
......@@ -50,6 +50,7 @@ describe("dashboard/selectors", () => {
id: 1,
field_ids: [],
field_id: null,
hasOnlyFieldTargets: true,
},
]);
});
......@@ -67,6 +68,7 @@ describe("dashboard/selectors", () => {
id: 1,
field_ids: [],
field_id: null,
hasOnlyFieldTargets: false,
},
]);
});
......@@ -84,6 +86,7 @@ describe("dashboard/selectors", () => {
id: 1,
field_ids: [1],
field_id: 1,
hasOnlyFieldTargets: true,
},
]);
});
......@@ -106,6 +109,7 @@ describe("dashboard/selectors", () => {
id: 1,
field_ids: [1],
field_id: 1,
hasOnlyFieldTargets: true,
},
]);
});
......@@ -128,6 +132,7 @@ describe("dashboard/selectors", () => {
id: 1,
field_ids: [1],
field_id: 1,
hasOnlyFieldTargets: false,
},
]);
});
......@@ -150,6 +155,7 @@ describe("dashboard/selectors", () => {
id: 1,
field_ids: [1, 2],
field_id: null,
hasOnlyFieldTargets: true,
},
]);
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment