From 0bb1ebc968b8b0cffc927f95285a6c7dcd9ed0c7 Mon Sep 17 00:00:00 2001 From: Christoph Anderson <37236531+lupusA@users.noreply.github.com> Date: Mon, 25 Sep 2023 20:38:55 +0200 Subject: [PATCH] fix(ui): Fix missing badges in policy table (#194) * Fix missing badges in policies * Childs now have unique key in list * Added isEmptyObject() --------- Co-authored-by: Christoph Anderson --- src/PoliciesTable.jsx | 60 ++++++++++++++++++++++--------------------- src/css/App.css | 7 +++++ 2 files changed, 38 insertions(+), 29 deletions(-) diff --git a/src/PoliciesTable.jsx b/src/PoliciesTable.jsx index bc5102b..6d0463a 100644 --- a/src/PoliciesTable.jsx +++ b/src/PoliciesTable.jsx @@ -120,36 +120,38 @@ export class PoliciesTable extends Component { }); } - policySummary(p) { + policySummary(policies) { + let bits = []; + /** + * Check if the object is empty + * @param {*} obj + * @returns true if the object is empty + */ + function isEmptyObject(obj) { + return ( + Object.getPrototypeOf(obj) === Object.prototype && + Object.getOwnPropertyNames(obj).length === 0 && + Object.getOwnPropertySymbols(obj).length === 0 + ); + } + /** + * Check if object has it's key as a property. + * However, if the object itself is a set of sets, it has to be checked by isEmptyObject() + * @param {*} obj + * @returns + */ function isEmpty(obj) { for (var key in obj) { if (obj.hasOwnProperty(key)) - return false; + return isEmptyObject(obj[key]); } - return true; } - - let bits = []; - if (!isEmpty(p.policy.retention)) { - bits.push(<>retention{' '}); - } - if (!isEmpty(p.policy.files)) { - bits.push(<>files{' '}); - } - if (!isEmpty(p.policy.errorHandling)) { - bits.push(<>errors{' '}); - } - if (!isEmpty(p.policy.compression)) { - bits.push(<>compression{' '}); - } - if (!isEmpty(p.policy.scheduling)) { - bits.push(<>scheduling{' '}); - } - if (!isEmpty(p.policy.upload)) { - bits.push(<>upload{' '}); + for (let pol in policies.policy) { + if (!isEmpty(policies.policy[pol])) { + bits.push({pol}); + } } - return bits; } @@ -213,16 +215,16 @@ export class PoliciesTable extends Component { break; }; - policies.sort((l,r) => { - const hc = compare(l.target.host,r.target.host); + policies.sort((l, r) => { + const hc = compare(l.target.host, r.target.host); if (hc) { return hc; } - const uc = compare(l.target.userName,r.target.userName); + const uc = compare(l.target.userName, r.target.userName); if (uc) { return uc; } - return compare(l.target.path,r.target.path); + return compare(l.target.path, r.target.path); }); @@ -273,8 +275,8 @@ export class PoliciesTable extends Component { {(this.state.selectedOwner === localPolicies || this.state.selectedOwner === this.state.localSourceName || this.state.selectedOwner === applicablePolicies) ? <> this.setState({ policyPath: p })} - placeholder="enter directory to find or set policy" - name="policyPath" value={this.state.policyPath} onChange={this.handleChange} /> + placeholder="enter directory to find or set policy" + name="policyPath" value={this.state.policyPath} onChange={this.handleChange} /> diff --git a/src/css/App.css b/src/css/App.css index 221a26b..abe1f3a 100644 --- a/src/css/App.css +++ b/src/css/App.css @@ -327,6 +327,13 @@ div.tab-body { margin: 2px; } +.policy-badge { + margin-block-start: 5px; + margin-right: 5px; + background-color: var(--color-primary) !important; + color: var(--text-color) !important; +} + .page-title { margin-left: 10px; font-weight: bold;