Skip to content

Commit

Permalink
adds support for creating children "under construction"
Browse files Browse the repository at this point in the history
  • Loading branch information
zippy committed Dec 27, 2023
1 parent 3c1b735 commit 26c88c6
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 37 deletions.
11 changes: 9 additions & 2 deletions dnas/how/zomes/coordinator/how/src/unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ pub fn get_units_path() -> Path {
pub const START_STATE: &str = "define";
pub const ALIVE_STATE: &str = "_alive";

#[derive(Clone, Serialize, Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct UnitInput {
pub state: String,
pub unit: Unit,
}

#[hdk_extern]
pub fn create_unit(input: Unit) -> ExternResult<UnitOutput> {
Ok(create_unit_inner(input, START_STATE)?)
pub fn create_unit(input: UnitInput) -> ExternResult<UnitOutput> {
Ok(create_unit_inner(input.unit, &input.state)?)
}

pub fn delete_unit_links(hash: EntryHash, tree_paths: Vec<Path>) -> ExternResult<()> {
Expand Down
48 changes: 25 additions & 23 deletions ui/src/elements/how-unit-dialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {property, query, state} from "lit/decorators.js";
import {sharedStyles} from "../sharedStyles";
import {ScopedElementsMixin} from "@open-wc/scoped-elements";
import {HowStore} from "../how.store";
import {Unit, howContext, Dictionary, Node, VersioningType} from "../types";
import {Unit, howContext, Dictionary, Node, VersioningType, SysState, UnitInfo} from "../types";
import {EntryHashB64} from "@holochain/client";
import {
Button,
Expand Down Expand Up @@ -54,6 +54,7 @@ export class HowUnitDialog extends ScopedElementsMixin(LitElement) {
@property() _stewards: Dictionary<string> = {};

@state() _parent?: Unit;
@state() _parentInfo?: UnitInfo;

private static readonly NONE = 'none'; // we need a default value for the mwc-selects because if an empty string is provided, the UI gets broken

Expand Down Expand Up @@ -85,6 +86,7 @@ export class HowUnitDialog extends ScopedElementsMixin(LitElement) {
}
open(parentEh: EntryHashB64) {
this._parent = this._store.unit(parentEh);
this._parentInfo = this._store.unitInfo(parentEh);
const dialog = this.shadowRoot!.getElementById("unit-dialog") as Dialog
dialog.open = true
}
Expand Down Expand Up @@ -128,7 +130,7 @@ export class HowUnitDialog extends ScopedElementsMixin(LitElement) {
this._versionField.reportValidity()
}

const processes = this.getProcessesValue()
const processes = this._parentInfo?.state == SysState.UnderConstruction ? [] : this.getProcessesValue()
const stewards = Object.keys(this._stewards).map((agent)=> agent)
if (stewards.length == 0) {
stewards.push(this._store.myAgentPubKey)
Expand All @@ -143,7 +145,7 @@ export class HowUnitDialog extends ScopedElementsMixin(LitElement) {
});

// - Add unit to commons
const newUnit = await this._store.addUnit(unit);
const newUnit = await this._store.addUnit(unit, this._parentInfo?.state == SysState.UnderConstruction? SysState.UnderConstruction : "define");
this.dispatchEvent(new CustomEvent('unit-added', { detail: newUnit, bubbles: true, composed: true }));

// - Clear all fields
Expand Down Expand Up @@ -218,26 +220,26 @@ export class HowUnitDialog extends ScopedElementsMixin(LitElement) {
<mwc-textfield type="text"
@input=${() => (this.shadowRoot!.getElementById("title-field") as TextField).reportValidity()}
id="title-field" minlength="3" maxlength="64" label="Title" autoValidate=true required></mwc-textfield>
${PROCESS_TYPES.map(processType =>
html`
<mwc-select
id="${processType}-process-select"
label="Select ${processType} process"
@closing=${(e: any) => e.stopPropagation()}
>
<mwc-list-item selected value=${HowUnitDialog.NONE}>
&ltnone&gt
</mwc-list-item>
${
this._processes[processType].value.map((process) =>
html`<mwc-list-item value=${process?.val.name}>${process?.val.name}</mwc-list-item>`
)
}
</mwc-select>
`
)}
${this._parentInfo?.state != SysState.UnderConstruction ?
PROCESS_TYPES.map(processType =>
html`
<mwc-select
id="${processType}-process-select"
label="Select ${processType} process"
@closing=${(e: any) => e.stopPropagation()}
>
<mwc-list-item selected value=${HowUnitDialog.NONE}>
&ltnone&gt
</mwc-list-item>
${
this._processes[processType].value.map((process) =>
html`<mwc-list-item value=${process?.val.name}>${process?.val.name}</mwc-list-item>`
)
}
</mwc-select>
`
) : ""}
Stewards: ${Object.keys(this._stewards).length} ${Object.entries(this._stewards).map(([agent, nickname])=>html`<span class="agent" title="${agent}">${nickname}</span>`)}
<search-agent
Expand Down
28 changes: 28 additions & 0 deletions ui/src/elements/how-unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export class HowUnit extends ScopedElementsMixin(LitElement) {
const path = this.getPath()
const docInfo = this._store.getCurrentDocument(path, this.currentUnitEh)
let allDocs = this._store.getDocumentsFiltered(path, this.currentUnitEh , DocType.Document, false)
let collections = this._store.getDocumentsFiltered(path, this.currentUnitEh , DocType.Collection, false)

const isSteward = unit.stewards.includes(this._store.myAgentPubKey)
let stewardsHTML = html`<how-agent-list .agents=${unit.stewards}></how-agent-list>`
Expand Down Expand Up @@ -238,6 +239,32 @@ export class HowUnit extends ScopedElementsMixin(LitElement) {
</mwc-select>
</div>`
}

let collectionsHTML
if (collections.length > 0) {
const collectionItemsHTML = []
for (let i=collections.length-1; i>= 0;i-=1){
const date = new Date(allDocs[i].actions[0].content.timestamp/1000)
collectionItemsHTML.push(html`
<mwc-list-item value=${i} @click=${()=>this.handleDocumentClick(collections[i].hash, true)}>
${date.toLocaleDateString('en-us', { year:"numeric", month:"short", day:"numeric"})} ${date.toLocaleTimeString('en-US')}
</mwc-list-item>`)
}
collectionsHTML = html`
<div class="history row">
<mwc-select
class="history-item"
label="Show Collection"
@closing=${(e: any) => e.stopPropagation()}
>
${collectionItemsHTML}
</mwc-select>
</div>`
}
else {
collectionsHTML = html`collections: ${collections.length}`
}

return html`
<div class="unit row">
<div class="column">
Expand Down Expand Up @@ -271,6 +298,7 @@ export class HowUnit extends ScopedElementsMixin(LitElement) {
</div>
</div>
${historyHTML}
${collectionsHTML}
<how-unit-details id="details-dialog" .state=${stateName}> </how-unit-details>
<how-confirm @confirmed=${(e:any) => this.handleConfirm(e.detail)}></how-confirm>
`;
Expand Down
4 changes: 2 additions & 2 deletions ui/src/how.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AppAgentClient, EntryHashB64, AgentPubKeyB64, AppAgentCallZomeRequest, RoleName, encodeHashToBase64 } from '@holochain/client';
import { Unit, RustNode, RustTree, Initialization, DocumentOutput, DocumentInput, UpdateDocumentInput, AdvanceStateInput, UnitOutput, MarkDocumentInput, HowSignal} from './types';
import { UnitInput, RustNode, RustTree, Initialization, DocumentOutput, DocumentInput, UpdateDocumentInput, AdvanceStateInput, UnitOutput, MarkDocumentInput, HowSignal} from './types';
import { ActionHash } from '@holochain/client';

export class HowService {
Expand All @@ -17,7 +17,7 @@ export class HowService {
return this.callZome('initialize', input);
}

async createUnit(unit: Unit): Promise<UnitOutput> {
async createUnit(unit: UnitInput): Promise<UnitOutput> {
return this.callZome('create_unit', unit);
}

Expand Down
25 changes: 16 additions & 9 deletions ui/src/how.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,28 +345,31 @@ export class HowStore {
return get(this.treeStore)
}

async initializeUnit(unitEh: EntryHashB64) : Promise<void> {
async initializeUnit(unitEh: EntryHashB64, state: string) : Promise<void> {
const unit = this.unit(unitEh)
const proc = unit.processes[0]
const processPath = `${proc[0]}.${proc[1]}`
const doc = new Document({unitHash: decodeHashFromBase64(unitEh), documentType: DocType.Document})
// TODO
doc.editors = unit.stewards
doc.state = state

doc.appendSections(await this.getSectionsFromHierarcy(unit.parents[0], 0, SectionType.Requirement))
await this.pullDocuments(processPath)
doc.appendSections(await this.getSectionsFromHierarcy(processPath, 2, SectionType.Process))

const proc = unit.processes[0]
if (proc) {
const processPath = `${proc[0]}.${proc[1]}`
await this.pullDocuments(processPath)
doc.appendSections(await this.getSectionsFromHierarcy(processPath, 2, SectionType.Process))
}

doc.setSection("title", unit.shortName)
console.log("ADDING DOC", doc)
const path = `${unit.parents[0]}.${unit.pathAbbreviation}`
await this.addDocument(path, doc)
}

async addUnit(unit: Unit) : Promise<EntryHashB64> {
const unitOutput: UnitOutput = await this.service.createUnit(unit)
async addUnit(unit: Unit, state: string) : Promise<EntryHashB64> {
const unitOutput: UnitOutput = await this.service.createUnit({unit, state})
this.updateUnitFromEntry(unitOutput)
await this.initializeUnit(encodeHashToBase64(unitOutput.info.hash))
await this.initializeUnit(encodeHashToBase64(unitOutput.info.hash), state)

//this.service.notify({unitHash:unitEh, message: {type:"NewUnit", content:unit}}, this.others());
return encodeHashToBase64(unitOutput.info.hash)
Expand All @@ -380,6 +383,10 @@ export class HowStore {
return get(this.unitsStore)[unitEh];
}

unitInfo(unitEh: EntryHashB64): UnitInfo {
return get(this.unitsInfoStore)[unitEh];
}

async addDocument(path: string, document: Document) : Promise<EntryHashB64> {
document.documentHash = await this.service.createDocument({path, document})

Expand Down
22 changes: 22 additions & 0 deletions ui/src/initHolochain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,28 @@ function mintNFT(uint256 memory target_) external {
editors: [progenitor],
meta: {}
},
{
path: "tech.hc_framework.organism.organ",
documentType: DocType.Collection,
content: [
{
name: "cell.immutable",
sourcePath: "tech.hc_framework.organism.organ.cell.immutable",
sectionType: SectionType.Content,
contentType: "text/markdown",
content: 'long spec about immutability',
},
{
name: "cell.ephemral",
sourcePath:"tech.hc_framework.organism.organ.cell.ephemral",
sectionType: SectionType.Content,
contentType: "text/markdown",
content: "",
},
],
editors: [progenitor],
meta: {}
},
{
path: "tech.hc_framework.organism.organ.dna",
documentType: DocType.Document,
Expand Down
7 changes: 6 additions & 1 deletion ui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export interface Initialization {
export type ProcessName = string
export type ProcessType = string

export interface UnitInput {
state: string,
unit: Unit,
}

export class Unit {
parents: Array<string> = []
version: string = ""
Expand Down Expand Up @@ -127,7 +132,7 @@ export class Document {
editors: Array<AgentPubKeyB64> = [] // people who can change this document, if empty anyone can
content: Array<Section> = [] // semantically identified content components
meta: Dictionary<string> = {} // semantically identified meta
state: string = "define"
state: string = SysState.UnderConstruction
marks: Array<Mark> = []
protected sectionsMap: Dictionary<number> = {}

Expand Down

0 comments on commit 26c88c6

Please sign in to comment.