Skip to content

Commit

Permalink
drama-queen: eslint and prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
ddecrulle committed Sep 19, 2023
1 parent 282990b commit 64dadb2
Show file tree
Hide file tree
Showing 27 changed files with 1,430 additions and 567 deletions.
3 changes: 3 additions & 0 deletions drama-queen/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules/
.DS_Store
dist
32 changes: 32 additions & 0 deletions drama-queen/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
"eslint:recommended",
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:jsx-a11y/recommended",
"plugin:react-hooks/recommended",
"plugin:prettier/recommended" // Make sure this is always the last element in the array.
],
parser: "@typescript-eslint/parser",
parserOptions: { ecmaVersion: "latest", sourceType: "module" },
settings: { react: { version: "detect" } },
env: { browser: true, amd: true, node: true },
plugins: ["simple-import-sort", "prettier"],
rules: {
"react/react-in-jsx-scope": "off",
"jsx-a11y/accessible-emoji": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"simple-import-sort/imports": "error",
"simple-import-sort/exports": "error",
"jsx-a11y/anchor-is-valid": [
"error",
{
components: ["Link"],
specialLink: ["hrefLeft", "hrefRight"],
aspects: ["invalidHref", "preferButton"]
}
]
}
};
6 changes: 6 additions & 0 deletions drama-queen/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/node_modules/
/dist/
/.eslintrc.js
/docs/
/CHANGELOG.md
/.yarn_home
11 changes: 11 additions & 0 deletions drama-queen/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"printWidth": 105,
"tabWidth": 4,
"useTabs": false,
"semi": true,
"singleQuote": false,
"quoteProps": "preserve",
"trailingComma": "none",
"bracketSpacing": true,
"arrowParens": "avoid"
}
76 changes: 44 additions & 32 deletions drama-queen/package.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,46 @@
{
"name": "drama-queen",
"private": true,
"version": "1.4.0",
"type": "module",
"scripts": {
"dev": "vite --port 5000 --strictPort",
"build": "tsc && node scripts/generate-entrypoint.js && vite build",
"preview": "vite preview --port 5000 --strictPort",
"serve": "vite preview --port 5000 --strictPort"
},
"dependencies": {
"dexie": "^3.2.4",
"dexie-react-hooks": "^1.1.6",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.14.1"
},
"devDependencies": {
"@types/node": "^20.3.3",
"@types/react": "^18.2.14",
"@types/react-dom": "^18.2.6",
"@vitejs/plugin-react": "^4.0.1",
"ts-node": "^10.9.1",
"typescript": "^5.1.6",
"vite": "^4.3.9",
"vite-plugin-pwa": "^0.16.4",
"workbox-cacheable-response": "^5.1.3",
"workbox-core": "^5.1.3",
"workbox-precaching": "^5.1.3",
"workbox-routing": "^5.1.3",
"workbox-strategies": "^5.1.3"
}
"name": "drama-queen",
"private": true,
"version": "1.4.0",
"scripts": {
"dev": "vite --port 5000 --strictPort",
"build": "tsc && node scripts/generate-entrypoint.js && vite build",
"preview": "vite preview --port 5000 --strictPort",
"serve": "vite preview --port 5000 --strictPort",
"lint:check": "eslint ./src --ext .ts,.tsx",
"lint": "npm run lint:check -- --fix",
"_format": "prettier \"**/*.{ts,tsx,json}\"",
"format": "npm run _format -- --write",
"format:check": "npm run _format -- --list-different"
},
"dependencies": {
"dexie": "^3.2.4",
"dexie-react-hooks": "^1.1.6",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.16.0"
},
"devDependencies": {
"@types/node": "^20.3.3",
"@types/react": "^18.2.14",
"@types/react-dom": "^18.2.6",
"@typescript-eslint/eslint-plugin": "^6.7.2",
"@typescript-eslint/parser": "^6.7.2",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-import": "^2.25.4",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-simple-import-sort": "^10.0.0",
"@vitejs/plugin-react": "^4.0.1",
"ts-node": "^10.9.1",
"typescript": "^5.1.6",
"vite": "^4.3.9",
"vite-plugin-pwa": "^0.16.4",
"workbox-cacheable-response": "^7.0.0",
"workbox-core": "^7.0.0",
"workbox-precaching": "^7.0.0",
"workbox-routing": "^7.0.0",
"workbox-strategies": "^7.0.0"
}
}
31 changes: 15 additions & 16 deletions drama-queen/src/bootstrap.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
import React from "react";
import { createRoot } from "react-dom/client";
import { RouterProvider } from "react-router-dom";
import { injectLegacyEntryQueens } from "utils/injectLegacyQueens";

