Skip to content

Commit

Permalink
Merge pull request #103 from utmgdsc/99-react-flow-integration
Browse files Browse the repository at this point in the history
Hotfix: Attribute section removed from interface
  • Loading branch information
RajveerSinghAnand authored Oct 17, 2024
2 parents 5a21b43 + 92a761f commit 6e5887e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 25 deletions.
24 changes: 1 addition & 23 deletions client/src/components/UMLInterfaceNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Handle, Position, NodeProps } from '@xyflow/react';
// Define types for the node data and props
interface UMLNodeData {
label?: string;
attributes?: string[];
methods?: string[];
color?: string;
removeNode?: (id: string) => void;
Expand All @@ -16,36 +15,24 @@ interface UMLNodeProps extends NodeProps<UMLNodeData> {}

const UMLInterfaceNode: React.FC<UMLNodeProps> = ({ data, id }) => {
const [label, setLabel] = useState<string>(data.label || 'Interface');
const [attributes, setAttributes] = useState<string>(data.attributes?.join('\n') || '');
const [methods, setMethods] = useState<string>(data.methods?.join('\n') || '');
const headerColor = data.color || '#FFEE93';

const attributesRef = useRef<HTMLTextAreaElement>(null);
const methodsRef = useRef<HTMLTextAreaElement>(null);

useEffect(() => {
if (attributesRef.current) {
attributesRef.current.style.height = 'auto';
attributesRef.current.style.height = `${attributesRef.current.scrollHeight}px`;
}
if (methodsRef.current) {
methodsRef.current.style.height = 'auto';
methodsRef.current.style.height = `${methodsRef.current.scrollHeight}px`;
}
}, [attributes, methods]);
}, [methods]);

const handleLabelChange = (e) => {
const newLabel = e.target.value;
setLabel(newLabel);
data.updateNodeData?.(id, { label: newLabel });
};

const handleAttributesChange = (e) => {
const newAttributes = e.target.value;
setAttributes(newAttributes);
data.updateNodeData?.(id, { attributes: newAttributes.split('\n') });
};

const handleMethodsChange = (e) => {
const newMethods = e.target.value;
setMethods(newMethods);
Expand Down Expand Up @@ -95,15 +82,6 @@ const UMLInterfaceNode: React.FC<UMLNodeProps> = ({ data, id }) => {
X
</button>
</div>
<div style={{ padding: '10px' }}>
<textarea
ref={attributesRef}
value={attributes}
onChange={handleAttributesChange}
placeholder="Attributes"
style={{ width: '100%', resize: 'none', overflow: 'hidden' }}
/>
</div>
<div style={{ padding: '10px' }}>
<textarea
ref={methodsRef}
Expand Down
2 changes: 0 additions & 2 deletions client/src/pages/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ const UMLDiagramEditor = ({ problemId }) => {
position: { x: Math.random() * 500, y: Math.random() * 500 },
data: {
label: `InterfaceNode${nodes.length + 1}`,
attributes: [],
methods: [],
color: getNodeColor(),
},
Expand Down Expand Up @@ -472,7 +471,6 @@ const UMLDiagramEditor = ({ problemId }) => {
<UMLInterfaceNode
data={{
label: 'New Interface',
attributes: ['attribute: type'], // Add attributes for preview
methods: ['method()'],
isPreview: true,
showButtons: false,
Expand Down

0 comments on commit 6e5887e

Please sign in to comment.