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

fix(ui): Fix missing badges in policy table #194

Merged
merged 3 commits into from
Sep 25, 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
60 changes: 31 additions & 29 deletions src/PoliciesTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<><Badge bg="success">retention</Badge>{' '}</>);
}
if (!isEmpty(p.policy.files)) {
bits.push(<><Badge bg="primary">files</Badge>{' '}</>);
}
if (!isEmpty(p.policy.errorHandling)) {
bits.push(<><Badge bg="danger">errors</Badge>{' '}</>);
}
if (!isEmpty(p.policy.compression)) {
bits.push(<><Badge bg="secondary">compression</Badge>{' '}</>);
}
if (!isEmpty(p.policy.scheduling)) {
bits.push(<><Badge bg="warning">scheduling</Badge>{' '}</>);
}
if (!isEmpty(p.policy.upload)) {
bits.push(<><Badge bg="info">upload</Badge>{' '}</>);
for (let pol in policies.policy) {
if (!isEmpty(policies.policy[pol])) {
bits.push(<Badge className="policy-badge" key={pol}>{pol}</Badge>);
}
}

return bits;
}

Expand Down Expand Up @@ -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);
});


Expand Down Expand Up @@ -273,8 +275,8 @@ export class PoliciesTable extends Component {
{(this.state.selectedOwner === localPolicies || this.state.selectedOwner === this.state.localSourceName || this.state.selectedOwner === applicablePolicies) ? <>
<Col>
<DirectorySelector autoFocus onDirectorySelected={p => 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} />
</Col>
<Col xs="auto">
<Button disabled={!this.state.policyPath} size="sm" type="submit" onClick={this.editPolicyForPath}>Set Policy</Button>
Expand Down
7 changes: 7 additions & 0 deletions src/css/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading