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

VYZN: Matrix Messaging Integration #455

Merged
merged 25 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3d43860
install matrix-widget-api
clecherbauer Oct 21, 2022
798f50f
bldrs to vyzn integration wip
clecherbauer Oct 20, 2022
37a733a
test out routing
clecherbauer Oct 21, 2022
5a68252
refactor code, use store instead of router
clecherbauer Oct 25, 2022
069a99c
changes for codeReview
clecherbauer Nov 5, 2022
4206e78
move WidgetApi into react context, use navigation() instead of the de…
clecherbauer Nov 8, 2022
301b66c
seperate events for selection an unselection of elements
clecherbauer Nov 11, 2022
52f3f1d
select multiple elements
clecherbauer Nov 12, 2022
bcb98a2
remove code comments
clecherbauer Nov 18, 2022
a376e72
changes from codereview
clecherbauer Nov 29, 2022
5ca7f6a
VYZN-806: Tests for Bldrs integration
Dec 16, 2022
2a7e985
Merge pull request #1 from Adrian62D/bldrs-to-vyzn
clecherbauer Dec 19, 2022
f44de2f
Merge remote-tracking branch 'origin/main' into bldrs-to-vyzn
clecherbauer Dec 21, 2022
9053e4d
fix issue after merge
clecherbauer Jan 4, 2023
51c9081
fix new linting issues after merge
clecherbauer Jan 4, 2023
2d7af8f
Merge remote-tracking branch 'origin/main' into bldrs-to-vyzn
clecherbauer Jan 4, 2023
a8ed57d
trigger preview deployment
clecherbauer Jan 6, 2023
adc8cf1
Merge remote-tracking branch 'bldrs/main' into bldrs-to-vyzn
Jan 18, 2023
b8e2267
stabilize cypress integration tests
Jan 19, 2023
c90c50f
cadview test fix
Jan 19, 2023
de92e48
Merge pull request #2 from aozien/bldrs-to-vyzn
clecherbauer Jan 19, 2023
b29368f
fix yarn lock conflict
Jan 20, 2023
a5c8c80
parameters bug fix & adding test case for it
Jan 20, 2023
dd022db
added matrix-widget-api to the lock file
Jan 21, 2023
55ec16a
Merge branch 'main' into bldrs-to-vyzn
pablo-mayrgundter Jan 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
# misc
.DS_Store
.vscode
.idea
*.log

cypress/videos
cypress/screenshots

