Skip to content

Commit b030dc6

Browse files
committed
feat: enabled selection and display of policy content
1 parent 9d541ae commit b030dc6

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import React, { useEffect, useState } from "react";
2-
import { createPolicy, doPolicyFlowFromString, readPolicyDirectory } from "../util/PolicyManagement";
2+
import { createPolicy, doPolicyFlowFromString, readPolicy, readPolicyDirectory } from "../util/PolicyManagement";
33
import PolicyModal from "./Modal";
44
import { SimplePolicy } from "../util/policyCreation";
55

66
export default function Home() {
77

8-
const [policyList, setPolicyList] = useState([] as SimplePolicy[])
8+
const [policyList, setPolicyList] = useState<SimplePolicy[]>([])
9+
const [selectedPolicy, setSelectedPolicy] = useState<null|string>(null)
910

1011
useEffect(() => {
1112
async function getPolicies() {
@@ -14,22 +15,27 @@ export default function Home() {
1415
}
1516
getPolicies()
1617
}, [])
17-
1818

1919
async function addPolicy(policyText: string) {
2020
console.log('Adding the following policy:')
2121
console.log(policyText)
2222
await doPolicyFlowFromString(policyText)
23+
const policyObject = await readPolicy(policyText)
24+
setPolicyList(policyList.concat(policyObject))
2325
}
2426

2527
function renderPolicy(policy: SimplePolicy) {
2628
return (
27-
<div className="policyentry">
29+
<div key={policy.policyLocation} className={`policyentry ${policy.policyIRI === selectedPolicy ? 'selectedentry' : ''}`} onClick={() => setSelectedPolicy(policy.policyIRI)}>
2830
<p>{policy.policyIRI}</p>
2931
</div>
3032
)
3133
}
3234

35+
const selectedPolicyText = selectedPolicy
36+
? policyList.filter(p => p.policyIRI === selectedPolicy)[0]?.policyText || ''
37+
: ''
38+
3339
return (
3440
<div id="policypage">
3541
<div id="policymanagementcontainer" className="rowcontainer">
@@ -42,9 +48,9 @@ export default function Home() {
4248
<PolicyModal addPolicy={addPolicy}/>
4349
</div>
4450
<div id="PolicyDisplayScreen">
45-
<textarea id="policyview" readOnly/>
51+
<textarea id="policyview" value={selectedPolicyText} readOnly/>
4652
</div>
4753
</div>
4854
</div>
4955
)
50-
}
56+
}

demo/data/demo/public/authorizationsite/src/index.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ nav {
7878
background-color:beige;
7979
}
8080

81+
.selectedentry {
82+
background-color:lightblue;
83+
}
84+
8185
#PolicyDisplayScreen {
8286
display: flex;
8387
align-items: center;
@@ -93,4 +97,4 @@ nav {
9397

9498
#PolicyListContainer {
9599
flex: 40%;
96-
}
100+
}

demo/data/demo/public/authorizationsite/src/util/PolicyManagement.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export async function readPolicyDirectory () {
6060

6161
}
6262

63-
async function readPolicy(policyText: string) {
63+
export async function readPolicy(policyText: string) {
6464
const parsed = await new Parser().parse(policyText)
6565
const store = new Store()
6666
store.addQuads(parsed)
@@ -69,7 +69,8 @@ async function readPolicy(policyText: string) {
6969
let simplePolicy: SimplePolicy = {
7070
representation: store,
7171
policyIRI,
72-
ruleIRIs: [ruleIRI]
72+
ruleIRIs: [ruleIRI],
73+
policyText: policyText,
7374
}
7475

7576
return simplePolicy

demo/data/demo/public/authorizationsite/src/util/policyCreation.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export interface SimplePolicy {
1414
policyIRI: string;
1515
// identifier of the rule
1616
ruleIRIs: string[];
17+
18+
policyLocation?: string;
19+
policyText?: string;
1720
}
1821

1922
/**

0 commit comments

Comments
 (0)