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

feat: Import JS API as a module #1084

Merged
merged 8 commits into from
Feb 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
>
mofojed marked this conversation as resolved.
Show resolved Hide resolved
<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