Skip to content

Commit

Permalink
Merge pull request #91 from InseeFr/fix/multiple-issues
Browse files Browse the repository at this point in the history
fix: solve multiple issue
  • Loading branch information
PierreVasseur authored Oct 23, 2024
2 parents c23c726 + 84a683d commit 4106284
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions public/configuration.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
11 changes: 9 additions & 2 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function Editor({ endpoint, queries, prefix }) {
const [yasgui, setYasgui] = useState();
const [counter, setCounter] = useState(0);
const ref = useRef(null);
const editorRef = useRef(null);

const [inserted, setInserted] = useState(false);

Expand All @@ -33,10 +34,15 @@ function Editor({ endpoint, queries, prefix }) {
};

useLayoutEffect(() => {
if (editorRef.current.getAttribute("data-yasgui") === "true") {
return;
}

localStorage.removeItem("yagui__config");
editorRef.current.setAttribute("data-yasgui", "true");
setYasgui(
// eslint-disable-next-line no-undef
new Yasgui(document.getElementById("editor"), {
new Yasgui(editorRef.current, {
requestConfig: {
endpoint
}
Expand All @@ -48,14 +54,15 @@ function Editor({ endpoint, queries, prefix }) {
<>
<div className="queries-block" ref={ref}>
{queries.map((query, i) => (
<button key={i} onClick={() => click(query)}>
<button type="button" key={i} onClick={() => click(query)}>
{" "}
{query.label}{" "}
</button>
))}
</div>
<div
id="editor"
ref={editorRef}
onClick={e => {
if (
endpoint !== defaultEndpoint &&
Expand Down
32 changes: 29 additions & 3 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react-swc";
import { configDefaults } from "vitest/config";
import { readFileSync } from "fs";
import { resolve } from "path";

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -19,6 +21,30 @@ export default defineConfig({
outDir: "temp_dist"
},
server: {
port: 3000
port: 3000,
proxy: {
"/queries/queries.json": {
bypass: function (req, res) {
res.setHeader("Content-Type", "application/json");
res.end(
readFileSync(
resolve(import.meta.dirname, "pages/queries/queries.json")
).toString()
);
return false;
}
},
"^/queries/.*.txt": {
bypass: function (req, res) {
res.setHeader("Content-Type", "application/json");
res.end(
readFileSync(
resolve(import.meta.dirname, "pages/", req.url!.replace("/", ""))
).toString()
);
return false;
}
}
}
}
});

0 comments on commit 4106284

Please sign in to comment.