import { createRouter } from "./routing/router-factory";
import { RoutingStrategy } from "./routing/types";
import { injectLegacyEntryQueens } from "utils/injectLegacyQueens";

const mount = ({
mountPoint,
initialPathname,
routingStrategy,
mountPoint,
initialPathname,
routingStrategy
}: {
mountPoint: HTMLElement;
initialPathname?: string;
routingStrategy?: RoutingStrategy;
mountPoint: HTMLElement;
initialPathname?: string;
routingStrategy?: RoutingStrategy;
}) => {
console.log("Mount Drama Queen");
injectLegacyEntryQueens();

console.log("Mount Drama Queen")
injectLegacyEntryQueens();

const router = createRouter({ strategy: routingStrategy, initialPathname });
const root = createRoot(mountPoint);
root.render(<RouterProvider router={router} />);
const router = createRouter({ strategy: routingStrategy, initialPathname });
const root = createRoot(mountPoint);
root.render(<RouterProvider router={router} />);

return () => queueMicrotask(() => root.unmount());
return () => queueMicrotask(() => root.unmount());
};

export { mount };
export { mount };
9 changes: 5 additions & 4 deletions drama-queen/src/custom.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable no-unused-vars */
declare module "queen_v2/*";
declare module "queen";

declare namespace JSX {
interface IntrinsicElements {
"queen-app": any;
"queen-v2-app": any;
}
interface IntrinsicElements {
"queen-app": any;
"queen-v2-app": any;
}
}
3 changes: 2 additions & 1 deletion drama-queen/src/indexedDb/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import BaseDexie from "dexie";
import { surveyUnitSchema, type SurveyUnitTable } from "./tables/surveyUnit";

import { paradataSchema, type ParadataTable } from "./tables/paradata";
import { surveyUnitSchema, type SurveyUnitTable } from "./tables/surveyUnit";

type DexieTables = SurveyUnitTable & ParadataTable;

Expand Down
2 changes: 1 addition & 1 deletion drama-queen/src/indexedDb/tables/paradata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Table } from "dexie";
export type Paradata = { id?: number; idSu: string; events: object };

export type ParadataTable = {
paradata: Table<Paradata>;
paradata: Table<Paradata>;
};

export const paradataSchema = { paradata: "++id,idSU,events" };
16 changes: 8 additions & 8 deletions drama-queen/src/indexedDb/tables/surveyUnit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import type { Table } from "dexie";

//TODO Use Type from lunatic (import @inseefr/lunatic as devDependencies)
export type SurveyUnit = {
id: number;
data: object;
questionnaireId: string;
comment: object;
stateData: object;
personalization: object;
id: number;
data: object;
questionnaireId: string;
comment: object;
stateData: object;
personalization: object;
};

export type SurveyUnitTable = {
surveyUnit: Table<SurveyUnit>;
surveyUnit: Table<SurveyUnit>;
};

export const surveyUnitSchema = {
surveyUnit: "id,data,stateData,personalization,comment,questionnaireId",
surveyUnit: "id,data,stateData,personalization,comment,questionnaireId"
};
14 changes: 6 additions & 8 deletions drama-queen/src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import('./bootstrap').then(
({ mount }) => {
const localRoot = document.getElementById('drama-queen');
import("./bootstrap").then(({ mount }) => {
const localRoot = document.getElementById("drama-queen");

mount({
mountPoint: localRoot!,
routingStrategy: 'browser',
mountPoint: localRoot!,
routingStrategy: "browser"
});
}
);
});

export { };
export {};
41 changes: 22 additions & 19 deletions drama-queen/src/pages/env/DisplayValues.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import React from 'react'
import './env.css'
import "./env.css";

import React from "react";

