diff --git a/package-lock.json b/package-lock.json index 1c121af..b843d09 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11838,6 +11838,7 @@ "@lit/localize": "^0.12.0", "@mdi/js": "^7.2.96", "@msgpack/msgpack": "^3.0.0-beta2", + "@scoped-elements/cytoscape": "^0.2.0", "@scoped-elements/markdown-renderer": "^0.0.3", "@shoelace-style/shoelace": "^2.15.0", "@ts-stack/markdown": "^1.5.0", diff --git a/ui/package.json b/ui/package.json index 3200497..c58be58 100644 --- a/ui/package.json +++ b/ui/package.json @@ -33,7 +33,8 @@ "sanitize-filename": "1.6.3", "automerge": "^1.0.1-preview.7", "@vanillawc/wc-codemirror": "^2.1.0", - "@gitgraph/js": "^1.4.0" + "@gitgraph/js": "^1.4.0", + "@scoped-elements/cytoscape": "^0.2.0" }, "devDependencies": { "@lightningrodlabs/we-dev-cli": "^0.10.5", diff --git a/ui/src/elements/commit-history.ts b/ui/src/elements/commit-history.ts index 0cb3ae7..46c7ce0 100644 --- a/ui/src/elements/commit-history.ts +++ b/ui/src/elements/commit-history.ts @@ -12,6 +12,10 @@ import { EntryRecord, RecordBag } from '@holochain-open-dev/utils'; import '@shoelace-style/shoelace/dist/components/card/card.js'; import '@shoelace-style/shoelace/dist/components/spinner/spinner.js'; +import '@shoelace-style/shoelace/dist/components/switch/switch.js'; +import SlSwitch from "@shoelace-style/shoelace/dist/components/switch/switch.js"; +import '@shoelace-style/shoelace/dist/components/range/range.js'; +import SlRange from "@shoelace-style/shoelace/dist/components/range/range.js"; import '@holochain-open-dev/elements/dist/elements/display-error.js'; import { Commit, DocumentStore } from '@holochain-syn/core'; @@ -20,6 +24,39 @@ import { sharedStyles } from '@holochain-open-dev/elements'; import { localized, msg, str } from '@lit/localize'; import { createGitgraph } from "@gitgraph/js"; import { Profile, ProfilesStore, profilesStoreContext } from '@holochain-open-dev/profiles'; +import '@scoped-elements/cytoscape'; + + +function getCommitGraph( + commits: RecordBag +): Array { + const elements: Array = []; + + for (const commitHash of commits.actionMap.keys()) { + const strCommitHash = encodeHashToBase64(commitHash); + elements.push({ + data: { + id: strCommitHash, + }, + }); + + for (const parentCommitHash of commits.entryRecord(commitHash)?.entry + .previous_commit_hashes || []) { + const strParentCommitHash = encodeHashToBase64(parentCommitHash); + + elements.push({ + data: { + id: `${strParentCommitHash}->${strCommitHash}`, + source: strParentCommitHash, + target: strCommitHash, + }, + }); + } + } + + return elements; +} + export const synDocumentContext = createContext>( 'syn-document-context' @@ -47,7 +84,7 @@ export class CommitHistory extends LitElement { graph: HTMLElement|undefined updated() { - if (this.graph && this._allCommits.value.status === "complete" ) { + if (!this._cytoscape && this.graph && this._allCommits.value.status === "complete" ) { const allCommits:RecordBag = new RecordBag(this._allCommits.value.value.map(er => er.record)) this.drawGraph(allCommits) } @@ -183,6 +220,11 @@ export class CommitHistory extends LitElement { async firstUpdated() { } + @state() + _cytoscape = false + + @state() + _zoom = 100 private _allCommits = new StoreSubscriber( this, @@ -193,8 +235,54 @@ export class CommitHistory extends LitElement { () => [] ); - renderContent(allCommits: RecordBag) { + onNodeSelected(nodeId: string) { + this.selectedCommitHash = nodeId; + this.dispatchEvent( + new CustomEvent('commit-selected', { + bubbles: true, + composed: true, + detail: { + commitHash: decodeHashFromBase64(nodeId), + }, + }) + ); + } + get selectedNodeIds() { + return this.selectedCommitHash ? [this.selectedCommitHash] : []; + } + + + renderContent(allCommits: RecordBag) { + if (this._cytoscape) { + const elements = getCommitGraph(allCommits); + if (elements.length === 0) + return html`
+ There are no commits yet +
`; + + return html` this.onNodeSelected(e.detail.id())} + >` + } if (Array.from(allCommits.actionMap.keys()).length === 0) return html`
There are no commits yet
`; - + return html` -
+
` } @@ -225,11 +313,24 @@ export class CommitHistory extends LitElement { return html` ${msg('Commit History')} (${this._allCommits.value.value.length} commits) - { - this.drawGraph(allCommits) + { + if (e.target) { + const s:SlSwitch = e.target as SlSwitch + this._cytoscape = s.checked + } }}> - Update - + ${this._cytoscape ? "graph" : "commits"} + + ${this._cytoscape ? "" : html` + { + if (e.target) { + const s:SlRange = e.target as SlRange + this._zoom = s.value + } + }} + > + `} ${this.renderContent(allCommits) } `; case 'error':