Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨Add component that enable to add import #136

Merged
merged 2 commits into from
Apr 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/components/xircuitBodyWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,17 @@ export const BodyWidget: FC<BodyWidgetProps> = ({
let current_node: any;
let package_name: string = "components";

const addImportNode = getNodeModelByName(nodeModels, 'AddImport');
if (componentName == 'AddImport') {
const importPortName = addImportNode['portsIn'][1].getOptions()['name']
const getImportPortLinks = addImportNode.getPorts()[importPortName].getLinks();
for (let portLink in getImportPortLinks) {
// Add value of import_str port for importing
const importLabel = getImportPortLinks[portLink].getSourcePort().getOptions()["label"];
pythonCode += importLabel + "\n";
}
}

if (component_exist != -1) {
current_node = componentList[component_exist];
package_name = current_node["package_name"];
Expand Down
14 changes: 13 additions & 1 deletion xai_components/xai_template/example_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,16 @@ def execute(self, ctx) -> None:

print(f"After Adding Context:\n{ctx}")

self.done = True
self.done = True

@xai_component(color="red")
class AddImport(Component):
import_str: InArg[str]

def __init__(self):
self.import_str = InArg.empty()
self.done = False

def execute(self, ctx) -> None:

self.done = True