summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-server/src/main/webui/components/projects/ImportTopology.js
diff options
context:
space:
mode:
authorvincent van beek <vincent@vlogic.nl>2026-03-27 16:49:40 +0100
committerGitHub <noreply@github.com>2026-03-27 15:49:40 +0000
commit048bf777997bdbf599240645fc66612c98abf3c2 (patch)
treec04e999cb981c98ae9dc0fd83ea70aec9eaa419c /opendc-web/opendc-web-server/src/main/webui/components/projects/ImportTopology.js
parent235057cd170f1583db14bf93ea7d2de39e492356 (diff)
Add import topology (#393)
* add a the posibility to import and export topogies in JSON format * fix web-runner integration, there were several bugs and mismatches between new implementations in OpenDC and the UI
Diffstat (limited to 'opendc-web/opendc-web-server/src/main/webui/components/projects/ImportTopology.js')
-rw-r--r--opendc-web/opendc-web-server/src/main/webui/components/projects/ImportTopology.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/opendc-web/opendc-web-server/src/main/webui/components/projects/ImportTopology.js b/opendc-web/opendc-web-server/src/main/webui/components/projects/ImportTopology.js
new file mode 100644
index 00000000..715c1a3e
--- /dev/null
+++ b/opendc-web/opendc-web-server/src/main/webui/components/projects/ImportTopology.js
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2021 AtLarge Research
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+import React, { useState } from 'react'
+import PropTypes from 'prop-types'
+import { UploadIcon } from '@patternfly/react-icons'
+import { Button } from '@patternfly/react-core'
+import { useNewTopology, useTopologies } from '../../data/topology'
+import ImportTopologyModal from './ImportTopologyModal'
+
+function ImportTopology({ projectId }) {
+ const [isVisible, setVisible] = useState(false)
+ const { mutate: addTopology } = useNewTopology()
+ const { data: topologies = [] } = useTopologies(projectId, { enabled: isVisible })
+
+ const onSubmit = (topology) => {
+ addTopology({ projectId, ...topology })
+ setVisible(false)
+ }
+
+ return (
+ <>
+ <Button variant="secondary" icon={<UploadIcon />} isSmall onClick={() => setVisible(true)}>
+ Import Topology
+ </Button>
+ <ImportTopologyModal
+ isOpen={isVisible}
+ onCancel={() => setVisible(false)}
+ onSubmit={onSubmit}
+ topologies={topologies}
+ />
+ </>
+ )
+}
+
+ImportTopology.propTypes = {
+ projectId: PropTypes.number,
+}
+
+export default ImportTopology