Skip to content

Commit ab4e796

Browse files
Add change request optional (#275)
* review make change_request workflow optional --------- Co-authored-by: Francesca-Bit <[email protected]>
1 parent 3243e00 commit ab4e796

File tree

13 files changed

+120
-189
lines changed

13 files changed

+120
-189
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export const AboutDataProduct = ({dataProductDetails, setShowDeleteModal, setSho
2424
const {documentClasses,getDocumentClasses} = useTDBDocuments(woqlClient)
2525
const [radioValue, setRadioValue] = useState(useChangeRequest===false ? "Inactive" : "Active");
2626

27+
28+
const isAdmin = accessControlDashboard ? accessControlDashboard.isAdmin() : false
2729
const {cloneDatabase, loading:loadingClone, error:errorClone , setError:setCloneError} = ManageDatabase()
2830

2931
const cloneInTeam = useRef(null);
@@ -38,6 +40,10 @@ export const AboutDataProduct = ({dataProductDetails, setShowDeleteModal, setSho
3840
return `${localSettings.server}${organization}/${organization}/${dataProduct}`
3941
}
4042

43+
useEffect(() =>{
44+
setRadioValue(useChangeRequest===false ? "Inactive" : "Active")
45+
},[useChangeRequest])
46+
4147
useEffect(() => {
4248
if(!healthColor) setColor("text-muted")
4349
if(healthColor == DATA_PRODUCT_HEALTHY) setColor("text-success")
@@ -104,7 +110,7 @@ export const AboutDataProduct = ({dataProductDetails, setShowDeleteModal, setSho
104110

105111
return <React.Fragment>
106112
<HealthModal dataProduct={dataProduct} showHealth={showHealth} setShowHealth={setShowHealth}/>
107-
{clientUser.serverType !== "TerminusDB" &&
113+
{clientUser.serverType !== "TerminusDB" && isAdmin &&
108114
<Card className="bg-transparent p-1 mb-5 tdb__align__container" border="muted">
109115
<Card.Body>
110116
<ButtonGroup>

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import {useParams} from 'react-router-dom'
88

99
export const IconBar = ({setShowFeedbackForm}) => {
1010

11-
const {currentChangeRequest,useChangeRequest} = WOQLClientObj()
11+
const {currentChangeRequest,useChangeRequest, accessControlDashboard} = WOQLClientObj()
12+
13+
const instanceRead = accessControlDashboard && accessControlDashboard.instanceRead() ? accessControlDashboard.instanceRead() : false
1214

1315
const { organization, dataProduct } = useParams();
1416

@@ -66,7 +68,7 @@ export const IconBar = ({setShowFeedbackForm}) => {
6668
{IconBarConfig.dataProductModal.icon}
6769
</Nav.Link>
6870
</Nav.Item>
69-
<Nav.Item>
71+
{instanceRead && <Nav.Item>
7072
<Nav.Link
7173
as={RouterNavLink}
7274
title={IconBarConfig.documentExplorer.title}
@@ -77,7 +79,7 @@ export const IconBar = ({setShowFeedbackForm}) => {
7779
id={IconBarConfig.documentExplorer.key}>
7880
{IconBarConfig.documentExplorer.icon}
7981
</Nav.Link>
80-
</Nav.Item>
82+
</Nav.Item>}
8183
<Nav.Item>
8284
<Nav.Link as={RouterNavLink}
8385
title={IconBarConfig.dataProductExplorer.title}
@@ -90,18 +92,18 @@ export const IconBar = ({setShowFeedbackForm}) => {
9092
</Nav.Link>
9193
</Nav.Item>
9294

93-
<Nav.Item>
95+
{instanceRead && <Nav.Item>
9496
<Nav.Link as={RouterNavLink}
9597
title={IconBarConfig.graphiql.title}
96-
className="nav-icon nav-product-expolorer"
98+
className="nav-icon nav-product-expolorer"
9799
{...disabled}
98100
to={getUrl(IconBarConfig.graphiql.path)}
99101

100102
id={IconBarConfig.graphiql.key}>
101103
{IconBarConfig.graphiql.icon}
102104
</Nav.Link>
103-
</Nav.Item>
104-
{useChangeRequest && <Nav.Item>
105+
</Nav.Item>}
106+
{instanceRead && useChangeRequest && <Nav.Item>
105107
<Nav.Link as={RouterNavLink}
106108
title={IconBarConfig.changes.title}
107109
className="nav-icon nav-product-explorer"
@@ -112,7 +114,8 @@ export const IconBar = ({setShowFeedbackForm}) => {
112114
{IconBarConfig.changes.icon}
113115
</Nav.Link>
114116
</Nav.Item>}
115-
{useChangeRequest && !currentChangeRequest &&
117+
{instanceRead && useChangeRequest && !currentChangeRequest &&
118+
<>
116119
<Nav.Item>
117120
<Nav.Link as={RouterNavLink}
118121
title={IconBarConfig.openAI.title}
@@ -124,8 +127,6 @@ export const IconBar = ({setShowFeedbackForm}) => {
124127
{IconBarConfig.openAI.icon}
125128
</Nav.Link>
126129
</Nav.Item>
127-
}
128-
{useChangeRequest && !currentChangeRequest &&
129130
<Nav.Item>
130131
<Nav.Link as={RouterNavLink}
131132
title={IconBarConfig.search.title}
@@ -137,9 +138,7 @@ export const IconBar = ({setShowFeedbackForm}) => {
137138
{IconBarConfig.search.icon}
138139
</Nav.Link>
139140
</Nav.Item>
140-
}
141-
{useChangeRequest && !currentChangeRequest &&
142-
<Nav.Item>
141+
<Nav.Item>
143142
<Nav.Link as={RouterNavLink}
144143
title={IconBarConfig.actions.title}
145144
className="nav-icon nav-product-expolorer"
@@ -150,6 +149,7 @@ export const IconBar = ({setShowFeedbackForm}) => {
150149
{IconBarConfig.actions.icon}
151150
</Nav.Link>
152151
</Nav.Item>
152+
</>
153153
}
154154
<hr className="my-3" role="separator"></hr>
155155
<div className="nav-icons-bottom">

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

Lines changed: 53 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {useOpenAI} from "../hooks/useOpenAI"
44
import {Alerts} from "./Alerts"
55
import {SwitchOpenAi} from "./SwitchOpenAi"
66

7-
export const OpenAICard=({organization})=>{
7+
export const OpenAICard=({organization,isAdmin})=>{
88

99
const {loading,changeOpenAIStatus,
1010
error,saveOpenAIKey,hasOpenAIKEY,hasKey,deleteOpenAIKEY} = useOpenAI()
@@ -25,8 +25,11 @@ export const OpenAICard=({organization})=>{
2525
}
2626
}
2727

28-
function deleteKey () {
29-
deleteOpenAIKEY(organization)
28+
async function deleteKey () {
29+
const done = await deleteOpenAIKEY(organization)
30+
if(done && openAIKEY.current){
31+
openAIKEY.current.value = ""
32+
}
3033
}
3134

3235
function changeStatus (isActive){
@@ -36,7 +39,7 @@ export const OpenAICard=({organization})=>{
3639

3740
const title = hasKey === false ? "Add your secret OpenAI API key" : "Your OpenAI API key has been set"
3841
const subTitle= getLabel()
39-
42+
4043
function getLabel(){
4144
if(hasKey === false){
4245
return <label className="description text-muted fw-bold">
@@ -45,62 +48,64 @@ export const OpenAICard=({organization})=>{
4548
}
4649
const label = hasKey === "active" ? "After every change request merge we'll index your documents" : "You have set an OpenAI API key. Please activate this option inorder to index your data"
4750
return label
48-
return <Stack direction="horizontal" gap={4}>
49-
<label className="description text-muted fw-bold mr-auto ">
50-
{label}
51-
</label>
52-
</Stack>
53-
51+
}
52+
const KeyInputComponentInstance = KeyInputComponent()
53+
function KeyInputComponent (){
54+
if(!isAdmin) return <div className="form-group">
55+
<div className="input-group mt-2 mb-2">
56+
<input className="form-control"
57+
value= {"xxxxxxxx"}
58+
type="password"
59+
/>
60+
</div>
61+
</div>
62+
if(hasKey) return <div className="form-group">
63+
<div className="input-group mt-2 mb-2">
64+
<input className="form-control"
65+
value= {"xxxxxxxx"}
66+
type="password"
67+
/>
68+
<div className="input-group-append">
69+
{!loading && <Button variant="danger" id="delete_openai_key" onClick={deleteKey}>Delete OpenAIKey</Button>}
70+
{loading && <button className="btn-lg disabled"><i className="fas fa-spinner fa-spin"></i>
71+
<span style={{marginLeft:"10px"}}>Loading</span></button>}
72+
</div>
73+
</div>
74+
</div>
75+
if(hasKey === false) return <div className="form-group">
76+
<div className="input-group mt-2 mb-2">
77+
<input className="form-control"
78+
id="openAIKEY"
79+
ref={openAIKEY}
80+
type="password"
81+
placeholder="Add your openAI key"
82+
/>
83+
<div className="input-group-append">
84+
{!loading && <Button variant="info" id="generate_new_token" onClick={saveOpenAIKeyHandler}> Save OpenAIKey</Button>}
85+
{loading && <button className="btn-lg disabled"><i className="fas fa-spinner fa-spin"></i>
86+
<span style={{marginLeft:"10px"}}>Loading</span></button>}
87+
</div>
88+
89+
</div>
90+
</div>
5491
}
5592

5693
return( <React.Fragment>
5794
<Card className="p-5 mb-5">
58-
<h4 className="mt-4 text-success"><strong>{title}</strong></h4>
95+
<h4 className="mt-4 text-success"><strong>{title}</strong></h4>
5996
<Stack direction="horizontal" gap={2}>
6097

6198
<div>
6299
{hasKey !== false && <SwitchOpenAi status={hasKey}
63100
changeOpenAIStatus={changeStatus}
64-
title={subTitle}/>}
101+
title={subTitle} isAdmin={isAdmin}/>}
65102
</div>
66103
</Stack>
67104
<Row>
68-
<Col>
69-
{hasKey &&
70-
<div className="form-group">
71-
<div className="input-group mt-2 mb-2">
72-
<input className="form-control"
73-
value= {"xxxxxxxx"}
74-
type="password"
75-
/>
76-
<div className="input-group-append">
77-
{!loading && <Button variant="danger" id="delete_openai_key" onClick={deleteKey}>Delete OpenAIKey</Button>}
78-
{loading && <button className="btn-lg disabled"><i className="fas fa-spinner fa-spin"></i>
79-
<span style={{marginLeft:"10px"}}>Loading</span></button>}
80-
</div>
81-
</div>
82-
</div>
83-
}
84-
{hasKey === false &&
85-
<div className="form-group">
86-
<div className="input-group mt-2 mb-2">
87-
<input className="form-control"
88-
id="openAIKEY"
89-
ref={openAIKEY}
90-
type="password"
91-
placeholder="Add your openAI key"
92-
/>
93-
<div className="input-group-append">
94-
{!loading && <Button variant="info" id="generate_new_token" onClick={saveOpenAIKeyHandler}> Save OpenAIKey</Button>}
95-
{loading && <button className="btn-lg disabled"><i className="fas fa-spinner fa-spin"></i>
96-
<span style={{marginLeft:"10px"}}>Loading</span></button>}
97-
</div>
98-
99-
</div>
100-
</div>}
101-
</Col>
105+
<Col>{KeyInputComponentInstance}</Col>
102106
</Row>
103-
</Card>
107+
</Card>
104108
</React.Fragment>
105109
)
106-
}
110+
}
111+

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import React, { useState } from "react"
33
import Form from "react-bootstrap/Form";
44

5-
export function SwitchOpenAi({ status, changeOpenAIStatus, title }) {
5+
export function SwitchOpenAi({ status, changeOpenAIStatus, title, isAdmin }) {
66

77
const [currentStatus,setStatus] = useState(status === "active" ? true : false)
88

@@ -14,14 +14,18 @@ export function SwitchOpenAi({ status, changeOpenAIStatus, title }) {
1414

1515
return <Form>
1616
<div key={`default-checkbox`} className="mb-3">
17-
<Form.Check // prettier-ignore
17+
{isAdmin && <Form.Check // prettier-ignore
1818
type={`checkbox`}
1919
id={`default-checkbox`}
2020
className="openai_checkbox"
2121
label={title}
2222
checked={currentStatus}
2323
onChange={onChange}
24-
/>
24+
/>}
25+
{!isAdmin && <div class="mb-3"><div class="openai_checkbox form-check">
26+
<label title="" for="default-checkbox" class="form-check-label">{title}</label>
27+
</div>
28+
</div>}
2529
</div>
2630
</Form>
2731

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

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@ export function useOpenAI(){
7171
}
7272

7373
///changes/:orgid/:dbid/indexedcommit
74-
const getSearchableCommit = async (limit=1, status=null)=>{
74+
const getSearchableCommit = async (limit=1, status=null, branch=null)=>{
7575
try{
76-
setSearchableCommit(false)
7776
setLoading(true)
78-
const url = `${getUrl('indexes')}?limit=${limit}&status=${status}`
77+
setSearchableCommit(false)
78+
const statusQuery = status ? `&status=${status}` : ''
79+
const branchQuery = branch ? `&branch=${branch}` : ''
80+
const url = `${getUrl('indexes')}?limit=${limit}${statusQuery}${branchQuery}`
7981
const result = await woqlClient.sendCustomRequest("GET", url)
8082
if(result && result.bindings){
8183
setSearchableCommit(result.bindings)
@@ -88,13 +90,13 @@ export function useOpenAI(){
8890
}
8991
}
9092

91-
const getResearchResult = async (commit, freeText, domain, branch = "main" ) =>{
93+
const getResearchResult = async (commit, freeText) =>{
9294
if(woqlClient){
9395
try{
94-
setSearchResult(false)
9596
setLoading(true)
97+
setSearchResult(false)
9698
localStorage.setItem(`${location.pathname}___SEARCH__TEXT`,freeText)
97-
const url = `${getUrl('indexes')}/search?domain=${domain}&commit=${commit}`
99+
const url = `${getUrl('indexes')}/search?commit=${commit}`
98100
const result = await woqlClient.sendCustomRequest("POST", url , {search:freeText})
99101
localStorage.setItem(`${location.pathname}___SEARCH__RESULT`,JSON.stringify(result))
100102
setSearchResult(result)
@@ -184,6 +186,7 @@ export function useOpenAI(){
184186
const url = `${client.server()}api/private/organizations/${UTILS.encodeURISegment(orgName)}/openaikey`
185187
const keyStatusObj = await client.sendCustomRequest("DELETE", url)
186188
setHasKey(keyStatusObj.key)
189+
return keyStatusObj
187190
}catch(err){
188191
setError()
189192
}finally{
@@ -297,11 +300,14 @@ export function useOpenAI(){
297300
const getPrewiew = async (type,queryStr,handlebarsTemplate)=>{
298301
try{
299302
setError(false)
300-
let queryWithLimit = queryStr//.replace("(","($offset: Int, $limit: Int , ")
301-
// queryWithLimit = queryWithLimit.replace(`${type}(`,`${type}(offset: $offset, limit: $limit, `)
303+
let queryWithLimit = queryStr
304+
if(queryStr.indexOf("$limit") === -1){
305+
queryWithLimit = queryStr.replace("(","($offset: Int, $limit: Int, ")
306+
queryWithLimit = queryWithLimit.replace(`${type}(`,`${type}(offset: $offset, limit: $limit, `)
307+
}
302308
setLoading(true)
303309
const query = gql(`${queryWithLimit}`)
304-
const result = await apolloClient.query({query:query,variables:{limit:5,offset:0}})
310+
const result = await apolloClient.query({query:query,variables:{limit:10,offset:0}})
305311

306312
if(result.errors){
307313
setError(result.errors)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const DocumentEdit = () => {
3737
}
3838
// implement the chage method
3939
useEffect(() => {
40-
if(!currentChangeRequest){
40+
if(useChangeRequest && !currentChangeRequest){
4141
setShowModal(true)
4242
}
4343
getDocumentFrames()
@@ -53,7 +53,7 @@ export const DocumentEdit = () => {
5353
return <React.Fragment>
5454
{error && <ErrorMessageReport error={error} setError={setError}/>}
5555
{showModal && <CreateChangeRequestModal showModal={showModal} type={type} setShowModal={setShowModal} updateViewMode={setChangeRequestBranch}/>}
56-
{!useChangeRequest || currentChangeRequest &&
56+
{(!useChangeRequest || currentChangeRequest) &&
5757
<EditDocumentComponent
5858
SearchComponent={DocumentSearchComponent}
5959
documentID={documentID}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export const DocumentView = () => {
9797
deleteDocument={callDeleteDocument}
9898
documentID={documentID}
9999
showDeleteModal={showDeleteModal}
100-
handleClose={()=>showDeleteModal(false)}
100+
handleClose={()=>setShowDeleteModal(false)}
101101
/> }
102102
<ViewDocumentComponent
103103
type={type}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {ErrorMessageReport} from "../components/ErrorMessageReport"
1111
// I pass this so I'm sure it exists before loading the component
1212
export const DocumentsGraphqlList = ({documentTablesConfig}) => {
1313
const {type} = useParams()
14-
const {apolloClient,branch,setChangeRequestBranch,woqlClient,ref} = WOQLClientObj()
14+
const {apolloClient,branch,setChangeRequestBranch,woqlClient,ref,currentChangeRequest,useChangeRequest} = WOQLClientObj()
1515
const {deleteDocument,loading,error,setError} = useTDBDocuments(woqlClient)
1616
const [showCRModal, setShowCRModal] = useState(false)
1717
const [showDeleteModal, setShowDeleteModal]=useState(false)
@@ -29,7 +29,7 @@ export const DocumentsGraphqlList = ({documentTablesConfig}) => {
2929
setTobeDeleted(fullId)
3030
// I can not change main directly
3131
// I can change other branches creates with create branch interface
32-
if(woqlClient.checkout() === "main"){
32+
if(useChangeRequest && !currentChangeRequest){
3333
setShowCRModal(true)
3434
}else setShowDeleteModal(true)
3535
}

0 commit comments

Comments
 (0)