Skip to content

Commit

Permalink
188131728 v3 DI Url Parameter (#1419)
Browse files Browse the repository at this point in the history
* Add plugin when specified in di url parameter.
  • Loading branch information
tealefristoe authored Aug 21, 2024
1 parent 9717bba commit 932689d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 8 additions & 2 deletions v3/cypress/e2e/plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ context("codap plugins", () => {
const url = `${Cypress.config("index")}?sample=mammals&dashboard`
cy.visit(url)
})
const apiTesterUrl='https://concord-consortium.github.io/codap-data-interactives/DataInteractiveAPITester/index.html?lang=en'
const openAPITester = () => {
const url='https://concord-consortium.github.io/codap-data-interactives/DataInteractiveAPITester/index.html?lang=en'
toolbar.getOptionsButton().click()
toolbar.getWebViewButton().click()
webView.enterUrl(url)
webView.enterUrl(apiTesterUrl)
cy.wait(1000)
}

it('will open plugin specified in url parameter', () => {
const url = `${Cypress.config("index")}?di=${apiTesterUrl}`
cy.visit(url)
webView.getTitle().should("contain.text", "CODAP API Tester")
})

it('will handle plugin requests', () => {
openAPITester()

Expand Down
13 changes: 13 additions & 0 deletions v3/src/components/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ export const App = observer(function App() {
addDefaultComponents()
}
}

const { di } = urlParams
if (typeof di === "string") {
// setTimeout ensures that other components have been rendered,
// which is necessary to properly position the plugin.
setTimeout(() => {
appState.document.content?.applyModelChange(() => {
const plugin = appState.document.content?.createTile?.(kWebViewTileType)
if (isWebViewModel(plugin?.content)) plugin.content.setUrl(di)
})
})
}

appState.enableUndoRedoMonitoring()
Logger.initializeLogger(appState.document)
}
Expand Down

0 comments on commit 932689d

Please sign in to comment.