export function EnvPage() {
return (
<div className="App">
<h1>Drama Queen v{APP_VERSION}</h1>
<div className="card">
<p>Les variables d'environnements</p>
<p className="read-the-docs">
{Object.entries(import.meta.env).filter(([k,]) => k.startsWith("VITE")).map(([k, v]) => (
<React.Fragment key={k}>
<b>{k}</b> : {v}<br />
</React.Fragment>
)
)}
</p>
</div>
</div >
)
};
return (
<div className="App">
<h1>Drama Queen v{APP_VERSION}</h1>
<div className="card">
<p>Les variables d&aposenvironnements</p>
<p className="read-the-docs">
{Object.entries(import.meta.env)
.filter(([k]) => k.startsWith("VITE"))
.map(([k, v]) => (
<React.Fragment key={k}>
<b>{k}</b> : {v}
<br />
</React.Fragment>
))}
</p>
</div>
</div>
);
}
30 changes: 15 additions & 15 deletions drama-queen/src/pages/queenMapping/SurveyUnitMapping.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import { db } from 'indexedDb'
import { useParams } from 'react-router-dom'
import { useLiveQuery } from "dexie-react-hooks";
import { db } from "indexedDb";
import { useParams } from "react-router-dom";
import { READ_ONLY } from "utils/constants";

type Params = {
readonly?: typeof READ_ONLY;
id: string;
}
readonly?: typeof READ_ONLY;
id: string;
};

export function SurveyUnitMapping() {
const { readonly, id } = useParams<Params>();
const { readonly, id } = useParams<Params>();

const surveyUnit = useLiveQuery(
() => db.surveyUnit.get({ id: id }), [id]
)
const surveyUnit = useLiveQuery(() => db.surveyUnit.get({ id: id }), [id]);

if (!surveyUnit) return <div>In Progress</div>
if (!surveyUnit) return <div>In Progress</div>;

//return <Navigate to={(`/queen/${readonly ? `${readonly}/` : ''}questionnaire/${surveyUnit?.questionnaireId}/survey-unit/${id}`)} />
//We know that we will reload the entire app but it's due on purpose
//Because of a faulty architecture and a queen non-modification constraint, we need to know which queen we're going to redirect to when the DramaQueen is mounted.
window.location.href = `/queen/${readonly ? `${readonly}/` : ''}questionnaire/${surveyUnit?.questionnaireId}/survey-unit/${id}`;
return null;
//return <Navigate to={(`/queen/${readonly ? `${readonly}/` : ''}questionnaire/${surveyUnit?.questionnaireId}/survey-unit/${id}`)} />
//We know that we will reload the entire app but it's due on purpose
//Because of a faulty architecture and a queen non-modification constraint, we need to know which queen we're going to redirect to when the DramaQueen is mounted.
window.location.href = `/queen/${
readonly ? `${readonly}/` : ""
}questionnaire/${surveyUnit?.questionnaireId}/survey-unit/${id}`;
return null;
}
40 changes: 22 additions & 18 deletions drama-queen/src/pages/queenMapping/VisualisationMapping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,28 @@ import { useSearchParams } from "react-router-dom";
import { isQueenV2Survey } from "utils/checkLunaticVersion/isQueenV2Survey";

export function VisualisationMapping() {
const [searchParams,] = useSearchParams();
const questionnaireUrl = searchParams.get("questionnaire")
const [isQueenV2, setIsQueenV2] = useState<boolean | undefined>(undefined);
const [isSurveyFetched, setIsSurveyFetched] = useState<boolean>(false);
const [searchParams] = useSearchParams();
const questionnaireUrl = searchParams.get("questionnaire");
const [isQueenV2, setIsQueenV2] = useState<boolean | undefined>(undefined);
const [isSurveyFetched, setIsSurveyFetched] = useState<boolean>(false);

useEffect(() => {
isQueenV2Survey(questionnaireUrl).then((r) => {
setIsQueenV2(r);
setIsSurveyFetched(true);
}).catch((e) => {
console.error("An error occured when fetching survey, by default we redirect to queen v1", e)
setIsSurveyFetched(true)
setIsQueenV2(false)
})
useEffect(() => {
isQueenV2Survey(questionnaireUrl)
.then(r => {
setIsQueenV2(r);
setIsSurveyFetched(true);
})
.catch(e => {
console.error(
"An error occured when fetching survey, by default we redirect to queen v1",
e
);
setIsSurveyFetched(true);
setIsQueenV2(false);
});
}, [questionnaireUrl]);

}, [questionnaireUrl]);
if (!isSurveyFetched) return <div>Loading</div>;

if (!isSurveyFetched) return <div>Loading</div>

return isQueenV2 ? <queen-v2-app /> : <queen-app />
}
return isQueenV2 ? <queen-v2-app /> : <queen-app />;
}
Loading

0 comments on commit 64dadb2

Please sign in to comment.