|
| 1 | +import React, {useState, useEffect} from 'react' |
| 2 | +import {Container, Row, Col, Card} from "react-bootstrap" |
| 3 | +import {useParams} from 'react-router-dom' |
| 4 | +import {GetDiffList} from "../hooks/DocumentHook" |
| 5 | +import {WOQLClientObj} from "../init-woql-client" |
| 6 | +import {DiffView} from "../components/DiffView" |
| 7 | +import Badge from 'react-bootstrap/Badge' |
| 8 | +import {BiGitBranch} from "react-icons/bi" |
| 9 | +import Tab from 'react-bootstrap/Tab' |
| 10 | +import Tabs from 'react-bootstrap/Tabs' |
| 11 | +import Stack from 'react-bootstrap/Stack' |
| 12 | +import {ChangeRequest} from "../hooks/ChangeRequest" |
| 13 | +import {Loading} from "../components/Loading" |
| 14 | +import Alert from 'react-bootstrap/Alert' |
| 15 | +import { |
| 16 | + DIFFS, |
| 17 | + MERGED, |
| 18 | + MESSAGES, |
| 19 | + TRACKING_BRANCH |
| 20 | +} from "../components/constants" |
| 21 | +import {Messages} from "../components/Messages" |
| 22 | +import {ReviewComponent} from "../components/ReviewComponent" |
| 23 | + |
| 24 | +const DocumentModifiedCount = ({documentModifiedCount}) => { |
| 25 | + if(documentModifiedCount > 1) return <h6 className="fw-bold mt-2 text-warning font-italic"> |
| 26 | + {`${documentModifiedCount} documents`} |
| 27 | + </h6> |
| 28 | + |
| 29 | + if(documentModifiedCount === 1) return <h6 className="fw-bold mt-2 text-warning font-italic"> |
| 30 | + {`${documentModifiedCount} document`} |
| 31 | + </h6> |
| 32 | +} |
| 33 | + |
| 34 | +const BranchCRMessage = ({css, branch}) => { |
| 35 | + return <React.Fragment> |
| 36 | + <Badge bg={css} className="fw-bold mr-2 text-dark"> |
| 37 | + <BiGitBranch className=" mr-1"/>{branch} |
| 38 | + </Badge> |
| 39 | + </React.Fragment> |
| 40 | +} |
| 41 | + |
| 42 | +const DisplayHeader = ({author, documentModifiedCount, tracking_branch}) => { |
| 43 | + return <> |
| 44 | + <h6 className="mt-2">{`${author} wants to merge `}</h6> |
| 45 | + <DocumentModifiedCount documentModifiedCount={documentModifiedCount}/> |
| 46 | + <h6 className="mt-2">{` into `}</h6> |
| 47 | + <BranchCRMessage branch={"main"} css={"success"}/> |
| 48 | + <h6 className="mt-2">{`from `}</h6> |
| 49 | + <BranchCRMessage branch={tracking_branch} css={"primary"}/> |
| 50 | + </> |
| 51 | +} |
| 52 | + |
| 53 | + |
| 54 | +export const ChangeDiffComponent = () => { |
| 55 | + |
| 56 | + const { |
| 57 | + woqlClient:client, |
| 58 | + currentCRObject |
| 59 | + } = WOQLClientObj() |
| 60 | + |
| 61 | + /*const { |
| 62 | + getChangeRequestByID, |
| 63 | + } = ChangeRequest()*/ |
| 64 | + |
| 65 | + const {id} = useParams() |
| 66 | + |
| 67 | + const [key, setKey] = useState(DIFFS) |
| 68 | + const [action, setAction]=useState(false) |
| 69 | + const [loading, setLoading]=useState(true) |
| 70 | + const [errorMsg, setErrorMsg]=useState(false) |
| 71 | + |
| 72 | + /* useEffect(() => { |
| 73 | + async function getCRID() { |
| 74 | + await getChangeRequestByID(id,true) |
| 75 | + } |
| 76 | + if(id, client) getCRID() |
| 77 | + }, [id, client])*/ |
| 78 | + |
| 79 | + //let changeRequestID=localStorage.getItem("TERMINUSCMS_CHANGE_REQUEST_ID") |
| 80 | + const result = GetDiffList(client, id, setLoading, setErrorMsg) |
| 81 | + //const result = GetDiffList(client, currentCRObject["@id"]) |
| 82 | + |
| 83 | + useEffect(() => { |
| 84 | + if(key === DIFFS) setAction(false) |
| 85 | + }, [key]) |
| 86 | + |
| 87 | + if(!client) return <div/> |
| 88 | + |
| 89 | + let documentModifiedCount = result ? result.length : 0 |
| 90 | + |
| 91 | + let author= currentCRObject&¤tCRObject.hasOwnProperty("creator") ? currentCRObject["creator"] : "user" |
| 92 | + |
| 93 | + return <Tabs |
| 94 | + id="change_request_tabs" |
| 95 | + activeKey={key} |
| 96 | + onSelect={(k) => setKey(k)} |
| 97 | + className="mb-3"> |
| 98 | + <Tab eventKey={DIFFS} title={DIFFS}> |
| 99 | + {loading && <Loading message={`Loading Diffs ...`}/>} |
| 100 | + {errorMsg && <Alert variant={"danger"} className="mr-3"> |
| 101 | + {errorMsg} |
| 102 | + </Alert>} |
| 103 | + {!documentModifiedCount && <h6 className="text-muted fw-bold mt-3 mb-3"> |
| 104 | + {`No documents `} |
| 105 | + </h6>} |
| 106 | + <Card bg="transparent" className="border-secondary mt-5 mb-5"> |
| 107 | + <Card.Header> |
| 108 | + <Stack direction="horizontal" gap={2} className="mt-1"> |
| 109 | + <DisplayHeader author={author} |
| 110 | + tracking_branch={currentCRObject.tracking_branch} |
| 111 | + documentModifiedCount={documentModifiedCount}/> |
| 112 | + </Stack> |
| 113 | + </Card.Header> |
| 114 | + <Card.Body> |
| 115 | + |
| 116 | + {currentCRObject.status !== MERGED && <ReviewComponent setKey={setKey} action={action} setAction={setAction}/> } |
| 117 | + <DiffView diffs={result} CRObject={currentCRObject}/> |
| 118 | + </Card.Body> |
| 119 | + </Card> |
| 120 | + </Tab> |
| 121 | + <Tab eventKey={MESSAGES} title={MESSAGES}> |
| 122 | + <Messages/> |
| 123 | + </Tab> |
| 124 | + </Tabs> |
| 125 | +} |
| 126 | + |
| 127 | + /*<small className="fw-bold mr-2 h6">You are in change request mode</small> |
| 128 | + <span className="float-right fw-bold mr-2 text-dark badge bg-primary mb-1"> |
| 129 | + {currentCRObject[TRACKING_BRANCH]} |
| 130 | + </span>*/ |
| 131 | + |
| 132 | +/** |
| 133 | + * |
| 134 | + <Row className="w-100 mt-5"> |
| 135 | + <Col md={6}> |
| 136 | + {result && <DocumentModifiedCount documentModifiedCount={documentModifiedCount}/>} |
| 137 | + </Col> |
| 138 | + <Col md={6}> |
| 139 | + <BranchCRMessage trackingBranch={currentCRObject.tracking_branch} originBranch={"main"}/> |
| 140 | + </Col> |
| 141 | + </Row> |
| 142 | + */ |
0 commit comments