Skip to content

Commit

Permalink
add checks to prevent reparenting into children
Browse files Browse the repository at this point in the history
  • Loading branch information
zippy committed Dec 7, 2023
1 parent fcff8d5 commit 748e225
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
5 changes: 3 additions & 2 deletions dnas/how/zomes/coordinator/how/src/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,9 @@ pub struct ReparentInput {
}
#[hdk_extern]
pub fn reparent(input: ReparentInput) -> ExternResult<()> {
// let new_parent_path = Path::from(input.new_parent);
// let link = get
if input.new_parent.starts_with(&input.path) {
return Err(wasm_error!(WasmErrorInner::Guest(String::from("Can't reparent to child"))));
}
let sub_tree = _get_path_tree(tree_path(input.path.clone()))?;
let mut parent:Vec<_> = input.path.split(".").into_iter().collect();
parent.pop();
Expand Down
23 changes: 17 additions & 6 deletions ui/src/elements/how-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,9 @@ export class HowController extends ScopedElementsMixin(LitElement) {
@click=${async ()=>{await this.doExport()}}>Export</sl-button>
</sl-dialog>
<sl-dialog id="reparent" label="Reparent">
<sl-dropdown id="units-menu">
${this._currentUnitEh ? html`
<sl-dialog id="reparent" label="Reparent">
<sl-dropdown id="units-menu">
<sl-button slot="trigger"
@click=${(e:any)=>{
e.stopPropagation()
Expand All @@ -570,12 +571,22 @@ export class HowController extends ScopedElementsMixin(LitElement) {
@mouseleave=${()=> this._unitsMenu.hide()}
@click=${(e:any)=>e.stopPropagation()}
@sl-select=${(e:any)=>{
console.log("SELECTED:", e.detail.item.value)
this._reparentingToUnitHash = e.detail.item.value
this._unitsMenu.hide()
}}>
${
Object.entries(this._units.value).map(([key, unit]) => html`
Object.entries(this._units.value).filter(([_,unit])=>{
const currentUnit = this._units.value[this._currentUnitEh]
const currentPath = currentUnit.path()
const unitPath = unit.path()
let current_path_parent = ""
if (currentUnit) {
const p = currentPath.split(".")
p.pop()
current_path_parent = p.join(".")
}
return !unitPath.startsWith(currentPath) && (unitPath != current_path_parent)
}).map(([key, unit]) => html`
<sl-menu-item value=${key}>
${unit.path() == "" ? "<Root>" : unit.path()}
</sl-menu-item>
Expand All @@ -585,8 +596,8 @@ export class HowController extends ScopedElementsMixin(LitElement) {
</sl-dropdown>
<sl-button
@click=${async ()=>{await this.doReparent()}}>Do it!</sl-button>
</sl-dialog>
</sl-dialog>
` : ""}
<div>
<div id="top-bar" class="row">
Expand Down

0 comments on commit 748e225

Please sign in to comment.