Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Widget params] Filtering out incompatible dashboard params #3330

Merged
merged 1 commit into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions client/app/components/ParameterMappingInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -223,15 +223,18 @@ export class ParameterMappingInput extends React.Component {
export class ParameterMappingListInput extends React.Component {
static propTypes = {
mappings: PropTypes.arrayOf(PropTypes.object),
existingParamNames: PropTypes.arrayOf(PropTypes.string),
existingParams: PropTypes.arrayOf(PropTypes.shape({
name: PropTypes.string,
type: PropTypes.string,
})),
onChange: PropTypes.func,
clientConfig: PropTypes.any, // eslint-disable-line react/forbid-prop-types
Query: PropTypes.any, // eslint-disable-line react/forbid-prop-types
};

static defaultProps = {
mappings: [],
existingParamNames: [],
existingParams: [],
onChange: () => {},
clientConfig: null,
Query: null,
Expand All @@ -255,17 +258,23 @@ export class ParameterMappingListInput extends React.Component {

return (
<div>
{this.props.mappings.map((mapping, index) => (
<div key={mapping.name} className={(index === 0 ? '' : ' m-t-15')}>
<ParameterMappingInput
mapping={mapping}
existingParamNames={this.props.existingParamNames}
onChange={newMapping => this.updateParamMapping(mapping, newMapping)}
clientConfig={clientConfig}
Query={Query}
/>
</div>
))}
{this.props.mappings.map((mapping, index) => {
const existingParamsNames = this.props.existingParams
.filter(({ type }) => type === mapping.param.type) // exclude mismatching param types
.map(({ name }) => name); // keep names only

return (
<div key={mapping.name} className={(index === 0 ? '' : ' m-t-15')}>
<ParameterMappingInput
mapping={mapping}
existingParamNames={existingParamsNames}
onChange={newMapping => this.updateParamMapping(mapping, newMapping)}
clientConfig={clientConfig}
Query={Query}
/>
</div>
);
})}
</div>
);
}
Expand Down
6 changes: 3 additions & 3 deletions client/app/components/dashboards/AddWidgetDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ class AddWidgetDialog extends React.Component {
const clientConfig = this.props.clientConfig; // eslint-disable-line react/prop-types
const Query = this.props.Query; // eslint-disable-line react/prop-types

const existingParamNames = map(
const existingParams = map(
this.props.dashboard.getParametersDefs(),
param => param.name,
({ name, type }) => ({ name, type }),
);

return (
Expand Down Expand Up @@ -311,7 +311,7 @@ class AddWidgetDialog extends React.Component {
<ParameterMappingListInput
key="parameters-list"
mappings={this.state.parameterMappings}
existingParamNames={existingParamNames}
existingParams={existingParams}
onChange={mappings => this.updateParamMappings(mappings)}
clientConfig={clientConfig}
Query={Query}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ class EditParameterMappingsDialog extends React.Component {
const clientConfig = this.props.clientConfig; // eslint-disable-line react/prop-types
const Query = this.props.Query; // eslint-disable-line react/prop-types

const existingParamNames = map(
const existingParams = map(
this.props.dashboard.getParametersDefs(),
param => param.name,
({ name, type }) => ({ name, type }),
);

return (
Expand All @@ -87,7 +87,7 @@ class EditParameterMappingsDialog extends React.Component {
(this.state.parameterMappings.length > 0) &&
<ParameterMappingListInput
mappings={this.state.parameterMappings}
existingParamNames={existingParamNames}
existingParams={existingParams}
onChange={mappings => this.updateParamMappings(mappings)}
clientConfig={clientConfig}
Query={Query}
Expand Down