Skip to content

Commit 75bd620

Browse files
committed
fix message
1 parent e0388b6 commit 75bd620

16 files changed

+78
-58
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
Legend,
88
ResponsiveContainer,
99
AreaChart, Area } from 'recharts'
10-
import {TimeTravelControl} from "../hooks/TimeTravelControl"
10+
import {useTimeTravel} from "../hooks/useTimeTravel"
1111
import {printtsDate, printtsTime} from "./utils"
1212
import {Loading} from "./Loading"
1313
import {PROGRESS_BAR_COMPONENT} from "./constants"
@@ -16,7 +16,7 @@ import {Col} from "react-bootstrap"
1616
export const DataProductActivityStatus = ()=>{
1717
const {
1818
dataProvider
19-
} = TimeTravelControl(50)
19+
} = useTimeTravel(50)
2020

2121
return <React.Fragment>
2222
<Col md={12}>

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export const DatePickerComponent = ({currentDay, setStartTime}) => {
1111
// convert to ISO timeStamp
1212
if(setStartTime)setStartTime(data)
1313
}
14+
15+
useEffect(()=>{
16+
setCurrentDate(currentDay)
17+
},[currentDay])
1418

1519
return <DatePicker onChange={handleOnChange}
1620
value={selected}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ export const MessageBox = ({ setMessage, message }) => {
5151
// displays textarea to write comments & button to save comments
5252
export const MessageComponent = ({setKey}) => {
5353
const { currentCRObject, setCurrentCRObject }= WOQLClientObj()
54-
const { updateChangeRequestStatus, loading } = ChangeRequest()
54+
const { addNewMessage, loading } = ChangeRequest()
5555
const [comment, setComment]=useState("")
5656
const { id } = useParams()
5757

5858
/** handle Message */
5959
async function handleMessage(comment) {
6060
let id=extractID(currentCRObject["@id"])
6161
// this call return the changeRequestObj Updated
62-
let res=await updateChangeRequestStatus(comment, currentCRObject.status, id)
62+
let res=await addNewMessage(comment,id)
6363
// we'll see if add need rebase check every time
6464
res.needRebase = currentCRObject.needRebase
6565
setCurrentCRObject(res)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export const QueryPane = ({queryObj}) => {
112112
<Col md={size}>
113113
<div className="editor-pallet">
114114
<WOQLEditor
115+
language={queryObj.editorObj.language}
115116
editorObject={queryObj.editorObj}
116117
editable={true}
117118
theme="dark"/>

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

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import React, {useState, useEffect, useRef} from "react"
22
import {BiTimer, BiTime, BiMessageAltDetail} from "react-icons/bi"
3-
import {BsFillCircleFill, BsCalendar} from"react-icons/bs"
3+
import {BsFillCircleFill} from"react-icons/bs"
44
import { VerticalTimeline, VerticalTimelineElement } from 'react-vertical-timeline-component'
55
import 'react-vertical-timeline-component/style.min.css'
6-
import {TimeTravelControl} from "../hooks/TimeTravelControl"
6+
import {useTimeTravel} from "../hooks/useTimeTravel"
77
import {Button, Card, Row, Col} from "react-bootstrap"
8-
import {TERMINUS_SUCCESS} from "./constants"
9-
import {Alerts} from "./Alerts"
108
import {AiOutlineUser} from "react-icons/ai"
119
import {printtsDate, printtsTime} from "./utils"
1210
import {WOQLClientObj} from '../init-woql-client'
@@ -16,31 +14,30 @@ import {PROGRESS_BAR_COMPONENT} from "./constants"
1614
import {DatePickerComponent} from "./DatePicker"
1715
import {FaInfoCircle} from "react-icons/fa"
1816

19-
20-
export const TimeTravel = ({show}) => {
21-
17+
export const TimeTravel = ({refreshTime}) => {
2218
let cardColor = "#303030", transparantColor = "transparent", activeColor = "#00bc8c"
23-
const {branch, chosenCommit,setHead, currentChangeRequest} = WOQLClientObj()
24-
25-
const {currentItem,
19+
const {setHead,chosenCommit,branch} = WOQLClientObj()
20+
const {
2621
dataProvider,
27-
//setSelectedValue,
28-
setCurrentDay,
2922
loadNextPage,
3023
olderCommit,
31-
loadPreviousPage,
32-
setReloadQuery,
3324
currentDay,
3425
setStartTime,
3526
loading,
3627
setLoading,
37-
} = TimeTravelControl()
28+
} = useTimeTravel()
3829

3930
useEffect(() => { // when new commit logs are loaded on click of previous or next
4031
if(dataProvider.length > 0) {
4132
setLoading(false)
4233
}
4334
}, [dataProvider])
35+
36+
useEffect(()=>{
37+
if(refreshTime){
38+
setStartTime(refreshTime,true)
39+
}
40+
},[refreshTime])
4441

4542
//const [reportAlert, setReportAlert] = useState(false)
4643

@@ -53,20 +50,6 @@ export const TimeTravel = ({show}) => {
5350
}
5451
}
5552

56-
/* useEffect(() => {
57-
if(chosenCommit && setHead){
58-
setHead(branch, chosenCommit)
59-
let message = `The state of data product has been set to date ${chosenCommit.label}`
60-
setReportAlert(<Alerts message={message} type={TERMINUS_SUCCESS} onCancel={setReportAlert}/>)
61-
}
62-
}, [chosenCommit])*/
63-
64-
// useEffect(() => {
65-
// if(show){
66-
// setReloadQuery(Date.now())
67-
// }
68-
// }, [show])
69-
7053

7154
const TimelineElements = () => {
7255
if(!dataProvider) return <div/>

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
import React from "react"
1+
import React, {useState} from "react"
22
import {Card, Button} from "react-bootstrap"
33
import {WOQLClientObj} from '../init-woql-client'
44
import {AiOutlineClose, AiOutlineRollback} from "react-icons/ai"
55
import {TimeTravel} from "./TimeTravel"
66

77
export const TimeTravelContainer = ({show, setShowTimeTravel}) => {
88
const {branch,setHead}=WOQLClientObj()
9-
9+
const [needRefresh,setNeedrefresh] = useState(false)
1010
const goToLatestCommit = () => {
11-
setHead("main", { commit: false, time: false });
11+
setHead(branch, { commit: false, time: false });
12+
setNeedrefresh(Date.now())
1213
};
1314

1415
let sliderClass = 'time-travel-slider'
@@ -21,7 +22,7 @@ export const TimeTravelContainer = ({show, setShowTimeTravel}) => {
2122
<Card.Header className="d-flex">
2223
<h6 className="mr-4 mt-2 w-100 float-left">Time travel on branch - <strong className="text-success">{branch}</strong></h6>
2324
<div className="float-right w-100 text-right">
24-
<Button variant="light" className="mr-3" title={"Go to the latest commit of main branch"} onClick={(e) => goToLatestCommit()}>
25+
<Button variant="light" className="mr-3" title={`Go to the latest commit of ${branch} branch`} onClick={(e) => goToLatestCommit()}>
2526
<AiOutlineRollback />
2627
</Button>
2728
<Button variant="light" className="mr-3" title={"Close Time Travel View"} onClick={(e) => setShowTimeTravel(false)}>
@@ -30,7 +31,7 @@ export const TimeTravelContainer = ({show, setShowTimeTravel}) => {
3031
</div>
3132
</Card.Header>
3233
<Card.Body>
33-
{show && <TimeTravel show={show}/>}
34+
{show && <TimeTravel refreshTime={needRefresh}/>}
3435
</Card.Body>
3536
</Card>
3637
</div>

packages/tdb-dashboard/src/components/layout/TDBToggleButtonGroup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const TDBToggleButtonGroup = (props) => {
1414

1515
return <ToggleButtonGroup type="radio" name="options" value={props.selected} >
1616
{config.buttons.map((item) =>
17-
<ToggleButton key={`item__${item.id}`} value={item.id} key={item.id}
17+
<ToggleButton key={`item__${item.id}`} value={item.id}
1818
id={item.id} className="btn-light btn-sm mt-1" onClick={(e)=>handleOnClick(item.id)} >
1919
{item.icon && <i className={item.icon}/>}
2020
{item.label}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,11 @@ export const status = {
303303

304304
/** just get change request ID, remove "Changerequest/" from ID */
305305
export function extractID(id) {
306-
let str= id.split("/")
307-
return str[1]
306+
if(typeof id === "string"){
307+
let str= id.split("/")
308+
return str[1]
309+
}
310+
return ""
308311
}
309312

310313
/** sorts alphabetically */

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,22 @@ export function ChangeRequest(){
3737
}
3838
}
3939

40+
const addNewMessage = async(message, crID = false) =>{
41+
try{
42+
setLoading(true)
43+
const payload = {message}
44+
const currentCR = crID
45+
const changeRequestDoc = await woqlClient.sendCustomRequest("POST", `${getUrl()}/${currentCR}/messages`,payload)
46+
return changeRequestDoc
47+
}catch(err){
48+
const errMessage = formatErrorMessage(err)
49+
setError(errMessage)
50+
return false
51+
}finally{
52+
setLoading(false)
53+
}
54+
}
55+
4056
const updateChangeRequestStatus = async(message, status="Submitted", crID = false) =>{
4157
try{
4258
setLoading(true)
@@ -113,6 +129,7 @@ export function ChangeRequest(){
113129
return {
114130
loading,
115131
setError,
132+
addNewMessage,
116133
errorMessage,
117134
changeRequestList,
118135
createChangeRequest,

packages/tdb-dashboard/src/hooks/TimeTravelControl.js renamed to packages/tdb-dashboard/src/hooks/useTimeTravel.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,22 @@ const QUERY_TYPE_LOAD = 'QUERY_TYPE_LOAD';
1010
const QUERY_TYPE_PREVIOUS = 'QUERY_TYPE_PREVIOUS';
1111
const QUERY_TYPE_NEXT = 'QUERY_TYPE_NEXT';
1212

13-
export const TimeTravelControl = (limit=5) => {
13+
export const useTimeTravel = (limit=5) => {
1414
const {woqlClient, branch, chosenCommit,setHead} = WOQLClientObj()
1515
if(!woqlClient) return ""
1616
const dataProduct = woqlClient.db()
1717

1818
const [report, setError] = useState(false)
1919
// type Date
20-
const currentDay = new Date()
21-
if(chosenCommit && chosenCommit.time)currentDay.setTime(chosenCommit.time*1000)
20+
const startcurrentDay = new Date()
21+
// If there is a commit selected I add 6 second to the time
22+
// because the query is less then or he not get the selected one
23+
if(chosenCommit && chosenCommit.time)startcurrentDay.setTime((chosenCommit.time*1000)+6000)
2224
//Unix timestamp (in seconds)
23-
const currentStartTime = Math.floor(+currentDay/1000) //currentDay.unix();
25+
const currentStartTime = Math.floor(+startcurrentDay/1000)
2426
const [olderCommit,setOlderCommit] = useState(true);
2527
const [currentPage, setCurrentPage] = useState(0);
28+
const [currentDay, setUpdateCurrentDay] = useState(startcurrentDay);
2629
const [startTime, setUpdateStartTime] = useState(currentStartTime);
2730
const [gotoPosition,setGotoPosition] = useState(null);
2831
const [reloadQuery,setReloadQuery] = useState(0);
@@ -87,6 +90,8 @@ export const TimeTravelControl = (limit=5) => {
8790
else queryObj = WOQL.lib().commits(branch, limit,currentPage);
8891
}
8992
const tmpWoqlClient = woqlClient.copy()
93+
// I should reset the commit or I see only a subset of commits
94+
tmpWoqlClient.ref(null)
9095

9196
tmpWoqlClient.query(queryObj).then((result) => {
9297
if (result.bindings) {
@@ -214,16 +219,21 @@ export const TimeTravelControl = (limit=5) => {
214219
// setReloadQuery(Date.now());
215220
}
216221

217-
const setStartTime=(date)=>{
222+
const setStartTime=(date,resetday)=>{
218223
setCurrentPage(0);
219224
setGotoPosition(null)
220225
//setCurrentCommit(null)
221-
const unixTime = (Math.floor(+date/1000)+86400) //time.add(1,'day').unix();
226+
const unixTime = (Math.floor(+date/1000)+86400)
222227
if(unixTime !==startTime) setDataProviderValues({dataProvider:[],selectedValue:0});
223228
if(chosenCommit && chosenCommit.time){
224229
//reset the commit
225230
setHead(branch, {})
226231
}
232+
if(resetday){
233+
const tmpCurrentDay = new Date()
234+
tmpCurrentDay.setTime(date)
235+
setUpdateCurrentDay(tmpCurrentDay+6000)
236+
}
227237
setUpdateStartTime(unixTime)
228238
}
229239

0 commit comments

Comments
 (0)