Skip to content

Commit

Permalink
Gardening.
Browse files Browse the repository at this point in the history
  • Loading branch information
mchilvers committed Mar 26, 2024
1 parent 3e4a24e commit 53f696d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
20 changes: 11 additions & 9 deletions src/tools/builder/src/python/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,26 @@ def get_available_components(self):

return json.dumps(blueprints)

def add_component(self, parent_id, component_klass_name):
def append_component(self, parent_id, component_type_name):
"""
Add a component to the end of the specified page.
Append a component to the specified parent.
"""
parent = self._app.get_component_by_id(parent_id)
if parent is None:
raise ValueError(f"No such container: {parent_id}")

component = create_component(component_klass_name)
self.insert_after(parent.content[-1], component)
self.insert_component_after(parent.content[-1], component_type_name)

def insert_after(self, after_component, component):
def insert_component_after(self, after_component, component_type_name):
"""
Insert a component after another (as a sibling).
"""

parent = after_component.parent
after_component_index = parent.content.index(after_component)

component = create_component(component_type_name)

if after_component_index == len(parent.content) - 1:
parent.append(component)
parent.append(BuilderDropZone(self))
Expand Down Expand Up @@ -287,14 +288,15 @@ def on_drop(self, event):
event.preventDefault()
event.stopPropagation()
self.element.classList.remove("drop-zone-active")

component_blueprint = json.loads(event.dataTransfer.getData("widget"))
component = create_component(component_blueprint["name"])
self.builder.insert_after(after_component=self, component=component)

self.builder.insert_component_after(
after_component=self, component_type_name=component_blueprint["name"]
)

def render(self):
"""
Render the component's HTML element.
Create the component's HTML element.
"""
element = document.createElement("div")
element.id = self.id
Expand Down
4 changes: 2 additions & 2 deletions src/tools/builder/src/utilities/builder-utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export class BuilderUtilities {

// Components //////////////////////////////////////////////////////////////////////

public static addComponent(parentId: string, componentTypeName: string): void {
this.builder().add_component(parentId, componentTypeName);
public static appendComponent(parentId: string, componentTypeName: string): void {
this.builder().append_component(parentId, componentTypeName);
}

public static deleteComponent(componentId: string) {
Expand Down
10 changes: 4 additions & 6 deletions src/tools/builder/src/views/builder/builder-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class BuilderModel extends ViewModelBase {
}
});
}

/**
* Called when a page button is clicked.
*/
Expand Down Expand Up @@ -116,7 +116,7 @@ export class BuilderModel extends ViewModelBase {
}
}

BuilderUtilities.addComponent(parentId, widgetBlueprint.name);
BuilderUtilities.appendComponent(parentId, widgetBlueprint.name);
}

/**
Expand All @@ -125,15 +125,13 @@ export class BuilderModel extends ViewModelBase {
* This is called from the Python-side of the view model.
*/
public onComponentClicked(componentBlueprint: any, component: any) {
this.state.activeWidgetId = component.id;
this.openPropertiesForWidget(componentBlueprint, component.id);
}

public openPropertiesForWidget(widgetBlueprint: WidgetModel, componentId: string): void {
this.state.activeWidgetProperties = BuilderUtilities.getComponentProperties(
componentId
);
this.state.activeWidgetId = componentId;
this.state.activeWidgetBlueprint = widgetBlueprint;
this.state.activeWidgetProperties = BuilderUtilities.getComponentProperties(componentId);
}

public updateComponentProperty(key: string, value: string, isFromDatastore?: boolean) {
Expand Down

0 comments on commit 53f696d

Please sign in to comment.