Skip to content

Commit 9206f67

Browse files
committed
fix issue #173 #170 #169 #168
1 parent d544fd8 commit 9206f67

File tree

14 files changed

+175
-132
lines changed

14 files changed

+175
-132
lines changed

packages/tdb-dashboard/src/App.css

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,4 +1281,41 @@ button.graphiql-tab-add>svg
12811281

12821282
.alert_expand_icons {
12831283
margin-top: -20px;
1284+
}
1285+
1286+
.group {
1287+
background: transparent !important;
1288+
border: 1px solid #dee2e6;
1289+
}
1290+
1291+
.rule {
1292+
background: transparent !important;
1293+
border: 1px solid #dee2e6;
1294+
padding: 10px;
1295+
}
1296+
1297+
.rule--field > .dropdown > .form-select {
1298+
min-width: 200px;
1299+
line-height: 1.5 !important;
1300+
min-height: 40px !important;
1301+
/* background: transparent !important; */
1302+
color: black;
1303+
}
1304+
1305+
.rule--operator > .dropdown > .form-select {
1306+
min-width: 100px;
1307+
line-height: 1.5 !important;
1308+
min-height: 40px !important;
1309+
/* background: transparent !important; */
1310+
color: black;
1311+
}
1312+
1313+
.widget--widget > .form-control{
1314+
min-width: 250px;
1315+
line-height: 1.5 !important;
1316+
min-height: 40px !important;
1317+
}
1318+
1319+
.accordion{
1320+
--bs-accordion-bg: #303030 !important;
12841321
}

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {ChangeRequest} from "../hooks/ChangeRequest"
44
import {useNavigate} from "react-router-dom"
55

