Skip to content

Commit

Permalink
Update notifications for latest API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
dlabrecq committed Jul 10, 2023
1 parent cc62394 commit 1651f52
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
15 changes: 9 additions & 6 deletions src/api/ros/recommendations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ export interface RecommendationValue {
format?: string;
}

export interface Notification {
code?: number;
message?: string;
type?: string;
}

export interface RecommendationItem {
// confidence_level?: number;
config: {
Expand All @@ -33,12 +39,9 @@ export interface RecommendationItem {
duration_in_hours?: string;
monitoring_start_time?: string;
monitoring_end_time?: string;
notifications?: [
{
type?: string;
message?: string;
},
];
notifications?: {
[key: string]: Notification;
};
}

export interface RecommendationItems {
Expand Down
11 changes: 6 additions & 5 deletions src/components/drawers/optimzations/optimizationsContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { createMapStateToProps, FetchStatus } from 'store/common';
import { rosActions, rosSelectors } from 'store/ros';
import { getTimeFromNow } from 'utils/dates';
import { formatOptimization } from 'utils/format';
import { hasRecommendation, hasRecommendationValues } from 'utils/recomendations';
import { getNotifications, hasRecommendation, hasRecommendationValues } from 'utils/recomendations';
import type { RouterComponentProps } from 'utils/router';
import { withRouter } from 'utils/router';

Expand Down Expand Up @@ -101,11 +101,12 @@ class OptimizationsContentBase extends React.Component<OptimizationsContentProps
const { intl, report } = this.props;
const { currentInterval } = this.state;

const recommendations = report?.recommendations?.duration_based;
const recommendation = recommendations ? recommendations[currentInterval] : undefined;
const notifications = recommendation && recommendation.notifications ? recommendation.notifications : [];
let notifications;
if (report?.recommendations?.duration_based?.[currentInterval]) {
notifications = getNotifications(report.recommendations.duration_based[currentInterval]);
}

if (notifications.length === 0) {
if (!notifications) {
return null;
}

Expand Down
12 changes: 10 additions & 2 deletions src/utils/recomendations.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import type { RecommendationItem } from 'api/ros/recommendations';
import type { Notification, RecommendationItem } from 'api/ros/recommendations';

export const getNotifications = (term: RecommendationItem): Notification[] => {
if (!hasNotification(term)) {
return undefined;
}
return Object.keys(term.notifications).map(key => term.notifications[key]);
};

export const hasNotification = (term: RecommendationItem) => {
if (!(term && term.notifications)) {
return false;
}
return term.notifications.length > 0;
const keys = Object.keys(term.notifications);
return keys.length > 0;
};

export const hasRecommendation = (term: RecommendationItem) => {
Expand Down

0 comments on commit 1651f52

Please sign in to comment.