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

Alerting Tab and minor bug fixes #1601

Merged
merged 1 commit into from
May 2, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ const AlertingView = () => {
}
`}</style>
<div className="this">
<TabMenu className="menu" model={items} activeItem={activeTab} onTabChange={(e) => setActiveTab(e.value)} />
<TabMenu className="menu" model={items} activeitem={activeTab} onTabChange={(e) => setActiveTab(e.value)} />

{activeTab === items[0] && (
<AlertingRulesView
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { useState, useEffect } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import React, { useEffect, useRef, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import classNames from 'classnames';
import classnames from 'classnames';
import _, { uniq } from 'lodash';
import PropTypes from 'prop-types';
import { Tree } from 'primereact/tree';
import { ContextMenu } from 'primereact/contextmenu';
import { alertingActions } from '../../../../../redux/ducks/alerting';
import classnames from 'classnames';
import { ruleIcon, templateIcon, topicIcon } from '../../constants';

/**
Expand All @@ -16,7 +16,7 @@ const AlertingRulesTree = ({ rules, templates, unsavedRules, onSelectionChanged,
const dispatch = useDispatch();

// state variables
const [contextMenu, setContextMenu] = useState(null);
const contextMenuRef = useRef(null);
const [treeIndex, setTreeIndex] = useState({});
const [treeData, setTreeData] = useState(null);

Expand All @@ -42,12 +42,24 @@ const AlertingRulesTree = ({ rules, templates, unsavedRules, onSelectionChanged,
{
label: 'Group by Notification Channel',
icon: 'pi pi-fw ' + (groupByTopics ? 'pi-check' : ''),
command: () => dispatch(alertingActions.changeRuleGroupingOptions({ groupByTemplates, groupByTopics: !groupByTopics })),
command: () =>
dispatch(
alertingActions.changeRuleGroupingOptions({
groupByTemplates,
groupByTopics: !groupByTopics,
})
),
},
{
label: 'Group by Templates',
icon: 'pi pi-fw ' + (groupByTemplates ? 'pi-check' : ''),
command: () => dispatch(alertingActions.changeRuleGroupingOptions({ groupByTemplates: !groupByTemplates, groupByTopics })),
command: () =>
dispatch(
alertingActions.changeRuleGroupingOptions({
groupByTemplates: !groupByTemplates,
groupByTopics,
})
),
},
];

Expand All @@ -69,25 +81,35 @@ const AlertingRulesTree = ({ rules, templates, unsavedRules, onSelectionChanged,
onSelectionChanged(newSelection);
};

const showContextMenu = (event) => {
event.originalEvent.persist();
contextMenuRef.current.show(event.originalEvent);
};

return (
<>
<style jsx>{`
.this {
overflow: auto;
flex-grow: 1;
}

.this :global(.p-treenode-label) {
width: 80%;
}

.this :global(.p-treenode-content:not(.p-highlight) .green) {
color: #4caf50;
}

.this :global(.p-treenode-content:not(.p-highlight) .grey) {
color: #9e9e9e;
}

.this :global(.p-treenode-content:not(.p-highlight) .red) {
color: #f44336;
}

.this :global(.rule-label) {
display: flex;
flex-direction: row;
Expand All @@ -102,10 +124,10 @@ const AlertingRulesTree = ({ rules, templates, unsavedRules, onSelectionChanged,
`}</style>

<div className="this">
<ContextMenu className="context-menu" model={contextMenuItems} ref={(el) => setContextMenu(el)} />
<ContextMenu className="p-contextmenu" model={contextMenuItems} ref={contextMenuRef} />

<Tree
onContextMenu={(event) => contextMenu.show(event.originalEvent)}
onContextMenu={showContextMenu}
filter={true}
filterBy="label"
value={treeData}
Expand All @@ -124,7 +146,7 @@ const AlertingRulesTree = ({ rules, templates, unsavedRules, onSelectionChanged,
*/
const nodeTemplate = (node) => {
if (node.type === 'rule') {
var classNames = 'pi ';
let classNames = 'pi ';
if (node.data.status === 'enabled' && !node.data.error) {
classNames = classNames + 'pi-circle-on green';
} else if (node.data.status === 'enabled' && node.data.error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class FileTree extends React.Component {
event.originalEvent.stopPropagation();
return;
}

event.originalEvent.persist();
this.setState({ contextMenuModel: this.getContextMenuModel(newSelection) });
this.contextMenuRef.current.show(event.originalEvent || event);
};
Expand Down