Loads of minor updates with cloud/onprem sync

This commit is contained in:
Frikky
2024-04-26 17:45:07 +02:00
parent e05e487db9
commit 9e34930718
9 changed files with 229 additions and 199 deletions
+112 -112
View File
@@ -1,10 +1,10 @@
import React, { useState, useEffect } from "react";
import theme from "../theme.jsx";
import { toast } from 'react-toastify';
import ReactJson from "react-json-view";
import { toast } from 'react-toastify';
import ReactJson from "react-json-view";
import {
Typography,
Typography,
Tooltip,
Divider,
TextField,
@@ -22,8 +22,8 @@ import {
} from "@mui/material";
import {
Link as LinkIcon,
AutoFixHigh as AutoFixHighIcon,
Link as LinkIcon,
AutoFixHigh as AutoFixHighIcon,
Edit as EditIcon,
FileCopy as FileCopyIcon,
SelectAll as SelectAllIcon,
@@ -46,7 +46,7 @@ import {
Visibility as VisibilityIcon,
VisibilityOff as VisibilityOffIcon,
} from "@mui/icons-material";
import { validateJson, } from "../views/Workflows.jsx";
import { validateJson, } from "../views/Workflows.jsx";
const scrollStyle1 = {
height: 100,
@@ -64,9 +64,9 @@ const scrollStyle2 = {
overflow: "scroll",
}
const CacheView = (props) => {
const { globalUrl, userdata, serverside, orgId } = props;
const { globalUrl, userdata, serverside, orgId, isSelectedDataStore } = props;
const [orgCache, setOrgCache] = React.useState("");
const [listCache, setListCache] = React.useState([]);
const [addCache, setAddCache] = React.useState("");
@@ -79,7 +79,7 @@ const CacheView = (props) => {
const [dataValue, setDataValue] = React.useState({});
const [editCache, setEditCache] = React.useState(false);
const [show, setShow] = useState({});
useEffect(() => {
listOrgCache(orgId);
}, []);
@@ -155,22 +155,22 @@ const CacheView = (props) => {
const deleteCache = (orgId, key) => {
toast("Attempting to delete Cache");
// method: "DELETE",
const method = "POST"
//const url = `${globalUrl}/api/v1/orgs/${orgId}/cache/${key}`
const url = `${globalUrl}/api/v1/orgs/${orgId}/delete_cache`
const parsed = {
"org_id": orgId,
"key": key,
}
const method = "POST"
//const url = `${globalUrl}/api/v1/orgs/${orgId}/cache/${key}`
const url = `${globalUrl}/api/v1/orgs/${orgId}/delete_cache`
const parsed = {
"org_id": orgId,
"key": key,
}
fetch(url, {
method: method,
method: method,
headers: {
Accept: "application/json",
},
body: JSON.stringify(parsed),
body: JSON.stringify(parsed),
credentials: "include",
})
.then((response) => {
@@ -255,20 +255,20 @@ const CacheView = (props) => {
});
};
const isValidJson = validateJson(value)
const autoFixJson = (inputvalue) => {
console.log("inputvalue: ", inputvalue)
try {
var parsedjson = JSON.parse(inputvalue)
// setValue() with the parsed json as string
setValue(JSON.stringify(parsedjson, null, 2))
} catch (e) {
console.log("Error parsing JSON: ", e)
//return JSON.stringify(inputvalue);
}
}
const isValidJson = validateJson(value)
const autoFixJson = (inputvalue) => {
console.log("inputvalue: ", inputvalue)
try {
var parsedjson = JSON.parse(inputvalue)
// setValue() with the parsed json as string
setValue(JSON.stringify(parsedjson, null, 2))
} catch (e) {
console.log("Error parsing JSON: ", e)
//return JSON.stringify(inputvalue);
}
}
const modalView = (
// console.log("key:", dataValue.key),
//console.log("value:",dataValue.value),
@@ -316,21 +316,21 @@ const CacheView = (props) => {
/>
</div>
<div style={{ paddingLeft: 30, paddingRight: 30 }}>
<div style={{display: "flex", }}>
<Typography style={{marginTop: 25, marginBottom: 0, flex: 20, }}>
Value - ({isValidJson.valid === true ? "Valid" : "Invalid"} JSON)
</Typography>
<Tooltip title="Auto Fix JSON" placement="right">
<IconButton
style={{flex: 1, }}
onClick={() => {
autoFixJson(value)
}}
>
<AutoFixHighIcon />
</IconButton>
</Tooltip>
</div>
<div style={{display: "flex", }}>
<Typography style={{marginTop: 25, marginBottom: 0, flex: 20, }}>
Value - ({isValidJson.valid === true ? "Valid" : "Invalid"} JSON)
</Typography>
<Tooltip title="Auto Fix JSON" placement="right">
<IconButton
style={{flex: 1, }}
onClick={() => {
autoFixJson(value)
}}
>
<AutoFixHighIcon />
</IconButton>
</Tooltip>
</div>
<TextField
color="primary"
style={{ backgroundColor: theme.palette.inputColor, marginTop: 0, }}
@@ -347,22 +347,22 @@ const CacheView = (props) => {
id="Valuefield"
margin="normal"
variant="outlined"
multiline
minRows={4}
maxRows={12}
multiline
minRows={4}
maxRows={12}
//defaultValue={editCache ? dataValue.value : ""}
value={value}
value={value}
onChange={(e) => setValue(e.target.value)}
/>
</div>
<DialogActions style={{ paddingLeft: "30px", paddingRight: '30px' }}>
<Button
style={{ borderRadius: "0px" }}
onClick={() => {
setModalOpen(false)
setValue("")
setDataValue({})
}}
onClick={() => {
setModalOpen(false)
setValue("")
setDataValue({})
}}
color="primary"
>
Cancel
@@ -372,9 +372,9 @@ const CacheView = (props) => {
style={{ borderRadius: "0px" }}
onClick={() => {
{editCache ? editOrgCache(orgId) : addOrgCache(orgId)}
setValue("")
setDataValue({})
setValue("")
setDataValue({})
}}
color="primary"
>
@@ -386,51 +386,51 @@ const CacheView = (props) => {
return (
<div style={{paddingBottom: 250, }}>
<div style={{paddingBottom: isSelectedDataStore?null:250, width: isSelectedDataStore?1030:null, padding:isSelectedDataStore?27:null, height: isSelectedDataStore?1200:null, color: isSelectedDataStore?'#ffffff':null, backgroundColor: isSelectedDataStore?'#212121':null, borderRadius: isSelectedDataStore?'16px':null, }}>
{modalView}
<div style={{ marginTop: 20, marginBottom: 20 }}>
<h2 style={{ display: "inline" }}>Shuffle Datastore</h2>
<span style={{ marginLeft: 25 }}>
Datastore is a permanent key-value database for storing data that can be used cross-workflow. You can store anything from lists of IPs to complex configurations.&nbsp;
<div style={{ marginTop: isSelectedDataStore?null:20, marginBottom: 20 }}>
<h2 style={{ display: isSelectedDataStore?null: "inline" }}>Shuffle Datastore</h2>
<span style={{ marginLeft: isSelectedDataStore?null:25, color:isSelectedDataStore?"#9E9E9E":null}}>
Datastore is a permanent key-value database for storing data that can be used cross-workflow. <br/>You can store anything from lists of IPs to complex configurations.&nbsp;
<a
target="_blank"
rel="noopener noreferrer"
href="/docs/organizations#datastore"
style={{ textDecoration: "none", color: "#f85a3e" }}
style={{ textDecoration: isSelectedDataStore?null:"none", color: isSelectedDataStore?"#FF8444":"#f85a3e" }}
>
Learn more
</a>
</span>
</div>
<Button
style={{}}
style={{backgroundColor: isSelectedDataStore?'rgba(255, 132, 68, 0.2)':null, color:isSelectedDataStore?"#FF8444":null, borderRadius:isSelectedDataStore?200:null, width:isSelectedDataStore?162:null, height:isSelectedDataStore?40:null}}
variant="contained"
color="primary"
onClick={() =>{
setEditCache(false)
setModalOpen(true)
setValue("")
}}
setValue("")
}}
>
Add Cache
</Button>
<Button
style={{ marginLeft: 5, marginRight: 15 }}
style={{ marginLeft: 5, marginRight: 15, backgroundColor: isSelectedDataStore?"#2F2F2F":null,borderRadius:isSelectedDataStore?200:null, width:isSelectedDataStore?81:null, height:isSelectedDataStore?40:null, }}
variant="contained"
color="primary"
onClick={() => listOrgCache(orgId)}
>
<CachedIcon />
</Button>
<Divider
{isSelectedDataStore? null :<Divider
style={{
marginTop: 20,
marginBottom: 20,
}}
/>
<List>
<ListItem>
/>}
<List style={{borderRadius: isSelectedDataStore?8:null, border:isSelectedDataStore?"1px solid #494949":null, marginTop:isSelectedDataStore?24:null}}>
<ListItem style={{width: isSelectedDataStore?"100%":null, borderBottom:isSelectedDataStore?"1px solid #494949":null}}>
<ListItemText
primary="Key"
style={{ minWidth: 250, maxWidth: 250, }}
@@ -454,8 +454,8 @@ const CacheView = (props) => {
if (index % 2 === 0) {
bgColor = "#1f2023";
}
const validate = validateJson(data.value);
const validate = validateJson(data.value);
return (
<ListItem key={index} style={{ backgroundColor: bgColor, maxHeight: 300, overflow: "auto", }}>
<ListItemText
@@ -467,35 +467,35 @@ const CacheView = (props) => {
primary={data.key}
/>
<ListItemText
style={{
minWidth: 400,
maxWidth: 400,
style={{
minWidth: 400,
maxWidth: 400,
}}
primary={validate.valid ?
<ReactJson
src={validate.result}
theme={theme.palette.jsonTheme}
style={theme.palette.reactJsonStyle}
collapsed={true}
enableClipboard={(copy) => {
//handleReactJsonClipboard(copy);
}}
displayDataTypes={false}
onSelect={(select) => {
//HandleJsonCopy(showResult, select, data.action.label);
//console.log("SELECTED!: ", select);
}}
name={"value"}
/>
:
data.value
primary={validate.valid ?
<ReactJson
src={validate.result}
theme={theme.palette.jsonTheme}
style={theme.palette.reactJsonStyle}
collapsed={true}
enableClipboard={(copy) => {
//handleReactJsonClipboard(copy);
}}
displayDataTypes={false}
onSelect={(select) => {
//HandleJsonCopy(showResult, select, data.action.label);
//console.log("SELECTED!: ", select);
}}
name={"value"}
/>
:
data.value
}
/>
<ListItemText
style={{
maxWidth: 200,
minWidth: 200,
marginLeft: 50,
marginLeft: 50,
}}
primary=<span style={{ display: "inline" }}>
<Tooltip
@@ -508,11 +508,11 @@ const CacheView = (props) => {
style={{ padding: "6px" }}
onClick={() => {
setEditCache(true)
setDataValue({
"key": data.key,
"value":data.value
})
setValue(data.value)
setDataValue({
"key": data.key,
"value":data.value
})
setValue(data.value)
setModalOpen(true)
}}
>
@@ -525,18 +525,18 @@ const CacheView = (props) => {
<Tooltip
title={"Public URL (types: text, raw, json)"}
style={{ marginLeft: 0, }}
aria-label={"Public URL"}
aria-label={"Public URL"}
>
<span>
<IconButton
style={{ padding: "6px" }}
disabled={data.public_authorization === undefined || data.public_authorization === null || data.public_authorization === "" ? true : false}
disabled={data.public_authorization === undefined || data.public_authorization === null || data.public_authorization === "" ? true : false}
onClick={() => {
window.open(`${globalUrl}/api/v1/orgs/${orgId}/cache/${data.key}?type=text&authorization=${data.public_authorization}`, "_blank");
}}
window.open(`${globalUrl}/api/v1/orgs/${orgId}/cache/${data.key}?type=text&authorization=${data.public_authorization}`, "_blank");
}}
>
<LinkIcon
/>
<LinkIcon
/>
</IconButton>
</span>
</Tooltip>