66
export const CreateChangeRequestModal = ({showModal, setShowModal , updateViewMode, type}) => {
7-
const nameRef = useRef(null);
7+
//const nameRef = useRef(null);
88
const messageRef = useRef(null);
99
const {loading,errorMessage,setError,createChangeRequest} = ChangeRequest()
1010
const navigate = useNavigate()
@@ -14,17 +14,17 @@ export const CreateChangeRequestModal = ({showModal, setShowModal , updateViewMo
1414
}
1515

1616
const runCreate = async () => {
17-
const name = nameRef.current.value
17+
// const name = nameRef.current.value
1818
const message = messageRef.current.value
19-
if(!name || name === "" || !message || message === "") {
20-
setError("Change request name and message are mandatory")
19+
if(!message || message === "") {
20+
setError("Change request message is mandatory")
2121
return
2222
}else{
23-
const changeReqId = await createChangeRequest(name, message)
24-
if(changeReqId){
25-
nameRef.current.value = ""
23+
const {changeRequestId,branchName} = await createChangeRequest(message)
24+
if(changeRequestId){
25+
//nameRef.current.value = ""
2626
messageRef.current.value = ""
27-
updateViewMode(name,changeReqId)
27+
updateViewMode(branchName,changeRequestId)
2828
setShowModal(false)
2929
}
3030
}
@@ -40,15 +40,7 @@ export const CreateChangeRequestModal = ({showModal, setShowModal , updateViewMo
4040
<Modal.Body className="p-3">
4141
{errorMessage &&
4242
<Alert variant="danger" onClose={() => setError(false)} dismissible>{errorMessage}</Alert>}
43-
<Form>
44-
<Form.Group className="mb-3 tdb__input">
45-
<Form.Control required
46-
ref={nameRef}
47-
id="add_changerequest_name"
48-
type="text"
49-
placeholder={`Please type the change request name`} />
50-
51-
</Form.Group>
43+
<Form>
5244
<Form.Group className="tdb__input">
5345
<Form.Control required
5446
ref={messageRef}
@@ -71,3 +63,12 @@ export const CreateChangeRequestModal = ({showModal, setShowModal , updateViewMo
7163
</Modal>
7264
}
7365

66+
/*<Form.Group className="mb-3 tdb__input">
67+
<Form.Control required
68+
ref={nameRef}
69+
id="add_changerequest_name"
70+
type="text"
71+
placeholder={`Please type the change request name`} />
72+
73+
</Form.Group>*/
74+

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

Lines changed: 39 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,28 @@ import 'codemirror/theme/material-darker.css'
99
//import 'codemirror/addon/display/autorefresh.js'
1010
import {PROGRESS_BAR_COMPONENT, TERMINUS_SUCCESS} from "./constants"
1111
import {Loading} from "./Loading"
12+
import {Alert} from "react-bootstrap"
1213
import {MODEL_BUILDER_EDITOR_OPTIONS} from "./constants"
1314
import { BiUndo } from "react-icons/bi"
1415
import {FaRegEdit} from 'react-icons/fa'
15-
import {Alerts} from "./Alerts"
16+
//import {Alerts} from "./Alerts"
1617
import {TERMINUS_DANGER,DOCUMENT_PREFIX} from "./constants"
1718
import {GRAPH_TAB} from "../pages/constants"
1819
import {GraphContextObj} from "@terminusdb-live/tdb-react-components"
1920
import {CopyButton} from "./utils"
2021
import Card from "react-bootstrap/Card"
2122
import {BsSave} from "react-icons/bs"
2223
import Stack from "react-bootstrap/Stack"
24+
import {modelCallServerHook} from "@terminusdb-live/tdb-react-components"
2325

24-
export const JSONModelBuilder = ({tab,saveGraph,accessControlEditMode, setReportMessage}) => {
26+
// we moved the save data at this level or we lost our change if there is an error
27+
export const JSONModelBuilder = ({tab,accessControlEditMode}) => {
2528

26-
const {getSchemaGraph,mainGraphObj} = GraphContextObj();
27-
const {dataProduct} = WOQLClientObj()
28-
const [loading, setLoading] = useState(false)
29-
const [error, setError] = useState(false)
29+
const {getSchemaGraph,mainGraphObj,updateMainGraphData} = GraphContextObj();
30+
const {dataProduct,woqlClient} = WOQLClientObj()
31+
// const [loading, setLoading] = useState(false)
3032
const [commitMsg, setCommitMessage]=useState("Add new schema")
31-
const [report, setReport]=useState(false)
32-
33+
3334
const [jsonSchema, setJsonSchema]=useState(false)
3435

3536
const [editMode, setEditMode]=useState(false)
@@ -38,83 +39,81 @@ export const JSONModelBuilder = ({tab,saveGraph,accessControlEditMode, setReport
3839
let branch = "main"
3940
let ref = ""
4041

42+
43+
const {saveGraphChanges,
44+
reportMessage,
45+
setReport,
46+
callServerLoading:loading,
47+
} = modelCallServerHook(woqlClient, branch, ref,dataProduct)
48+
4149
const onBlurHandler = (value) =>{
4250
setValue(value)
4351
}
4452

45-
async function getJSONSchema () {
53+
async function loadSchema () {
54+
setEditMode(false);
55+
setReport(false)
4656
//get the schema from the mainGraphObj
4757
//the result is the schema in json format
48-
const resultJson = getSchemaGraph()// await woqlClient.getDocument(params, dataProduct)
58+
const resultJson = await getSchemaGraph()// await woqlClient.getDocument(params, dataProduct)
4959
setJsonSchema(resultJson)
5060
setValue(resultJson)
5161
}
5262

5363
useEffect(() => {
5464
if(tab == GRAPH_TAB) return
55-
setEditMode(false)
56-
getJSONSchema()
65+
loadSchema()
5766
}, [tab,dataProduct,mainGraphObj])
5867

5968

6069

61-
6270
MODEL_BUILDER_EDITOR_OPTIONS.readOnly=!editMode
6371

6472
function handleCommitMessage (e) {
6573
setCommitMessage(e.target.value)
6674
}
6775

6876

69-
async function saveChange (){
70-
setLoading(<Loading message={"Updating schema"} type={PROGRESS_BAR_COMPONENT}/>)
71-
77+
async function saveGraph (){
7278
if(value) {
73-
try{
74-
//save change in the server
75-
await saveGraph(value, commitMsg)
76-
setLoading(false)
77-
//setEditMode(false)
78-
79-
}catch(err){
80-
let jsonError= JSON.parse(JSON.stringify(err))
81-
setLoading(false)
82-
if(jsonError.data && jsonError.data["api:message"]) {
83-
setReport(<Alerts message={jsonError.data["api:message"]} type={TERMINUS_DANGER}/>)
84-
}
85-
else setReport(<Alerts message={err.toString()} type={TERMINUS_DANGER}/>)
86-
}
79+
const result = await saveGraphChanges(value, commitMsg)
80+
if(result){
81+
const resultJson = JSON.stringify(result,null,4)
82+
updateMainGraphData(result)
83+
setJsonSchema(resultJson)
84+
setValue(resultJson)
85+
setEditMode(false);
86+
}
8787
}
8888
}
8989

90-
function handleUndo () {
91-
// sets report messagen from modelCallServerHook to false
92-
if(setReportMessage) setReportMessage(false)
93-
setEditMode(false);
94-
getJSONSchema();
95-
}
96-
9790
const editStyle = editMode ? {className:"border rounded border-warning position-sticky"} : {}
9891
const editMessage = editMode ? "Save schema or you will lose your changes" : ""
9992

10093
//console.log("editMode", editMode)
10194
return <>
10295
<label className="text-warning mt-4">{editMessage}</label>
96+
{reportMessage && !loading &&
97+
<Alert className ="mt-3" variant="danger" dismissible onClose={() => setReport(false)}>
98+
<Alert.Heading>{reportMessage.message.title}</Alert.Heading>
99+
100+
<p>{reportMessage.message.text}</p>
101+
</Alert>}
103102
<Card className={`border border-secondary mt-4`} {...editStyle}>
104-
{loading && loading}
103+
{loading && <Loading message={"Updating schema"} type={PROGRESS_BAR_COMPONENT}/>}
105104
<Card.Header>
106105
<Stack direction="horizontal" className="w-100 justify-content-end">
107106
{editMode && <div className="w-100">
108107
<div role="group" className="btn-group w-100">
109108
<div className="col-md-10 pr-0 pl-0">
110109
<input id="schema_save_description" placeholder={"Enter a description to tag update"} type="text" className="form-control" onBlur={handleCommitMessage}/>
111110
</div>
112-
<button type="button" id="schema_save_button" className="btn btn-sm bg-light text-dark" onClick={saveChange}>
111+
<button type="button" id="schema_save_button" className="btn btn-sm bg-light text-dark" onClick={saveGraph}>
113112
<BsSave className="small"/> {"Save"}
114113
</button>
115114
<button type="button"
116115
title="Undo changes"
117-
className="btn btn-sm bg-danger text-white mr-2" onClick={()=>{ handleUndo() }}>
116+
className="btn btn-sm bg-danger text-white mr-2" onClick={()=>{ loadSchema() }}>
118117
<BiUndo className="h5"/> {"Undo"}
119118
</button>
120119
</div>
@@ -133,7 +132,6 @@ export const JSONModelBuilder = ({tab,saveGraph,accessControlEditMode, setReport
133132
</Stack>
134133
</Card.Header>
135134
<div className="h-100">
136-
{report && <span className="w-100 m-4">{report}</span>}
137135
<CodeMirror
138136
onBlur={(editor, data) => {
139137
const editorValue =editor.doc.getValue()

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

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ import ToggleButton from 'react-bootstrap/ToggleButton';
1111
import {Loading} from "../components/Loading"
1212
import { MessageBox, MessageComponent } from "./Messages"
1313
import {AiOutlineCheck, AiOutlineClose} from "react-icons/ai"
14+
import {Alerts} from "./Alerts"
1415

15-
const ToggleActions = ({ message }) => {
16+
const ToggleActions = ({ message, updateChangeRequestStatus , loading}) => {
1617
const { setCurrentCRObject, exitChangeRequestBranch }= WOQLClientObj()
17-
const { updateChangeRequestStatus, loading, error } = ChangeRequest()
1818
const { organization, dataProduct , changeid} = useParams()
19+
const [loadingMessage,setLoadingMessage] = useState(`Approving Change Request ...`)
1920
const navigate = useNavigate()
20-
let action = CONST.APPROVE
2121

2222
async function doAction(submitAction) {
23-
action = submitAction
23+
if(submitAction !== CONST.APPROVE ) setLoadingMessage(`Rejecting Change Request ...`)
2424
let status = submitAction === CONST.APPROVE ? CONST.MERGED : CONST.REJECTED
2525
let res=await updateChangeRequestStatus(message, status, changeid)
2626
if(res){
@@ -35,7 +35,7 @@ const ToggleActions = ({ message }) => {
3535
{ name: CONST.REJECT, value: CONST.REJECT , className: "rounded-right", variant: "outline-danger", icon: <AiOutlineClose className="mr-1 mb-1 text-danger"/> }
3636
];
3737

38-
if(loading) return <Loading message={action === CONST.APPROVE ? `Approving Change Request ...` : `Rejecting Change Request ...`}/>
38+
if(loading) return <Loading message={loadingMessage}/>
3939

4040
return <Stack directtion="horizontal" className="float-right">
4141
<small className="text-muted fst-italic fw-light mr-2 ms-auto">
@@ -60,23 +60,13 @@ const ToggleActions = ({ message }) => {
6060
</Stack>
6161
}
6262

63-
64-
/**
65-
* @returns view based on CR actions
66-
*/
67-
export const Review = ({ message, setMessage }) => {
68-
return <React.Fragment>
69-
<MessageBox setMessage={setMessage} message={message}/>
70-
<ToggleActions message={message}/>
71-
</React.Fragment>
72-
}
73-
7463
export const ReviewComponent = () => {
7564
const {
7665
userHasMergeRole,
7766
currentCRObject
7867
}= WOQLClientObj()
7968

69+
const { updateChangeRequestStatus, loading, errorMessage, setError } = ChangeRequest()
8070
// feedback constants
8171
const [message, setMessage]=useState("")
8272

@@ -86,17 +76,21 @@ export const ReviewComponent = () => {
8676
return <MessageComponent/>
8777
}*/
8878

89-
return <Card className="bg-transparent border border-dark m-3">
90-
<Card.Header className="bg-transparent border border-dark">
91-
<Stack direction="horizontal" gap={3} className="text-right w-100">
92-
<h6>Submit your Review</h6>
93-
<span className="text-light ms-auto">{`Status:`}</span>
94-
{status[currentCRObject.status]}
95-
</Stack>
96-
</Card.Header>
97-
<Card.Body>
98-
<Review message={message} setMessage={setMessage}/>
99-
</Card.Body>
100-
</Card>
79+
return <React.Fragment>
80+
{errorMessage && <Alerts message={errorMessage} type={CONST.TERMINUS_DANGER} onCancel={setError}/>}
81+
<Card className="bg-transparent border border-dark m-3">
82+
<Card.Header className="bg-transparent border border-dark">
83+
<Stack direction="horizontal" gap={3} className="text-right w-100">
84+
<h6>Submit your Review</h6>
85+
<span className="text-light ms-auto">{`Status:`}</span>
86+
{status[currentCRObject.status]}
87+
</Stack>
88+
</Card.Header>
89+
<Card.Body>
90+
<MessageBox setMessage={setMessage} message={message}/>
91+
<ToggleActions message={message} loading={loading} updateChangeRequestStatus={updateChangeRequestStatus}/>
92+
</Card.Body>
93+
</Card>
94+
</React.Fragment>
10195

10296
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ export function ChangeRequest(){
1818
return client.connectionConfig.dbBase("changes")
1919
}
2020

21-
const createChangeRequest = async(branchName, message) =>{
21+
const createChangeRequest = async(message) =>{
2222
try{
2323
setLoading(true)
24-
const payload = {tracking_branch:branchName,
25-
original_branch:"main",
24+
const payload = {original_branch:"main",
2625
message:message,
2726
author:woqlClient.user()}
2827
const result = await woqlClient.sendCustomRequest("POST", getUrl(),payload)
29-
return result.change_request_id
28+
//{changeRequestId,branchName}
29+
return result
3030
}catch(err){
3131
const errMessage = formatErrorMessage(err)
3232
setError(errMessage)

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,15 +224,19 @@ export const DocumentControlProvider = ({children}) => {
224224
const params={id:documentId}
225225
let commitMsg=`Deleting document ${documentId}`
226226
const res = await woqlClient.deleteDocument(params, dataProduct, commitMsg)
227-
return res
227+
return true
228228
}catch(err){
229229
setError(`I can not delete the document ${err.message}`)
230230
}finally{setLoading(false)}
231231
}
232232

233233

234234
// check if the current change request is still open
235-
async function checkStatus (){
235+
async function checkStatus (){
236+
// I can decide to change a document
237+
// in a new branch without using the change request workflow
238+
// in this case currentChangeRequest is false
239+
if(!currentChangeRequest) return
236240
const CRObject = await getChangeRequestByID(currentChangeRequest)
237241
if(CRObject.status !== "Open"){
238242
throw Error(`The current Change Request has been ${CRObject.status}.

0 commit comments

Comments
 (0)