-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
852 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/*** UNDER NO CIRCUMSTANCES DO NOT EDIT THIS FILE. THIS FILE IS COPIED ***/ | ||
/*** FROM OSS UI. ANY CHANGES TO BE MADE IN KUBEVIOUS OSS UI. ***/ | ||
/*** SOURCE: ../ui.git/src/src/components/Alerts/AlertView/index.js ***/ | ||
|
||
import React, { useState } from 'react' | ||
import { parseDn } from '../../../utils/naming-utils'; | ||
import cx from 'classnames' | ||
import { prettyKind } from '../../../utils/ui-utils'; | ||
import { sortSeverity, uniqueMessages, uniqueObjects } from '../../../utils/util'; | ||
|
||
const AlertView = ({ alerts, clickDn, openRule }) => { | ||
const [group, setGroup] = useState('no') | ||
|
||
const clickMessage = (alert) => { | ||
if (alert.source.kind === 'rule') { | ||
openRule(alert.source.id) | ||
} | ||
} | ||
|
||
const renderAlert = ({ alert, index, shouldRenderDn = true }) => { | ||
return ( | ||
<div className={cx('alert-detail', { 'even': index % 2 !== 0 })} key={alert.id}> | ||
<div className={cx('message-container', { 'rule': alert.source.kind === 'rule' })} | ||
onClick={() => clickMessage(alert)}> | ||
<div className={'alert-item ' + alert.severity} /> | ||
{alert.msg} | ||
</div> | ||
|
||
{shouldRenderDn && renderDnParts(alert.dn)} | ||
</div> | ||
) | ||
} | ||
|
||
const renderDnParts = (dn) => { | ||
const dnParts = parseDn(dn).slice(1) | ||
|
||
return ( | ||
<div className="dn-container" key={dn} onClick={() => clickDn(dn)}> | ||
<div className="logo-container"> | ||
<img className="dn-logo" src="/img/entities/ns.svg" alt="logo" /> | ||
</div> | ||
<div className="parts-container"> | ||
{dnParts.map(part => ( | ||
<span className="dn-part" key={part.name}> | ||
{prettyKind(part.kind)} {part.name} | ||
</span> | ||
))} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
const renderMessageGroup = () => { | ||
const messages = uniqueMessages(alerts.map(({ msg, severity, source }) => ({ msg, severity, source }))) | ||
.map(m => ({ | ||
...m, | ||
alerts: alerts.filter(a => a.severity === m.severity && a.msg === m.msg), | ||
})).sort(sortSeverity) | ||
|
||
return ( | ||
<> | ||
{messages.map((message, index) => ( | ||
<div className="message-group-container" key={index}> | ||
<div className="message-container" onClick={() => clickMessage(message)}> | ||
<div className={'alert-item ' + message.severity} /> | ||
{message.msg} | ||
</div> | ||
|
||
<div className="message-objects"> | ||
{message.alerts.map(alert => renderDnParts(alert.dn))} | ||
</div> | ||
</div> | ||
))} | ||
</> | ||
) | ||
} | ||
|
||
const renderObjectGroup = () => { | ||
const objects = uniqueObjects(alerts.map(({ dn }) => ({ dn }))) | ||
.map(o => ({ | ||
...o, | ||
alerts: alerts.filter(a => a.dn === o.dn), | ||
})) | ||
|
||
return ( | ||
<> | ||
{objects.map((object, index) => ( | ||
<div className="message-group-container" key={index}> | ||
<div className="object-container"> | ||
{renderDnParts(object.dn)} | ||
</div> | ||
|
||
<div className="message-objects"> | ||
{object.alerts.map(alert => renderAlert({ alert, shouldRenderDn: false }))} | ||
</div> | ||
</div> | ||
))} | ||
</> | ||
) | ||
} | ||
|
||
return ( | ||
<div className="AlertView-container"> | ||
<div className={`alerts group-${group}`}> | ||
{group === 'no' && <> | ||
{alerts.map((alert, index) => renderAlert({ alert, index }))} | ||
</>} | ||
|
||
{group === 'message' && renderMessageGroup()} | ||
|
||
{group === 'object' && renderObjectGroup()} | ||
</div> | ||
|
||
|
||
<div className="group-options"> | ||
<div | ||
className={cx('option', { 'selected': group === 'no' })} | ||
onClick={() => setGroup('no')} | ||
> | ||
No Group | ||
</div> | ||
|
||
<div | ||
className={cx('option', { 'selected': group === 'object' })} | ||
onClick={() => setGroup('object')} | ||
> | ||
Group by Object | ||
</div> | ||
|
||
<div | ||
className={cx('option', { 'selected': group === 'message' })} | ||
onClick={() => setGroup('message')} | ||
> | ||
Group by Message | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default AlertView |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.