Skip to content

Commit

Permalink
Merge pull request #341 from XpressAI/paul/attach-literals-copy-paste
Browse files Browse the repository at this point in the history
Copy & Paste support for Attached Literals
  • Loading branch information
MFA-X-AI authored Jul 16, 2024
2 parents a464313 + c5a4db3 commit b4dbe0b
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
28 changes: 23 additions & 5 deletions src/commands/NodeActionCommands.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,33 @@ export function addNodeActionCommands(
label: trans.__('Add Comment')
});

function selectAllRelevantNodes(widget: XircuitsPanel){
widget.xircuitsApp.getDiagramEngine().getModel().getSelectedEntities().forEach(entity => {
if(entity.getType() === 'custom-node'){
const node = (entity as CustomNodeModel);
// Find links to attached node and copy them too
Object.values(node.getPorts()).forEach(port => {
Object.values(port.getLinks()).forEach(link => {
const parentNode = link.getSourcePort().getParent();
if(parentNode.getOptions()?.extras?.attached){
parentNode.setSelected(true);
link.setSelected(true);
}
})
})
}
});

return widget.xircuitsApp.getDiagramEngine().getModel().getSelectedEntities();
}

function cutNode(): void {
const widget = tracker.currentWidget?.content as XircuitsPanel;

if (!widget) return;

const engine = widget.xircuitsApp.getDiagramEngine();
const selected = widget.xircuitsApp.getDiagramEngine().getModel().getSelectedEntities()
const selected = selectAllRelevantNodes(widget);
const copies = selected.map(entity =>
entity.serialize()
);
Expand All @@ -536,9 +556,7 @@ export function addNodeActionCommands(

if (!widget) return;

const copies = widget.xircuitsApp.getDiagramEngine().getModel().getSelectedEntities().map(entity =>
entity.serialize(),
);
const copies = selectAllRelevantNodes(widget).map(entity => entity.serialize());

localStorage.setItem('clipboard', JSON.stringify(copies));
}
Expand Down Expand Up @@ -658,7 +676,7 @@ export function addNodeActionCommands(
clipboardLinks.forEach(serializedLink => {
const newSourceID = idMap[serializedLink.sourcePort];
const newTargetID = idMap[serializedLink.targetPort];

if (newSourceID && newTargetID) {
const { sourcePort, targetPort } = getSourceAndTargetPorts(model, newSourceID, newTargetID);
if(sourcePort && targetPort) recreateLink(engine, model, serializedLink, sourcePort, targetPort, mousePosition, centerX, centerY);
Expand Down
4 changes: 2 additions & 2 deletions src/dialog/FormDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ const preventDefaultDialogHandler = (
event.stopPropagation();
event.preventDefault();
}
// When 'Enter' key is pressed while on input dialog and the input isn't Literal Chat, force focus to submit button
// When 'Enter' key is pressed while on input dialog and the input isn't Literal Chat or the attached checkbox, force focus to submit button
const dialogInput = dialog.node.getElementsByTagName('input')[0];
if (dialogInput && dialogInput.name !== 'messages') {
if (dialogInput && !['messages', 'attachNode'].includes(dialogInput.name)) {
await defaultButton.focus();
}
} else {
Expand Down
1 change: 0 additions & 1 deletion src/dialog/LiteralInputDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export const LiteralInputDialog = ({ title, oldValue, type, inputType, attached,
const InputValueDialog = () => {
const [attach, setAttach] = useState(attached || false)
const InputComponent = inputComponents[inputType === 'textarea' ? inputType.toLowerCase() : type.toLowerCase()];
console.log("me seeks", InputComponent, showAttachOption);

// The `type` prop is now passed to all components
const extraProps = { type, inputType };
Expand Down
2 changes: 0 additions & 2 deletions src/tray_library/GeneralComponentLib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ export async function handleLiteralInput(nodeName, nodeData, inputValue = "", ty
let attached = false;

do {
console.log("valuexxx", nodeConnections);

const isCreatingNewNode = nodeConnections === 0;
let dialogOptions = inputDialog({ title, oldValue: inputValue, type, attached: (nodeData.extras?.attached || false ), showAttachOption: !isCreatingNewNode});
let dialogResult = await showFormDialog(dialogOptions);
Expand Down

0 comments on commit b4dbe0b

Please sign in to comment.