Skip to content

Commit cafa88a

Browse files
committed
beautifying
1 parent a162ee5 commit cafa88a

File tree

5 files changed

+63
-8
lines changed

5 files changed

+63
-8
lines changed

packages/tdb-dashboard/src/App.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ pre.CodeMirror-line > span > span.cm-string {
12121212
border: 1px solid #f5c2c7 !important;
12131213
}
12141214

1215-
.alert_more_info_border {
1215+
.alert_danger_border {
12161216
border: 1px solid #842029 !important;
12171217
}
12181218

packages/tdb-dashboard/src/components/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ export function sortAlphabetically (list, byID) {
322322
})
323323
}
324324

325-
// function which displays CR Conflict errors
325+
// function which displays CR Conflict errors
326326
export const getCRConflictError = (errorData) => {
327327
//const [showError, setShowError] = useState(false)
328328
let message = "It looks like there are conflicts, fix these conflicts and then update or exit the Change Request"

packages/tdb-dashboard/src/hooks/DocumentControlContext.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ export const DocumentControlContext = React.createContext()
33
export const DocumentControlObj = () => useContext(DocumentControlContext)
44
import {WOQLClientObj} from '../init-woql-client'
55
import * as CONST from "../components/constants"
6+
import { ErrorDisplay } from "../components/ErrorDisplay"
7+
import Stack from "react-bootstrap/Stack"
8+
69

710
export const DocumentControlProvider = ({children}) => {
811

@@ -37,6 +40,26 @@ export const DocumentControlProvider = ({children}) => {
3740

3841

3942

43+
// function to format and display errors in document Interface
44+
function formatErrorMessages (error) {
45+
let message = error["api:message"]
46+
let errorElements = []
47+
if(error["api:error"]) {
48+
if(Array.isArray(error["api:error"]["api:witnesses"])) {
49+
error["api:error"]["api:witnesses"].map(err => {
50+
errorElements.push(<Stack className="mb-3">
51+
<div className="fw-bold d-flex">
52+
{`${err["@type"]} on `}
53+
<pre className="alert_danger_border ml-1 p-1 rounded">{err["constraint_name"]}</pre>
54+
</div>
55+
<div>{err.message}</div>
56+
</Stack>)
57+
})
58+
}
59+
}
60+
return <ErrorDisplay errorData={errorElements} message={message}/>
61+
}
62+
4063
return (
4164
<DocumentControlContext.Provider
4265
value={{
@@ -46,7 +69,8 @@ export const DocumentControlProvider = ({children}) => {
4669
jsonContent,
4770
setJsonContent,
4871
showFrames,
49-
setShowFrames
72+
setShowFrames,
73+
formatErrorMessages
5074
}}
5175
>
5276
{children}

packages/tdb-dashboard/src/hooks/DocumentHook.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useNavigate, useParams } from "react-router-dom";
44
import { ChangeRequest } from "./ChangeRequest";
55
import { WOQLClientObj } from "../init-woql-client";
66

7+
78
// to be review this
89
export function CheckStatusObj() {
910
const {currentChangeRequest} = WOQLClientObj()

packages/tdb-dashboard/src/pages/DocumentNew.js

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import Alert from 'react-bootstrap/Alert'
1212
import {DocumentControlObj} from "../hooks/DocumentControlContext"
1313
import {Loading} from "../components/Loading"
1414
import {CreateChangeRequestModal} from "../components/CreateChangeRequestModal"
15+
import { Alerts } from "../components/Alerts"
1516

1617

1718
const checkIfPrefix =(id)=>{
@@ -52,6 +53,7 @@ const onSelect = async (inp, type) => {
5253
return results
5354
}
5455

56+
5557
const DisplayDocumentBody = ({setLoading, setErrorMsg}) => {
5658
const {
5759
woqlClient,
@@ -102,17 +104,44 @@ const DisplayDocumentBody = ({setLoading, setErrorMsg}) => {
102104
/>
103105
}
104106

107+
108+
const FAKE_ERROR = {
109+
"@type":"api:InsertDocumentErrorResponse",
110+
"api:error": {
111+
"@type":"api:SchemaCheckFailure",
112+
"api:witnesses": [
113+
{
114+
"@type":"ConstraintFailure",
115+
"constraint_name":"MidLifeInsurance",
116+
"message":"Failed to satisfy: 12 > 30\n\n\n In the Constraint:\n\n( 'Policy/3':'Policy'\n ∧ 'Policy/3' =[insurance_product]> 'MidLifeInsurance/Mid-Life%20Insurance%20Product'\n ∧ 'MidLifeInsurance/Mid-Life%20Insurance%20Product':'MidLifeInsurance'\n ) ⇒\n 'Policy/3' =[customer]> 'Customer/Jill+Curry+2'\n ∧ 'Customer/Jill+Curry+2' =[age]> 12\n ∧ « 12 > 30\n » ∧ 12 < 60\n \n"
117+
},
118+
{
119+
"@type":"ConstraintFailure",
120+
"constraint_name":"Policy",
121+
"message":"Failed to satisfy: 12 > 30\n\n\n In the Constraint:\n\n( 'Policy/3':'Policy'\n ∧ 'Policy/3' =[insurance_product]> 'MidLifeInsurance/Mid-Life%20Insurance%20Product'\n ∧ 'MidLifeInsurance/Mid-Life%20Insurance%20Product':'MidLifeInsurance'\n ) ⇒\n 'Policy/3' =[customer]> 'Customer/Jill+Curry+2'\n ∧ 'Customer/Jill+Curry+2' =[age]> 12\n ∧ « 12 > 30\n » ∧ 12 < 60\n \n"
122+
}
123+
]
124+
},
125+
"api:message":"Schema check failure",
126+
"api:status":"api:failure"
127+
}
128+
105129
export const DocumentNew = () => {
106130
const {
107131
setChangeRequestBranch, branch,woqlClient
108132
} = WOQLClientObj()
109133

134+
const {
135+
formatErrorMessages
136+
} = DocumentControlObj()
137+
110138

111139
const [showModal, setShowModal] = useState(false)
112140
const {type} = useParams()
113141

114142
const [loading, setLoading]=useState(false)
115-
const [errorMsg, setErrorMsg]=useState(false)
143+
//const [errorMsg, setErrorMsg]=useState(false)
144+
const [errorMsg, setErrorMsg]=useState(FAKE_ERROR)
116145

117146
useEffect(() => {
118147
if(branch === "main"){
@@ -127,16 +156,17 @@ export const DocumentNew = () => {
127156
// setCurrentMode(currentMode)
128157
}
129158

130-
return <main className="content w-100 document__interface__main">
131-
{errorMsg && <Alert variant={"danger"} className="mr-3">
159+
return <main className="content w-100 document__interface__main">
160+
{errorMsg && <Alerts message={formatErrorMessages(errorMsg)} type={CONST.TERMINUS_DANGER} onCancel={setErrorMsg}/>}
161+
{/*errorMsg && <Alert variant={"danger"} className="mr-3">
132162
{errorMsg}
133-
</Alert>}
163+
</Alert>*/}
134164
{showModal && <CreateChangeRequestModal showModal={showModal}
135165
type={type}
136166
setShowModal={setShowModal}
137167
updateViewMode={updateViewMode}/>}
138168
{branch !== "main" &&
139-
<Card className="mr-3 bg-dark">
169+
<Card className="bg-dark">
140170
<Card.Header className="justify-content-between d-flex w-100 text-break">
141171
<Header mode={CONST.CREATE_DOCUMENT} type={type}/>
142172
</Card.Header>

0 commit comments

Comments
 (0)