From 6f8df9a2d64d65478354914f22ff931325aa69d8 Mon Sep 17 00:00:00 2001 From: Christoph Anderson Date: Sat, 23 Sep 2023 14:38:51 +0200 Subject: [PATCH 1/3] Fix missing badges in policies --- src/PoliciesTable.jsx | 40 ++++++++++++---------------------------- src/css/App.css | 7 +++++++ 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/src/PoliciesTable.jsx b/src/PoliciesTable.jsx index bc5102b..26467a4 100644 --- a/src/PoliciesTable.jsx +++ b/src/PoliciesTable.jsx @@ -120,36 +120,20 @@ export class PoliciesTable extends Component { }); } - policySummary(p) { + policySummary(policies) { + let bits = []; function isEmpty(obj) { for (var key in obj) { if (obj.hasOwnProperty(key)) return false; } - 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 +197,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 +257,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; From 856a5fbe0583372caabde10c8333ae2896892c0f Mon Sep 17 00:00:00 2001 From: Christoph Anderson Date: Sat, 23 Sep 2023 16:35:23 +0200 Subject: [PATCH 2/3] Childs now have unique key in list --- src/PoliciesTable.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PoliciesTable.jsx b/src/PoliciesTable.jsx index 26467a4..2725127 100644 --- a/src/PoliciesTable.jsx +++ b/src/PoliciesTable.jsx @@ -131,7 +131,7 @@ export class PoliciesTable extends Component { } for (let pol in policies.policy) { if (!isEmpty(policies.policy[pol])) { - bits.push(<>{pol}); + bits.push({pol}); } } return bits; From 9985ceaa5c7dcdabf929462a25143e90340cd125 Mon Sep 17 00:00:00 2001 From: Christoph Anderson Date: Mon, 25 Sep 2023 20:35:10 +0200 Subject: [PATCH 3/3] Added isEmptyObject() --- src/PoliciesTable.jsx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/PoliciesTable.jsx b/src/PoliciesTable.jsx index 2725127..6d0463a 100644 --- a/src/PoliciesTable.jsx +++ b/src/PoliciesTable.jsx @@ -122,10 +122,28 @@ export class PoliciesTable extends Component { 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; }