summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/components/context
diff options
context:
space:
mode:
authorFabian Mastenbroek <mail.fabianm@gmail.com>2021-10-25 14:53:54 +0200
committerFabian Mastenbroek <mail.fabianm@gmail.com>2021-10-25 14:53:54 +0200
commitaa9b32f8cd1467e9718959f400f6777e5d71737d (patch)
treeb88bbede15108c6855d7f94ded4c7054df186a72 /opendc-web/opendc-web-ui/src/components/context
parenteb0e0a3bc557c05a70eead388797ab850ea87366 (diff)
parentb7a71e5b4aa77b41ef41deec2ace42b67a5a13a7 (diff)
merge: Integrate v2.1 progress into public repository
This pull request integrates the changes planned for the v2.1 release of OpenDC into the public Github repository in order to sync the progress of both repositories.
Diffstat (limited to 'opendc-web/opendc-web-ui/src/components/context')
-rw-r--r--opendc-web/opendc-web-ui/src/components/context/ContextSelectionSection.js34
-rw-r--r--opendc-web/opendc-web-ui/src/components/context/ContextSelectionSection.module.scss28
-rw-r--r--opendc-web/opendc-web-ui/src/components/context/ContextSelector.js75
-rw-r--r--opendc-web/opendc-web-ui/src/components/context/ContextSelector.module.scss45
-rw-r--r--opendc-web/opendc-web-ui/src/components/context/PortfolioSelector.js47
-rw-r--r--opendc-web/opendc-web-ui/src/components/context/ProjectSelector.js48
-rw-r--r--opendc-web/opendc-web-ui/src/components/context/TopologySelector.js52
7 files changed, 329 insertions, 0 deletions
diff --git a/opendc-web/opendc-web-ui/src/components/context/ContextSelectionSection.js b/opendc-web/opendc-web-ui/src/components/context/ContextSelectionSection.js
new file mode 100644
index 00000000..5d3a6441
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/components/context/ContextSelectionSection.js
@@ -0,0 +1,34 @@
+/*
+ * 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 PropTypes from 'prop-types'
+import { contextSelectionSection } from './ContextSelectionSection.module.scss'
+
+function ContextSelectionSection({ children }) {
+ return <section className={contextSelectionSection}>{children}</section>
+}
+
+ContextSelectionSection.propTypes = {
+ children: PropTypes.node,
+}
+
+export default ContextSelectionSection
diff --git a/opendc-web/opendc-web-ui/src/components/context/ContextSelectionSection.module.scss b/opendc-web/opendc-web-ui/src/components/context/ContextSelectionSection.module.scss
new file mode 100644
index 00000000..0e902af0
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/components/context/ContextSelectionSection.module.scss
@@ -0,0 +1,28 @@
+/*!
+ * 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.
+ */
+
+.contextSelectionSection {
+ padding-left: var(--pf-c-page__main-breadcrumb--PaddingLeft);
+ flex-shrink: 0;
+ border-bottom: var(--pf-global--BorderWidth--sm) solid var(--pf-global--BorderColor--100);
+ background-color: var(--pf-c-page__main-breadcrumb--BackgroundColor);
+}
diff --git a/opendc-web/opendc-web-ui/src/components/context/ContextSelector.js b/opendc-web/opendc-web-ui/src/components/context/ContextSelector.js
new file mode 100644
index 00000000..3712cfa0
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/components/context/ContextSelector.js
@@ -0,0 +1,75 @@
+/*
+ * 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 PropTypes from 'prop-types'
+import { ContextSelector as PFContextSelector, ContextSelectorItem } from '@patternfly/react-core'
+import { useMemo, useState, useReducer } from 'react'
+import { contextSelector } from './ContextSelector.module.scss'
+
+function ContextSelector({ activeItem, items, onSelect, label }) {
+ const [isOpen, toggle] = useReducer((isOpen) => !isOpen, false)
+ const [searchValue, setSearchValue] = useState('')
+
+ const filteredItems = useMemo(
+ () => items.filter(({ name }) => name.toLowerCase().indexOf(searchValue.toLowerCase()) !== -1) || items,
+ [items, searchValue]
+ )
+
+ return (
+ <PFContextSelector
+ menuAppendTo={global.document?.body}
+ className={contextSelector}
+ toggleText={activeItem ? `${label}: ${activeItem.name}` : label}
+ onSearchInputChange={(value) => setSearchValue(value)}
+ searchInputValue={searchValue}
+ isOpen={isOpen}
+ onToggle={toggle}
+ onSelect={(event) => {
+ const targetId = event.target.value
+ const target = items.find((item) => item._id === targetId)
+
+ toggle()
+ onSelect(target)
+ }}
+ >
+ {filteredItems.map((item) => (
+ <ContextSelectorItem key={item._id} value={item._id}>
+ {item.name}
+ </ContextSelectorItem>
+ ))}
+ </PFContextSelector>
+ )
+}
+
+const Item = PropTypes.shape({
+ _id: PropTypes.string.isRequired,
+ name: PropTypes.string.isRequired,
+})
+
+ContextSelector.propTypes = {
+ activeItem: Item,
+ items: PropTypes.arrayOf(Item).isRequired,
+ onSelect: PropTypes.func.isRequired,
+ label: PropTypes.string,
+}
+
+export default ContextSelector
diff --git a/opendc-web/opendc-web-ui/src/components/context/ContextSelector.module.scss b/opendc-web/opendc-web-ui/src/components/context/ContextSelector.module.scss
new file mode 100644
index 00000000..fefba41f
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/components/context/ContextSelector.module.scss
@@ -0,0 +1,45 @@
+/*
+ * 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.
+ */
+
+.contextSelector {
+ width: auto;
+ margin-right: 20px;
+
+ --pf-c-context-selector__toggle--PaddingTop: var(--pf-global--spacer--sm);
+ --pf-c-context-selector__toggle--PaddingRight: 0;
+ --pf-c-context-selector__toggle--PaddingBottom: var(--pf-global--spacer--sm);
+ --pf-c-context-selector__toggle--PaddingLeft: 0;
+ --pf-c-context-selector__toggle--BorderWidth: 0;
+ --pf-c-context-selector__toggle-text--FontSize: var(--pf-global--FontSize--sm);
+
+ & :global(.pf-c-context-selector__toggle) {
+ &:active,
+ &:focus-within,
+ &:global(.pf-m-active) {
+ --pf-c-context-selector__toggle--after--BorderBottomWidth: 0;
+ }
+ }
+
+ &:global(.pf-m-expanded) > :global(.pf-c-context-selector__toggle) {
+ --pf-c-context-selector__toggle--after--BorderBottomWidth: 0;
+ }
+}
diff --git a/opendc-web/opendc-web-ui/src/components/context/PortfolioSelector.js b/opendc-web/opendc-web-ui/src/components/context/PortfolioSelector.js
new file mode 100644
index 00000000..694681ac
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/components/context/PortfolioSelector.js
@@ -0,0 +1,47 @@
+/*
+ * 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 { useRouter } from 'next/router'
+import { useMemo } from 'react'
+import { useProjectPortfolios } from '../../data/project'
+import ContextSelector from './ContextSelector'
+
+function PortfolioSelector() {
+ const router = useRouter()
+ const { project, portfolio: activePortfolioId } = router.query
+ const { data: portfolios = [] } = useProjectPortfolios(project)
+ const activePortfolio = useMemo(() => portfolios.find((portfolio) => portfolio._id === activePortfolioId), [
+ activePortfolioId,
+ portfolios,
+ ])
+
+ return (
+ <ContextSelector
+ label="Portfolio"
+ activeItem={activePortfolio}
+ items={portfolios}
+ onSelect={(portfolio) => router.push(`/projects/${portfolio.projectId}/portfolios/${portfolio._id}`)}
+ />
+ )
+}
+
+export default PortfolioSelector
diff --git a/opendc-web/opendc-web-ui/src/components/context/ProjectSelector.js b/opendc-web/opendc-web-ui/src/components/context/ProjectSelector.js
new file mode 100644
index 00000000..753632ab
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/components/context/ProjectSelector.js
@@ -0,0 +1,48 @@
+/*
+ * 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 PropTypes from 'prop-types'
+import { useRouter } from 'next/router'
+import { useMemo } from 'react'
+import { useProjects } from '../../data/project'
+import ContextSelector from './ContextSelector'
+
+function ProjectSelector({ projectId }) {
+ const router = useRouter()
+ const { data: projects = [] } = useProjects()
+ const activeProject = useMemo(() => projects.find((project) => project._id === projectId), [projectId, projects])
+
+ return (
+ <ContextSelector
+ label="Project"
+ activeItem={activeProject}
+ items={projects}
+ onSelect={(project) => router.push(`/projects/${project._id}`)}
+ />
+ )
+}
+
+ProjectSelector.propTypes = {
+ projectId: PropTypes.string,
+}
+
+export default ProjectSelector
diff --git a/opendc-web/opendc-web-ui/src/components/context/TopologySelector.js b/opendc-web/opendc-web-ui/src/components/context/TopologySelector.js
new file mode 100644
index 00000000..d5e51c6c
--- /dev/null
+++ b/opendc-web/opendc-web-ui/src/components/context/TopologySelector.js
@@ -0,0 +1,52 @@
+/*
+ * 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 PropTypes from 'prop-types'
+import { useRouter } from 'next/router'
+import { useMemo } from 'react'
+import { useProjectTopologies } from '../../data/topology'
+import ContextSelector from './ContextSelector'
+
+function TopologySelector({ projectId, topologyId }) {
+ const router = useRouter()
+ const { data: topologies = [] } = useProjectTopologies(projectId)
+ const activeTopology = useMemo(() => topologies.find((topology) => topology._id === topologyId), [
+ topologyId,
+ topologies,
+ ])
+
+ return (
+ <ContextSelector
+ label="Topology"
+ activeItem={activeTopology}
+ items={topologies}
+ onSelect={(topology) => router.push(`/projects/${topology.projectId}/topologies/${topology._id}`)}
+ />
+ )
+}
+
+TopologySelector.propTypes = {
+ projectId: PropTypes.string,
+ topologyId: PropTypes.string,
+}
+
+export default TopologySelector