.idea
clecherbauer marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion package.json
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bldrs",
"version": "1.0.0-r501",
"version": "1.0.0-r530",
"main": "src/index.jsx",
"homepage": "https://github.com/bldrs-ai/Share",
"bugs": {
Expand Down Expand Up @@ -34,6 +34,7 @@
"@mui/styles": "^5.9.2",
"@octokit/rest": "^19.0.3",
"clsx": "^1.2.1",
"matrix-widget-api": "^1.1.1",
"normalize.css": "^8.0.1",
"prop-types": "^15.8.1",
"react": "^18.2.0",
Expand Down
9 changes: 7 additions & 2 deletions src/BaseRoutes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {useEffect} from 'react'
import {Outlet, Route, Routes, useLocation, useNavigate} from 'react-router-dom'
import ShareRoutes from './ShareRoutes'
import debug from './utils/debug'

import useStore from './store/useStore'

/**
* From URL design: https://github.com/bldrs-ai/Share/wiki/URL-Structure
Expand All @@ -24,14 +24,19 @@ export default function BaseRoutes({testElt = null}) {
const navigation = useNavigate()
const installPrefix = window.location.pathname.startsWith('/Share') ? '/Share' : ''
const basePath = `${installPrefix }/`
const widgetApiUri = useStore((state) => state.widgetApiUri)

useEffect(() => {
if (location.pathname === installPrefix ||
location.pathname === basePath) {
debug().log('BaseRoutes#useEffect[], forwarding to: ', `${installPrefix }/share`)
navigation(`${installPrefix }/share`)
}
}, [basePath, installPrefix, location, navigation])
if (widgetApiUri) {
navigation(widgetApiUri)
}

}, [basePath, installPrefix, location, navigation, widgetApiUri])

return (
<Routes>
Expand Down
26 changes: 26 additions & 0 deletions src/WidgetApi/ApiConnection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class AbstractApiConnection {

on(event, callable) {
clecherbauer marked this conversation as resolved.
Show resolved Hide resolved
}

start() {
}

stop() {
}

missingArgumentResponse = function (argumentName) {
return {
'error': true,
'reason': `Missing argument ${argumentName}`
}
}
successfulResponse = function (data) {
return {
'error': false,
...data
}
}
}

export default AbstractApiConnection
34 changes: 34 additions & 0 deletions src/WidgetApi/ApiConnectionIframe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {WidgetApi as MatrixWidgetApi} from "matrix-widget-api/lib/WidgetApi"
import AbstractApiConnection from "./ApiConnection";

class ApiConnectionIframe extends AbstractApiConnection{
widgetId = 'bldrs-share'
matrixWidgetApi = null

constructor() {
super();
this.matrixWidgetApi = new MatrixWidgetApi(this.widgetId)
this.matrixWidgetApi.requestCapabilities([])
}

on(eventName, callable) {
this.matrixWidgetApi.on(
eventName,
(event) => {
event.preventDefault();
let response = callable(event.detail.data)
this.matrixWidgetApi.transport.reply(event.detail, response)
}
)
}

start() {
this.matrixWidgetApi.start()
}

stop() {
this.matrixWidgetApi.stop()
}
}

export default ApiConnectionIframe
51 changes: 51 additions & 0 deletions src/WidgetApi/ApiEventsRegistry.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import useStore from '../store/useStore'

const EVENT_LOAD_MODEL = 'action:ai.bldrs-share.loadModel'
const EVENT_HIGHLIGHT_ELEMENTS = 'action:ai.bldrs-share.highlightElements'

class ApiEventsRegistry {

apiConnection = null

constructor(apiConnection) {
this.apiConnection = apiConnection
this.registerEventHandlers()
}

EVENT_HANDLER_LOAD_MODEL = (data) => {
if (!('githubIfcPath' in data)) {
return this.apiConnection.missingArgumentResponse('githubIfcPath')
}
useStore.setState({ widgetApiUri: '/share/v/gh/' + data.githubIfcPath })
return this.apiConnection.successfulResponse()
}

EVENT_HANDLER_HIGHLIGHT_ELEMENTS = (data) => {
if (!('githubIfcPath' in data)) {
return this.apiConnection.missingArgumentResponse('githubIfcPath')
}
if (!('globalIds' in data)) {
return this.apiConnection.missingArgumentResponse('globalIds')
}
if (data.globalIds.length) {
useStore.setState({ widgetApiUri: '/share/v/gh/' + data.githubIfcPath + '/' + data.globalIds[0] })
} else {
useStore.setState({ widgetApiUri: '/share/v/gh/' + data.githubIfcPath })
}

return this.apiConnection.successfulResponse()
}

EVENT_HANDLER_MAP = {
[EVENT_LOAD_MODEL]: this.EVENT_HANDLER_LOAD_MODEL,
[EVENT_HIGHLIGHT_ELEMENTS]: this.EVENT_HANDLER_HIGHLIGHT_ELEMENTS
}

registerEventHandlers = () => {
for (const [eventName, callable] of Object.entries(this.EVENT_HANDLER_MAP)) {
this.apiConnection.on(eventName, callable)
}
}
}

export default ApiEventsRegistry
23 changes: 23 additions & 0 deletions src/WidgetApi/WidgetApi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import ApiConnectionIframe from "./ApiConnectionIframe";
import ApiEventsRegistry from "./ApiEventsRegistry";

class WidgetApi {
clecherbauer marked this conversation as resolved.
Show resolved Hide resolved

constructor() {
if (this.detectIframe()) {
let apiConnection = new ApiConnectionIframe()
clecherbauer marked this conversation as resolved.
Show resolved Hide resolved
new ApiEventsRegistry(apiConnection)
apiConnection.start()
}
}

detectIframe () {
try {
return window.self !== window.top;
clecherbauer marked this conversation as resolved.
Show resolved Hide resolved
} catch (e) {
return true;
}
}
}

export default WidgetApi
5 changes: 4 additions & 1 deletion src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import React from 'react'
import {createRoot} from 'react-dom/client'
import {BrowserRouter} from 'react-router-dom'
import BaseRoutes from './BaseRoutes'

import WidgetApi from "./WidgetApi/WidgetApi";

const root = createRoot(document.getElementById('root'))

new WidgetApi()
clecherbauer marked this conversation as resolved.
Show resolved Hide resolved

root.render(
<BrowserRouter>
<BaseRoutes/>
Expand Down
1 change: 1 addition & 0 deletions src/store/useStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import createRepositorySlice from './RepositorySlice'


const useStore = create((set, get) => ({
widgetApiUri: null,
clecherbauer marked this conversation as resolved.
Show resolved Hide resolved
...createIFCSlice(set, get),
...createIssuesSlice(set, get),
...createRepositorySlice(set, get),
Expand Down
13 changes: 13 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3379,6 +3379,11 @@
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.51.tgz#cfd70924a25a3fd32b218e5e420e6897e1ac4f40"
integrity sha512-CuPgU6f3eT/XgKKPqKd/gLZV1Xmvf1a2R5POBOGQa6uv82xpls89HU5zKeVoyR8XzHd1RGNOlQlvUe3CFkjWNQ==

"@types/events@^3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7"
integrity sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g==

"@types/glob@*", "@types/glob@^7.1.1":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.2.0.tgz#bc1b5bf3aa92f25bd5dd39f35c57361bdce5b2eb"
Expand Down Expand Up @@ -10049,6 +10054,14 @@ markdown-table@^3.0.0:
resolved "https://registry.yarnpkg.com/markdown-table/-/markdown-table-3.0.2.tgz#9b59eb2c1b22fe71954a65ff512887065a7bb57c"
integrity sha512-y8j3a5/DkJCmS5x4dMCQL+OR0+2EAq3DOtio1COSHsmW2BGXnNCK3v12hJt1LrUz5iZH5g0LmuYOjDdI+czghA==

matrix-widget-api@^1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/matrix-widget-api/-/matrix-widget-api-1.1.1.tgz#d3fec45033d0cbc14387a38ba92dac4dbb1be962"
integrity sha512-gNSgmgSwvOsOcWK9k2+tOhEMYBiIMwX95vMZu0JqY7apkM02xrOzUBuPRProzN8CnbIALH7e3GAhatF6QCNvtA==
dependencies:
"@types/events" "^3.0.0"
events "^3.2.0"

md5.js@^1.3.4:
version "1.3.5"
resolved "https://registry.yarnpkg.com/md5.js/-/md5.js-1.3.5.tgz#b5d07b8e3216e3e27cd728d72f70d1e6a342005f"
Expand Down