You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ma...@apache.org on 2023/09/16 13:56:35 UTC
[camel-karavan] branch main updated: Open file from topology #893
This is an automated email from the ASF dual-hosted git repository.
marat pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-karavan.git
The following commit(s) were added to refs/heads/main by this push:
new 5c9464f5 Open file from topology #893
5c9464f5 is described below
commit 5c9464f588b03dc5b39a8d3ef3f33ef272a58fac
Author: Marat Gubaidullin <ma...@talismancloud.io>
AuthorDate: Sat Sep 16 09:56:27 2023 -0400
Open file from topology #893
---
.../src/main/webui/src/project/files/FilesTab.tsx | 8 ++--
.../main/webui/src/project/topology/CustomNode.tsx | 20 +++++++--
.../webui/src/project/topology/TopologyApi.tsx | 6 ++-
.../project/topology/TopologyPropertiesPanel.tsx | 34 +++++++++++++++
.../webui/src/project/topology/TopologyStore.ts | 35 ++++++++++++++++
.../webui/src/project/topology/TopologyTab.tsx | 29 ++++---------
.../webui/src/project/topology/TopologyToolbar.tsx | 49 ----------------------
7 files changed, 102 insertions(+), 79 deletions(-)
diff --git a/karavan-web/karavan-app/src/main/webui/src/project/files/FilesTab.tsx b/karavan-web/karavan-app/src/main/webui/src/project/files/FilesTab.tsx
index 409fff07..a78470e1 100644
--- a/karavan-web/karavan-app/src/main/webui/src/project/files/FilesTab.tsx
+++ b/karavan-web/karavan-app/src/main/webui/src/project/files/FilesTab.tsx
@@ -35,7 +35,7 @@ export function FilesTab () {
const [files] = useFilesStore((s) => [s.files], shallow);
const [project] = useProjectStore((s) => [s.project], shallow);
- const [operation] = useFileStore((s) => [s.operation], shallow);
+ const [operation, setFile] = useFileStore((s) => [s.operation, s.setFile], shallow);
function getDate(lastUpdate: number): string {
if (lastUpdate) {
@@ -100,9 +100,9 @@ export function FilesTab () {
</Td>
<Td>
<Button style={{padding: '6px'}} variant={"link"}
- onClick={e =>
- useFileStore.setState({file: file, operation: "select"})
- }>
+ onClick={e => {
+ setFile('select', file);
+ }}>
{file.name}
</Button>
</Td>
diff --git a/karavan-web/karavan-app/src/main/webui/src/project/topology/CustomNode.tsx b/karavan-web/karavan-app/src/main/webui/src/project/topology/CustomNode.tsx
index 7722c2d1..ed987471 100644
--- a/karavan-web/karavan-app/src/main/webui/src/project/topology/CustomNode.tsx
+++ b/karavan-web/karavan-app/src/main/webui/src/project/topology/CustomNode.tsx
@@ -5,6 +5,8 @@ import { DefaultNode, observer} from '@patternfly/react-topology';
import {getDesignerIcon} from "../../designer/utils/KaravanIcons";
import {CamelUi} from "../../designer/utils/CamelUi";
import './topology.css';
+import {useFilesStore, useFileStore, useProjectStore} from "../../api/ProjectStore";
+import {shallow} from "zustand/shallow";
function getIcon(data: any) {
if (['route', 'rest'].includes(data.icon)) {
@@ -24,16 +26,26 @@ function getIcon(data: any) {
}
const CustomNode: React.FC<any> = observer(({ element, ...rest }) => {
+
+ const [files] = useFilesStore((s) => [s.files], shallow);
+ const [setFile] = useFileStore((s) => [s.setFile], shallow);
+
const data = element.getData();
+ function openFile(data: any) {
+ if (data.fileName) {
+ const file = files.filter(f => f.name === data.fileName)?.at(0);
+ if (file) {
+ setFile('select', file);
+ }
+ }
+ }
+
return (
<DefaultNode
className="common-node"
element={element} {...rest}
- // badge={data.badge}
- // badgeColor={}
- // badgeTextColor={badgeColors?.badgeTextColor}
- // badgeBorderColor={badgeColors?.badgeBorderColor}
+ onSelect={e => openFile(data)}
>
{getIcon(data)}
</DefaultNode>
diff --git a/karavan-web/karavan-app/src/main/webui/src/project/topology/TopologyApi.tsx b/karavan-web/karavan-app/src/main/webui/src/project/topology/TopologyApi.tsx
index 403a519b..99461f5f 100644
--- a/karavan-web/karavan-app/src/main/webui/src/project/topology/TopologyApi.tsx
+++ b/karavan-web/karavan-app/src/main/webui/src/project/topology/TopologyApi.tsx
@@ -61,14 +61,16 @@ export function getRoutes(tins: TopologyRouteNode[]): NodeModel[] {
const node: NodeModel = {
id: tin.id,
type: 'node',
- // label: tin.title,
+ label: tin.title,
width: NODE_DIAMETER,
height: NODE_DIAMETER,
shape: NodeShape.rect,
status: NodeStatus.default,
data: {
isAlternate: false,
- icon: 'route'
+ icon: 'route',
+ routeId: tin.routeId,
+ fileName: tin.fileName,
}
}
return node;
diff --git a/karavan-web/karavan-app/src/main/webui/src/project/topology/TopologyPropertiesPanel.tsx b/karavan-web/karavan-app/src/main/webui/src/project/topology/TopologyPropertiesPanel.tsx
new file mode 100644
index 00000000..34aa7285
--- /dev/null
+++ b/karavan-web/karavan-app/src/main/webui/src/project/topology/TopologyPropertiesPanel.tsx
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+import React from 'react';
+import '../../designer/karavan.css';
+import {shallow} from "zustand/shallow";
+import {TopologySideBar} from "@patternfly/react-topology";
+import {useTopologyStore} from "./TopologyStore";
+
+export function TopologyPropertiesPanel () {
+ const [selectedIds, setSelectedIds] = useTopologyStore((s) => [s.selectedIds, s.setSelectedIds], shallow);
+ return (
+ <TopologySideBar
+ className="topology-sidebar"
+ show={selectedIds.length > 0}
+ onClose={() => setSelectedIds([])}
+ >
+ <div style={{ marginTop: 27, marginLeft: 20, height: '800px' }}>{selectedIds[0]}</div>
+ </TopologySideBar>
+ )
+}
diff --git a/karavan-web/karavan-app/src/main/webui/src/project/topology/TopologyStore.ts b/karavan-web/karavan-app/src/main/webui/src/project/topology/TopologyStore.ts
new file mode 100644
index 00000000..dce4b08c
--- /dev/null
+++ b/karavan-web/karavan-app/src/main/webui/src/project/topology/TopologyStore.ts
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import {createWithEqualityFn} from "zustand/traditional";
+import {shallow} from "zustand/shallow";
+
+interface TopologyState {
+ selectedIds: string [],
+ setSelectedIds: (images: string []) => void;
+}
+
+export const useTopologyStore = createWithEqualityFn<TopologyState>((set) => ({
+ selectedIds: [],
+ setSelectedIds: (selectedIds: string[]) => {
+ set((state: TopologyState) => {
+ state.selectedIds.length = 0;
+ state.selectedIds.push(...selectedIds);
+ return {selectedIds: state.selectedIds};
+ });
+ }
+}), shallow)
diff --git a/karavan-web/karavan-app/src/main/webui/src/project/topology/TopologyTab.tsx b/karavan-web/karavan-app/src/main/webui/src/project/topology/TopologyTab.tsx
index 534d6dab..49b47f21 100644
--- a/karavan-web/karavan-app/src/main/webui/src/project/topology/TopologyTab.tsx
+++ b/karavan-web/karavan-app/src/main/webui/src/project/topology/TopologyTab.tsx
@@ -13,22 +13,18 @@ import {
VisualizationProvider,
VisualizationSurface,
DagreLayout,
- ColaLayout,
- ForceLayout,
- ColaGroupsLayout,
- GridLayout,
SELECTION_EVENT,
- TopologySideBar,
} from '@patternfly/react-topology';
import {customComponentFactory, getModel} from "./TopologyApi";
-import {useFilesStore, useProjectStore} from "../../api/ProjectStore";
+import {useFilesStore} from "../../api/ProjectStore";
import {shallow} from "zustand/shallow";
+import {useTopologyStore} from "./TopologyStore";
+import {TopologyPropertiesPanel} from "./TopologyPropertiesPanel";
export const TopologyTab: React.FC = () => {
const [files] = useFilesStore((s) => [s.files], shallow);
- const [project] = useProjectStore((s) => [s.project], shallow);
- const [selectedIds, setSelectedIds] = React.useState<string[]>([]);
+ const [selectedIds, setSelectedIds] = useTopologyStore((s) => [s.selectedIds, s.setSelectedIds], shallow);
const controller = React.useMemo(() => {
const model = getModel(files);
@@ -36,7 +32,10 @@ export const TopologyTab: React.FC = () => {
newController.registerLayoutFactory((_, graph) => new DagreLayout(graph));
newController.registerComponentFactory(customComponentFactory);
- newController.addEventListener(SELECTION_EVENT, setSelectedIds);
+ // newController.addEventListener(SELECTION_EVENT, setSelectedIds);
+ // newController.addEventListener(SELECTION_EVENT, args => {
+ // console.log(args)
+ // });
newController.addEventListener(GRAPH_LAYOUT_END_EVENT, () => {
newController.getGraph().fit(80);
});
@@ -50,20 +49,10 @@ export const TopologyTab: React.FC = () => {
controller.fromModel(model, false);
}, []);
- const topologySideBar = (
- <TopologySideBar
- className="topology-sidebar"
- show={selectedIds.length > 0}
- onClose={() => setSelectedIds([])}
- >
- <div style={{ marginTop: 27, marginLeft: 20, height: '800px' }}>{selectedIds[0]}</div>
- </TopologySideBar>
- );
-
return (
<TopologyView
viewToolbar={<ToolbarItem>{}</ToolbarItem>}
- sideBar={topologySideBar}
+ sideBar={<TopologyPropertiesPanel/>}
controlBar={
<TopologyControlBar
controlButtons={createTopologyControlButtons({
diff --git a/karavan-web/karavan-app/src/main/webui/src/project/topology/TopologyToolbar.tsx b/karavan-web/karavan-app/src/main/webui/src/project/topology/TopologyToolbar.tsx
deleted file mode 100644
index 3036c5bb..00000000
--- a/karavan-web/karavan-app/src/main/webui/src/project/topology/TopologyToolbar.tsx
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-import React, {useEffect, useState} from 'react';
-import {
- Button,
- Flex,
- FlexItem, Form, FormGroup, FormHelperText, Label, Modal, ModalVariant, TextInput, Tooltip, TooltipPosition,
-} from '@patternfly/react-core';
-import '../../designer/karavan.css';
-import UploadIcon from "@patternfly/react-icons/dist/esm/icons/upload-icon";
-import PlusIcon from "@patternfly/react-icons/dist/esm/icons/plus-icon";
-import {useFilesStore, useFileStore, useProjectStore} from "../../api/ProjectStore";
-import {shallow} from "zustand/shallow";
-import {ProjectService} from "../../api/ProjectService";
-import PushIcon from "@patternfly/react-icons/dist/esm/icons/code-branch-icon";
-
-export function TopologyToolbar () {
-
- const [project, isPushing] = useProjectStore((state) => [state.project, state.isPushing], shallow )
- const {files} = useFilesStore();
- const [file, editAdvancedProperties, setEditAdvancedProperties, setAddProperty] = useFileStore((state) =>
- [state.file, state.editAdvancedProperties, state.setEditAdvancedProperties, state.setAddProperty], shallow )
-
-
- useEffect(() => {
- }, [project, file]);
-
- function canAddFiles(): boolean {
- return !['templates', 'services'].includes(project.projectId);
- }
-
- return <Flex className="toolbar" direction={{default: "row"}} justifyContent={{default: "justifyContentFlexEnd"}}>
-
- </Flex>
-}