@@ -6,122 +6,62 @@ import {WOQLClientObj} from "../init-woql-client"
66import Stack from "react-bootstrap/Stack"
77import { status } from "./utils"
88import { ChangeRequest } from "../hooks/ChangeRequest"
9- import Spinner from 'react-bootstrap/Spinner' ;
10-
11- const ActionButton = ( { variant, title, content, onClick, loading, icon} ) => {
12- return < Button
13- className = "text-dark btn btn-sm fw-bold d-flex mt-3 float-end"
14- variant = { variant }
15- title = { title }
16- onClick = { onClick } >
17- { loading && < Spinner
18- as = "span"
19- animation = "border"
20- size = "sm"
21- role = "status"
22- className = "mr-1 mt-1"
23- aria-hidden = "true"
24- /> }
25- < div className = "d-flex" >
26- { icon }
27- < label > { content } </ label >
28- </ div >
29- </ Button >
30- }
31-
32- /**
33- * @returns buttons to reject commit or approve based on user action
34- */
35- const Actions = ( { checked, message, setKey, setMessage} ) => {
36-
37- const {
38- woqlClient,
39- currentCRObject,
40- setCurrentCRObject,
41- exitChangeRequestBranch
42- } = WOQLClientObj ( )
43-
44- const {
45- updateChangeRequestStatus,
46- getChangeRequestList,
47- loading
48- } = ChangeRequest ( woqlClient )
49-
50- const { organization, dataProduct, id} = useParams ( )
51- const navigate = useNavigate ( ) // to navigate
52-
53- /** handle Message */
54- async function handleMessage ( ) {
55- let id = extractID ( currentCRObject [ "@id" ] )
56- // this call return the changeRequestObj Updated
57- let res = await updateChangeRequestStatus ( message , currentCRObject . status , id )
58- // we'll see if add need rebase check every time
59- res . needRebase = currentCRObject . needRebase
60- setCurrentCRObject ( res )
61- if ( setKey ) setKey ( CONST . MESSAGES )
62- if ( setMessage ) setMessage ( "" )
63- }
64-
65- /** handle Merge */
66- async function handleMerge ( ) {
67- let res = await updateChangeRequestStatus ( message , CONST . MERGED , id )
68- if ( res ) {
69- setCurrentCRObject ( false )
70- exitChangeRequestBranch ( )
71- navigate ( `/${ organization } /${ dataProduct } ` )
72- }
73- }
74-
75- /** handle Reject */
76- async function handleReject ( ) {
77- let res = await updateChangeRequestStatus ( message , CONST . REJECTED , id )
78- if ( res ) {
79- setCurrentCRObject ( false )
80- exitChangeRequestBranch ( )
81- navigate ( `/${ organization } /${ dataProduct } ` )
82- }
83- }
84-
85- let chosen = CONST . REVIEW_OPTIONS . filter ( arr => arr . title === checked )
86-
87- if ( checked === CONST . APPROVE ) {
88- return < ActionButton variant = "success"
89- loading = { loading }
90- title = { "Approve Changes" }
91- content = { checked }
92- icon = { chosen [ 0 ] . icon }
93- onClick = { handleMerge } />
94- }
95- else if ( checked === CONST . COMMENT ) {
96- return < ActionButton variant = "light"
97- title = { "Leave a Comment or message" }
98- content = { checked }
99- loading = { loading }
100- icon = { chosen [ 0 ] . icon }
101- onClick = { handleMessage } />
102- }
103- else if ( checked === CONST . REJECT ) {
104- return < ActionButton variant = "danger"
105- title = { "Reject Changes" }
106- content = { checked }
107- loading = { loading }
108- icon = { chosen [ 0 ] . icon }
109- onClick = { handleReject } />
110- }
111- return < div />
112- }
113-
114- /**
115- * @returns help texts
116- */
117- function getHelpText ( checked ) {
118- const arr = CONST . REVIEW_OPTIONS . filter ( arr => arr . title === checked )
119- if ( ! arr ) return < div />
120- return < small className = "fw-light" > { arr [ 0 ] . helpText } </ small >
121- }
122-
123- function getChecked ( checked , id ) {
124- return checked === id ? true : false
9+ import ButtonGroup from 'react-bootstrap/ButtonGroup' ;
10+ import ToggleButton from 'react-bootstrap/ToggleButton' ;
11+ import { Loading } from "../components/Loading"
12+ import { MessageBox , MessageComponent } from "./Messages"
13+ import { AiOutlineCheck , AiOutlineClose } from "react-icons/ai"
14+
15+ const ToggleActions = ( { message } ) => {
16+ const [ action , setAction ] = useState ( false ) ;
17+ const { setCurrentCRObject, exitChangeRequestBranch } = WOQLClientObj ( )
18+ const { updateChangeRequestStatus, loading } = ChangeRequest ( )
19+ const { organization, dataProduct , id} = useParams ( )
20+ const navigate = useNavigate ( )
21+
22+
23+ useEffect ( ( ) => {
24+ async function doAction ( ) {
25+ let status = action === CONST . APPROVE ? CONST . MERGED : CONST . REJECTED
26+ let res = await updateChangeRequestStatus ( message , status , id )
27+ if ( res ) {
28+ setCurrentCRObject ( false )
29+ exitChangeRequestBranch ( )
30+ navigate ( `/${ organization } /${ dataProduct } ` )
31+ }
32+ }
33+ if ( action ) doAction ( )
34+ } , [ action ] )
35+
36+ const reviewButtons = [
37+ { name : CONST . APPROVE , value : CONST . APPROVE , className : "rounded-left" , variant : "outline-success" , icon : < AiOutlineCheck className = "mr-1 mb-1 text-success" /> } ,
38+ { name : CONST . REJECT , value : CONST . REJECT , className : "rounded-right" , variant : "outline-danger" , icon : < AiOutlineClose className = "mr-1 mb-1 text-danger" /> }
39+ ] ;
40+
41+ if ( loading ) return < Loading message = { action === CONST . APPROVE ? `Approving Change Request ...` : `Rejecting Change Request ...` } />
42+
43+ return < Stack directtion = "horizontal" className = "float-right" >
44+ < small className = "text-muted fst-italic fw-light mr-2 ms-auto" >
45+ { `Approve or Reject Change Request` }
46+ </ small >
47+ < ButtonGroup >
48+ { reviewButtons . map ( ( button ) => (
49+ < ToggleButton
50+ key = { button . name }
51+ id = { button . name }
52+ type = "radio"
53+ variant = { button . variant }
54+ name = { button . name }
55+ value = { button . value }
56+ className = { button . className }
57+ checked = { action === button . value }
58+ onChange = { ( e ) => setAction ( e . currentTarget . value ) }
59+ >
60+ { button . icon } { button . name }
61+ </ ToggleButton >
62+ ) ) }
63+ </ ButtonGroup >
64+ </ Stack >
12565}
12666
12767
0 commit comments