Skip to content

Graph Explorer Import / Export #2138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions src/components/utilities/CippCodeOffcanvas.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { useState } from 'react'
import React, { useState, useEffect } from 'react'
import { CButton, CCallout, CCol, CRow, CSpinner } from '@coreui/react'
import { CippOffcanvas } from 'src/components/utilities'
import { useLazyGenericGetRequestQuery, useLazyGenericPostRequestQuery } from 'src/store/api/app'

import { Editor } from '@monaco-editor/react'
import { useSelector } from 'react-redux'
import PropTypes from 'prop-types'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import CopyToClipboard from 'react-copy-to-clipboard'

function CippCodeOffCanvas({
row,
Expand All @@ -14,11 +16,13 @@ function CippCodeOffCanvas({
type,
title = 'Template JSON',
hideButton = false,
path = `/api/ExecEditTemplate?type=${type}`,
}) {
const [SaveTemplate, templateDetails] = useLazyGenericPostRequestQuery()
const currentTheme = useSelector((state) => state.app.currentTheme)
const [templateData, setFormData] = useState(row)
const [invalidJSON, setInvalid] = useState(false)
const [copied, setCopied] = useState(false)

function handleEditorChange(value, event) {
try {
Expand All @@ -29,6 +33,10 @@ function CippCodeOffCanvas({
}
}

useEffect(() => {
setCopied(false)
}, [setCopied, templateData])

return (
<>
<CippOffcanvas
Expand All @@ -53,18 +61,28 @@ function CippCodeOffCanvas({
<CRow className="mb-3">
<CCol>
{!hideButton && (
<CButton
disabled={invalidJSON}
onClick={() =>
SaveTemplate({
path: `/api/ExecEditTemplate?type=${type}`,
method: 'POST',
values: templateData,
})
}
>
Save changes {templateDetails.isFetching && <CSpinner size="sm" />}
</CButton>
<>
<CButton
disabled={invalidJSON}
onClick={() =>
SaveTemplate({
path: path,
method: 'POST',
values: templateData,
})
}
className="me-2"
>
<FontAwesomeIcon icon="save" className="me-2" /> Save changes
{templateDetails.isFetching && <CSpinner size="sm" />}
</CButton>
<CopyToClipboard text={JSON.stringify(row, null, 2)} onCopy={() => setCopied(true)}>
<CButton disabled={invalidJSON}>
<FontAwesomeIcon icon={copied ? 'check' : 'clipboard'} className="me-2" /> Copy
to Clipboard
</CButton>
</CopyToClipboard>
</>
)}
</CCol>
</CRow>
Expand All @@ -83,6 +101,7 @@ CippCodeOffCanvas.propTypes = {
type: PropTypes.string,
title: PropTypes.string,
hideButton: PropTypes.bool,
path: PropTypes.string,
}

export default CippCodeOffCanvas
2 changes: 1 addition & 1 deletion src/components/utilities/SharedModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function mapBodyComponent({ componentType, data, componentProps }) {
}

const sharedProps = {
componentType: PropTypes.oneOf(['table', 'list', 'text', 'confirm']),
componentType: PropTypes.oneOf(['table', 'list', 'text', 'confirm', 'codeblock']),
componentProps: PropTypes.object,
body: PropTypes.oneOfType([PropTypes.node, PropTypes.element]),
data: PropTypes.any,
Expand Down
31 changes: 29 additions & 2 deletions src/views/tenant/administration/GraphExplorer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
import { OnChange } from 'react-final-form-listeners'
import { cellGenericFormatter } from 'src/components/tables/CellGenericFormat'
import PropTypes from 'prop-types'
import { ModalService } from 'src/components/utilities'
import { CippCodeOffCanvas, ModalService } from 'src/components/utilities'

const GraphExplorer = () => {
const tenant = useSelector((state) => state.app.currentTenant)
Expand All @@ -39,6 +39,7 @@ const GraphExplorer = () => {
const [alertVisible, setAlertVisible] = useState()
const [random, setRandom] = useState('')
const [random2, setRandom2] = useState('')
const [ocVisible, setOCVisible] = useState(false)
const [searchNow, setSearchNow] = useState(false)
const [visibleA, setVisibleA] = useState(true)
const handleSubmit = async (values) => {
Expand Down Expand Up @@ -316,7 +317,11 @@ const GraphExplorer = () => {
</div>
<RFFCFormInput type="text" name="name" label="Preset Name" />
<WhenFieldChanges field="reportTemplate" set="name" />
<RFFCFormSwitch name="IsShared" label="Share Preset" />
<CTooltip content="Share this preset with other users?">
<span>
<RFFCFormSwitch name="IsShared" label="Share Preset" />
</span>
</CTooltip>
<WhenFieldChanges field="reportTemplate" set="IsShared" />
<FormSpy>
{(props) => {
Expand All @@ -326,6 +331,14 @@ const GraphExplorer = () => {
return (
<>
<div className="my-2">
<CTooltip content="Import / Export" placement="right">
<CButton
onClick={() => setOCVisible(true)}
className="me-2"
>
<FontAwesomeIcon icon="exchange-alt" />
</CButton>
</CTooltip>
{!preset[0]?.isBuiltin &&
preset[0]?.id &&
preset[0]?.IsMyPreset && (
Expand Down Expand Up @@ -373,6 +386,7 @@ const GraphExplorer = () => {
values: props.values,
})
}
className="me-2"
>
<FontAwesomeIcon icon="trash" />
</CButton>
Expand All @@ -394,6 +408,19 @@ const GraphExplorer = () => {
{postResults.data?.Results}
</CAlert>
)}
<CippCodeOffCanvas
title="Preset Import / Export"
row={{
action: 'Copy',
values: props.values,
}}
state={ocVisible}
path="api/ExecGraphExplorerPreset"
hideFunction={() => {
setOCVisible(false)
setRandom2((Math.random() + 1).toString(36).substring(7))
}}
/>
</>
)
}}
Expand Down