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

Parameter feedback - #4 Added in Dashboard params #4321

Merged
merged 4 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions client/app/pages/dashboards/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ <h3>
</label>
</div>

<div class="m-b-10 p-15 bg-white tiled" ng-if="$ctrl.globalParameters.length > 0" data-test="DashboardParameters">
<parameters parameters="$ctrl.globalParameters" on-values-change="$ctrl.refreshDashboard"></parameters>
<div class="m-b-10 p-t-15 p-l-15 p-r-15 p-b-5 bg-white tiled" ng-if="$ctrl.globalParameters.length > 0" data-test="DashboardParameters">
<parameters parameters="$ctrl.globalParameters" query-result-error-data="$ctrl.dashboard.getQueryResultsErrorData()" on-values-change="$ctrl.refreshDashboard"></parameters>
</div>

<div class="m-b-10 p-15 bg-white tiled" ng-if="$ctrl.filters | notEmpty">
Expand Down
4 changes: 2 additions & 2 deletions client/app/pages/dashboards/public-dashboard-page.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<div class="container p-t-10 p-b-20" ng-if="$ctrl.dashboard">
<page-header title="$ctrl.dashboard.name"></page-header>

<div class="m-b-10 p-15 bg-white tiled" ng-if="$ctrl.globalParameters.length > 0">
<parameters parameters="$ctrl.globalParameters" on-values-change="$ctrl.refreshDashboard"></parameters>
<div class="m-b-10 p-t-15 p-l-15 p-r-15 p-b-5 bg-white tiled" ng-if="$ctrl.globalParameters.length > 0">
<parameters parameters="$ctrl.globalParameters" query-result-error-data="$ctrl.dashboard.getQueryResultsErrorData()" on-values-change="$ctrl.refreshDashboard"></parameters>
</div>

<div class="m-b-5">
Expand Down
33 changes: 33 additions & 0 deletions client/app/services/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,39 @@ function DashboardService($resource, $http, $location, currentUser) {
});
};

let currentQueryResultsErrorData; // swap for useMemo ANGULAR_REMOVE_ME
resource.prototype.getQueryResultsErrorData = function getQueryResultsErrorData() {
const dashboardErrors = _.map(this.widgets, (widget) => {
// get result
const result = widget.getQueryResult();
if (!result) {
return null;
}

// get error data
const errorData = result.getErrorData();
if (_.isEmpty(errorData)) {
return null;
}

// dashboard params only
const localParamNames = _.map(widget.getLocalParameters(), p => p.name);
const filtered = _.omit(errorData.parameters, localParamNames);

return filtered;
});

const merged = _.assign({}, ...dashboardErrors);
const errorData = _.isEmpty(merged) ? null : { parameters: merged };

// avoiding Angular infdig (ANGULAR_REMOVE_ME)
if (!_.isEqual(currentQueryResultsErrorData, errorData)) {
currentQueryResultsErrorData = errorData;
}

return currentQueryResultsErrorData;
};

return resource;
}

Expand Down
23 changes: 23 additions & 0 deletions client/cypress/integration/query/parameter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,29 @@ describe('Parameter', () => {
expectValueValidationError();
cy.percySnapshot('Validation error in widget-level parameter');
});

it('shows validation error in dashboard-level parameter', function () {
createDashboard('Foo')
.then(({ slug, id }) => {
this.dashboardUrl = `/dashboard/${slug}`;
return addWidget(id, this.vizId, {
parameterMappings: {
'test-parameter': {
type: 'dashboard-level',
title: '',
name: 'test-parameter',
mapTo: 'test-parameter',
value: null,
},
},
});
})
.then(() => {
cy.visit(this.dashboardUrl);
});
expectValueValidationError();
cy.percySnapshot('Validation error in dashboard-level parameter');
});
});

describe('Apply Changes', () => {
Expand Down