Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Commit

Permalink
Refresh rules if alerts don't know their name (#1201)
Browse files Browse the repository at this point in the history
  • Loading branch information
mechaffin authored Dec 13, 2018
1 parent 8b20891 commit b8b3326
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
18 changes: 16 additions & 2 deletions src/components/pages/dashboard/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ export class Dashboard extends Component {
}

componentDidMount() {
// Load the rules
if (!this.props.rulesError) this.props.fetchRules();
// Ensure the rules are loaded
this.refreshRules();

// Telemetry stream - START
const onPendingStart = () => this.setState({ telemetryIsPending: true });
Expand Down Expand Up @@ -272,6 +272,10 @@ export class Dashboard extends Component {
)
);

refreshRules = () => {
if (!this.props.rulesError && !this.props.rulesIsPending) this.props.fetchRules();
}

render() {
const {
theme,
Expand Down Expand Up @@ -347,6 +351,16 @@ export class Dashboard extends Component {
count: Math.min(alert.count, Config.maxAlertsCount)
}));

// Determine if the rules for all of the alerts are actually loaded.
const unloadedRules =
topAlerts.filter(alert => !rules[alert.ruleId]).length
+ currentActiveAlerts.filter(alert => !rules[alert.ruleId]).length;
if (unloadedRules > 0) {
// Fetch the rules since at least one alert doesn't know the name for its rule
this.refreshRules();
}


// Convert the list of alerts by device id to alerts by device type
const alertsPerDeviceType = Object.keys(alertsPerDeviceId).reduce((acc, deviceId) => {
const deviceType = (devices[deviceId] || {}).type || deviceId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class AlertsPanel extends Component {
columnDefs: translateColumnDefs(t, this.columnDefs),
rowData: alerts,
suppressFlyouts: true,
gridAutoHeight: true,
domLayout: 'autoHeight',
deltaRowDataMode: false,
t
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ export const defaultDeploymentDetailsGridProps = {
deltaRowDataMode: true,
enableSorting: true,
unSortIcon: true,
gridAutoHeight: true
domLayout: 'autoHeight'
};
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export class DeviceDetails extends Component {
rowData: isPending ? undefined : this.applyRuleNames(this.state.alerts || [], this.props.rules || []),
t: this.props.t,
deviceGroups: this.props.deviceGroups,
gridAutoHeight: true,
domLayout: 'autoHeight',
columnDefs: translateColumnDefs(this.props.t, this.columnDefs),
suppressFlyouts: true
};
Expand Down
6 changes: 3 additions & 3 deletions src/components/pages/maintenance/jobDetails/jobDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ export class JobDetails extends Component {

const selectedJob = this.state.selectedJob;
const jobGridProps = {
gridAutoHeight: true,
domLayout: 'autoHeight',
rowData: isPending ? undefined : selectedJob ? [selectedJob] : [],
pagination: false,
t,
onColumnMoved: this.props.onColumnMoved
};

const jobStatusGridProps = {
gridAutoHeight: true,
domLayout: 'autoHeight',
rowData: this.state.jobStatusIsPending ? undefined : [this.state.jobStatus],
pagination: true,
paginationPageSize: Config.smallGridPageSize,
Expand Down Expand Up @@ -157,7 +157,7 @@ export class JobDetails extends Component {
?
<DevicesGridContainer
t={t}
gridAutoHeight={true}
domLayout="autoHeight"
rowData={this.state.selectedDevices}
onContextMenuChange={this.onContextMenuChange} />
: t('maintenance.noOccurrenceSelected')
Expand Down
4 changes: 2 additions & 2 deletions src/components/pages/maintenance/ruleDetails/ruleDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export class RuleDetails extends Component {
const alertName = (this.state.selectedRule || {}).name || selectedId;

const alertsGridProps = {
gridAutoHeight: true,
domLayout: 'autoHeight',
rowSelection: 'multiple',
deltaRowDataMode: true,
getRowNodeId: ({ id }) => id,
Expand Down Expand Up @@ -407,7 +407,7 @@ export class RuleDetails extends Component {
<h4 className="sub-heading">{t('maintenance.alertedDevices')}</h4>
<DevicesGridContainer
t={t}
gridAutoHeight={true}
domLayout="autoHeight"
onGridReady={this.onDeviceGridReady}
rowData={isPending ? undefined : this.state.devices}
onContextMenuChange={this.onContextMenuChange('deviceContextBtns')}
Expand Down

0 comments on commit b8b3326

Please sign in to comment.