Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: add dev mode for app #583

Merged
merged 3 commits into from
Jun 27, 2024
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
8 changes: 6 additions & 2 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@
<div id="pygwalker-app"></div>
<script type="module">
import PyGWalkerApp from './src/index';
PyGWalkerApp.GWalker({}, "pygwalker-app");
window.addEventListener('message', function(event) {
if (event.data.type == "pyg_props") {
PyGWalkerApp.GWalker(event.data.data, "pygwalker-app");
}
}, false);
</script>
</body>
</html>
</html>
4 changes: 2 additions & 2 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build:app": "vite build",
"dev:preinstall": "(cd ../graphic-walker/packages/graphic-walker; yarn --frozen-lockfile && yarn build)",
"dev:server": "vite --host",
"dev": "vite build --mode=develop",
"dev": "vite",
"test:front_end": "vite --host",
"test": "npm run test:front_end",
"serve": "vite preview"
Expand Down Expand Up @@ -60,7 +60,7 @@
"@types/styled-components": "^5.1.26",
"@vitejs/plugin-react": "^3.1.x",
"typescript": "^5.4.2",
"vite": "^4.1.4",
"vite": "4.1.5",
"vite-plugin-wasm": "^3.2.2"
},
"resolutions": {
Expand Down
20 changes: 11 additions & 9 deletions app/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { observer } from "mobx-react-lite";
import { autorun } from "mobx"
import { GraphicWalker, PureRenderer, GraphicRenderer, TableWalker } from '@kanaries/graphic-walker'
import type { VizSpecStore } from '@kanaries/graphic-walker/store/visualSpecStore'
import type { IGWHandler, IViewField, ISegmentKey, IDarkMode, IChatMessage } from '@kanaries/graphic-walker/interfaces';
import type { IGWHandler, IViewField, ISegmentKey, IDarkMode, IChatMessage, IRow } from '@kanaries/graphic-walker/interfaces';
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";

import Options from './components/options';
Expand All @@ -29,6 +29,7 @@ import { formatExportedChartDatas } from "./utils/save";
import { tracker } from "@/utils/tracker";
import Notification from "./notify"
import initDslParser from "@kanaries/gw-dsl-parser";
import wasmPath from "@kanaries/gw-dsl-parser/gw_dsl_parser_bg.wasm?url";
import {
Select,
SelectContent,
Expand Down Expand Up @@ -306,7 +307,7 @@ const initOnJupyter = async(props: IAppProps) => {
if (props.needLoadDatas) {
comm.sendMsgAsync("request_data", {}, null);
}
await initDslParser();
await initDslParser(wasmPath);
}

const initOnHttpCommunication = async(props: IAppProps) => {
Expand All @@ -316,18 +317,19 @@ const initOnHttpCommunication = async(props: IAppProps) => {
const visSpecResp = await comm.sendMsg("get_latest_vis_spec", {});
props.visSpec = visSpecResp["data"]["visSpec"];
}
await initDslParser();
await initDslParser(wasmPath);
}

const defaultInit = async(props: IAppProps) => {}

function GWalkerComponent(props: IAppProps) {
const [initChartFlag, setInitChartFlag] = useState(false);
const [dataSource, setDataSource] = useState<IRow[]>(props.dataSource);

useEffect(() => {
if (props.needLoadDatas) {
loadDataSource(props.dataSourceProps).then((data) => {
props.dataSource = data;
setDataSource(data);
setInitChartFlag(true);
commonStore.setInitModalOpen(false);
})
Expand All @@ -338,15 +340,15 @@ function GWalkerComponent(props: IAppProps) {

switch(props.gwMode) {
case "explore":
return <ExploreApp {...props} initChartFlag={initChartFlag} />;
return <ExploreApp {...props} dataSource={dataSource} initChartFlag={initChartFlag} />;
case "renderer":
return <PureRednererApp {...props} />;
return <PureRednererApp {...props} dataSource={dataSource} />;
case "filter_renderer":
return <GraphicRendererApp {...props} />;
return <GraphicRendererApp {...props} dataSource={dataSource} />;
case "table":
return <TableWalkerApp {...props} />;
return <TableWalkerApp {...props} dataSource={dataSource} />;
default:
return<ExploreApp {...props} initChartFlag={initChartFlag} />
return<ExploreApp {...props} dataSource={dataSource} initChartFlag={initChartFlag} />
}
}

Expand Down
19 changes: 15 additions & 4 deletions app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ const modulesNotToBundle = Object.keys(peerDependencies);

// https://vitejs.dev/config/
export default defineConfig((config: ConfigEnv) => {
console.log("defineConfig: ", config);

const buildConfigMap = {
"production": {
lib: {
Expand Down Expand Up @@ -50,8 +48,9 @@ export default defineConfig((config: ConfigEnv) => {
}

return {
base: "/pyg_dev_app/",
server: {
port: 2002,
port: 8769,
},
plugins: [
react(),
Expand All @@ -73,6 +72,18 @@ export default defineConfig((config: ConfigEnv) => {
"@": path.resolve(__dirname, "./src"),
},
},
build: buildConfigMap[config.mode]
build: {
...buildConfigMap[config.mode],
rollupOptions: {
external: modulesNotToBundle,
output: {
globals: {
'react': 'React',
'react-dom': 'ReactDOM',
'styled-components': 'styled',
},
},
},
}
} as UserConfig;
})
Loading
Loading