Skip to content

Commit

Permalink
feat: Import JS API as a module (#1084)
Browse files Browse the repository at this point in the history
- Pulled the types out of `jsapi-shim` into a separate pacakge
`jsapi-types`
- Now other packages can import just the types without the shim possibly
failing because the API isn't loaded yet
- Will be deprecated/replaced with the automatically published TS
definitions when @niloc132 has finished that
- Added `jsapi-bootstrap` package to load the API and display an error
if it can't load
  - Can set the API globally, or use it from a React context object
  - Displays an error if the API cannot be loaded
- Use code-splitting to bootstrap the API globally to keep existing code
running until we port everything over
- We should now look at completing #444 , and get rid of the
`embed-grid` and `embed-chart` packages. We can now code-split at the
top level.
- Enabled proxy in both embed-grid and embed-chart, keeping the loading
similar between all three apps
- Requires change deephaven/deephaven-core#2733

Breaking Change: The JS API packaged as a module is now required for the
`code-studio`, `embed-grid`, and `embed-chart` applications. Existing
(Enterprise) applications should be able to use `jsapi-shim` still and
load the JS API using the old method.
  • Loading branch information
mofojed authored Feb 12, 2023
1 parent 805bb37 commit 9aab657
Show file tree
Hide file tree
Showing 45 changed files with 1,671 additions and 1,224 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
run: npm ci --no-audit

- name: Build
run: VITE_CORE_API_URL=http://localhost:10000/jsapi npm run build
run: npm run build

- name: Install Playwright dependencies
run: PLAYWRIGHT_BROWSERS_PATH=0 npx playwright install --with-deps
Expand Down
65 changes: 65 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,10 @@
"@deephaven/grid": "file:packages/grid",
"@deephaven/icons": "file:packages/icons",
"@deephaven/iris-grid": "file:packages/iris-grid",
"@deephaven/jsapi-bootstrap": "file:packages/jsapi-bootstrap",
"@deephaven/jsapi-components": "file:packages/jsapi-components",
"@deephaven/jsapi-shim": "file:packages/jsapi-shim",
"@deephaven/jsapi-types": "file:packages/jsapi-types",
"@deephaven/jsapi-utils": "file:packages/jsapi-utils",
"@deephaven/log": "file:packages/log",
"@deephaven/mocks": "file:packages/mocks",
Expand Down
33 changes: 0 additions & 33 deletions packages/code-studio/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,7 @@
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="/manifest.json" />

<link rel="icon" href="#VITE_FAVICON#" />

<!-- The script is currently tightly coupled with the server -->
<script
src="#VITE_CORE_API_URL#/#VITE_OPEN_API_NAME#"
type="text/javascript"
></script>
<script
src="#VITE_CORE_API_URL#/#VITE_CORE_API_NAME#"
type="text/javascript"
></script>
<script>
(function () {
document.addEventListener('DOMContentLoaded', function () {
// If for some reason the API doesn't load, our app will not work. Write out a message to help the user.
if (!window.dh) {
document.getElementById('root').insertAdjacentHTML(
'afterbegin',
`<div class="modal d-block">
<div class="modal-dialog modal-dialog-centered theme-bg-light">
<div class="modal-content">
<div class="modal-body">
<h5 class="modal-title">Error: Unable to load API</h5>
<p class="text-break">Ensure the server is running and you are able to reach #VITE_CORE_API_URL#/#VITE_CORE_API_NAME#, then refresh the page.</p>
</div>
</div>
</div>
</div>`
);
}
});
})();
</script>
<title>Deephaven</title>
</head>
<body>
Expand Down
2 changes: 2 additions & 0 deletions packages/code-studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"@deephaven/grid": "file:../grid",
"@deephaven/icons": "file:../icons",
"@deephaven/iris-grid": "file:../iris-grid",
"@deephaven/jsapi-bootstrap": "file:../jsapi-bootstrap",
"@deephaven/jsapi-shim": "file:../jsapi-shim",
"@deephaven/jsapi-types": "file:../jsapi-types",
"@deephaven/jsapi-utils": "file:../jsapi-utils",
"@deephaven/log": "file:../log",
"@deephaven/pouch-storage": "file:../pouch-storage",
Expand Down
29 changes: 29 additions & 0 deletions packages/code-studio/src/AppRoot.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, { useEffect } from 'react';
import { Provider } from 'react-redux';
import { MonacoUtils } from '@deephaven/console';
import { store } from '@deephaven/redux';
import MonacoWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
import AppRouter from './main/AppRouter';
import DownloadServiceWorkerUtils from './DownloadServiceWorkerUtils';
import { unregister } from './serviceWorker';

export function AppRoot() {
useEffect(() => {
unregister();
DownloadServiceWorkerUtils.registerOnLoaded();
MonacoUtils.init({ getWorker: () => new MonacoWorker() });

// disable annoying dnd-react warnings
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window['__react-beautiful-dnd-disable-dev-warnings'] = true;
}, []);

return (
<Provider store={store}>
<AppRouter />
</Provider>
);
}

export default AppRoot;
34 changes: 15 additions & 19 deletions packages/code-studio/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
import React from 'react';
import React, { Suspense } from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import 'fira';
import '@deephaven/components/scss/BaseStyleSheet.scss';
import { MonacoUtils } from '@deephaven/console';
import { store } from '@deephaven/redux';
import MonacoWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
import AppRouter from './main/AppRouter';
import DownloadServiceWorkerUtils from './DownloadServiceWorkerUtils';
import { LoadingOverlay } from '@deephaven/components';
import { ApiBootstrap } from '@deephaven/jsapi-bootstrap';
import logInit from './log/LogInit';
import { unregister } from './serviceWorker';

logInit();

const AppRoot = React.lazy(() => import('./AppRoot'));

ReactDOM.render(
<Provider store={store}>
<AppRouter />
</Provider>,
<ApiBootstrap
apiUrl={`${import.meta.env.VITE_CORE_API_URL}/${
import.meta.env.VITE_CORE_API_NAME
}`}
setGlobally
>
<Suspense fallback={<LoadingOverlay />}>
<AppRoot />
</Suspense>
</ApiBootstrap>,
document.getElementById('root')
);
unregister();
DownloadServiceWorkerUtils.registerOnLoaded();
MonacoUtils.init({ getWorker: () => new MonacoWorker() });

// disable annoying dnd-react warnings
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
window['__react-beautiful-dnd-disable-dev-warnings'] = true;
24 changes: 12 additions & 12 deletions packages/code-studio/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,8 @@
"noEmit": true,
"emitDeclarationOnly": false
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.js",
"src/**/*.jsx"
],
"exclude": [
"node_modules",
"src/**/*.test.*",
"src/**/__mocks__/*"
],
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.js", "src/**/*.jsx"],
"exclude": ["node_modules", "src/**/*.test.*", "src/**/__mocks__/*"],
"references": [
{
"path": "../chart"
Expand Down Expand Up @@ -45,9 +36,18 @@
{
"path": "../iris-grid"
},
{
"path": "../jsapi-bootstrap"
},
{
"path": "../jsapi-shim"
},
{
"path": "../jsapi-types"
},
{
"path": "../jsapi-utils"
},
{
"path": "../log"
},
Expand All @@ -70,4 +70,4 @@
"path": "../filters"
}
]
}
}
1 change: 1 addition & 0 deletions packages/code-studio/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export default defineConfig(({ mode }) => {
outDir: path.resolve(__dirname, env.VITE_BUILD_PATH),
emptyOutDir: true,
sourcemap: true,
target: 'esnext',
rollupOptions: {
output: {
manualChunks: id => {
Expand Down
6 changes: 3 additions & 3 deletions packages/components/src/LoadingOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import LoadingSpinner from './LoadingSpinner';
import './LoadingOverlay.scss';

type LoadingOverlayProps = {
isLoaded: boolean;
isLoading: boolean;
errorMessage: string | null;
isLoaded?: boolean;
isLoading?: boolean;
errorMessage?: string | null;
'data-testid'?: string;
};

Expand Down
1 change: 0 additions & 1 deletion packages/embed-chart/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Set this value to __mocks__ to use mock server instead
VITE_CORE_API_URL=/jsapi
VITE_CORE_API_NAME=dh-core.js
VITE_OPEN_API_NAME=dh-internal.js
VITE_BUILD_PATH=./build
VITE_LOG_LEVEL=2
VITE_FAVICON=./favicon-cc-app.svg
Loading

0 comments on commit 9aab657

Please sign in to comment.