Skip to content

Commit

Permalink
fix(dashboard): nouveau DataLoader (#1692)
Browse files Browse the repository at this point in the history
* fix(dashboard): nouveau DataLoader

* fix: sorting when necessary

* add logs

* fix: recoil default

* fix: clean

* fix: need to initiate default recoil values before setting new values

* fix: test

* fix: restricted roles

* fix: move API.get({ path: /now });

* fix and cleans

* fix: clean

* fix: remove data.length check

* fix: return from data migrator

* fix: setFullScreen(isStartingInitialLoad)
  • Loading branch information
arnaudambro authored Oct 10, 2023
1 parent 3362028 commit fa8c753
Show file tree
Hide file tree
Showing 22 changed files with 542 additions and 477 deletions.
22 changes: 10 additions & 12 deletions api/src/controllers/organisation.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ router.get(
passport.authenticate("user", { session: false }),
validateUser(["superadmin", "admin", "normal", "restricted-access"]),
catchErrors(async (req, res, next) => {
const startLoadingDate = Date.now();

try {
z.object({
organisation: z.string().regex(looseUuidRegex),
Expand Down Expand Up @@ -77,28 +75,28 @@ router.get(
// Medical data is never saved in cache so we always have to download all at every page reload.
// In other words "after" param is intentionnaly ignored for consultations, treatments and medical files.
const medicalDataQuery =
withAllMedicalData !== "true" ? query : { where: { organisation: req.query.organisation }, paranoid: withDeleted === "true" };
withAllMedicalData !== "true" ? query : { where: { organisation: req.query.organisation }, paranoid: withDeleted === "true" ? false : true };
const consultations = await Consultation.count(medicalDataQuery);
const medicalFiles = await MedicalFile.count(medicalDataQuery);
const treatments = await Treatment.count(medicalDataQuery);

return res.status(200).send({
ok: true,
data: {
actions,
consultations,
treatments,
comments,
passages,
rencontres,
medicalFiles,
persons,
groups,
reports,
passages,
rencontres,
actions,
territories,
places,
relsPersonPlace,
territories,
territoryObservations,
reports,
comments,
consultations,
treatments,
medicalFiles,
},
});
})
Expand Down
17 changes: 11 additions & 6 deletions dashboard/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import ScrollToTop from './components/ScrollToTop';
import TopBar from './components/TopBar';
import VersionOutdatedAlert from './components/VersionOutdatedAlert';
import ModalConfirm from './components/ModalConfirm';
import DataLoader, { initialLoadingTextState, loadingTextState, useDataLoader } from './components/DataLoader';
import DataLoader, { initialLoadIsDoneState, useDataLoader } from './components/DataLoader';
import { Bounce, cssTransition, ToastContainer } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';
import SentryRoute from './components/Sentryroute';
Expand Down Expand Up @@ -90,7 +90,7 @@ if (ENV === 'production') {
const App = ({ resetRecoil }) => {
const authToken = useRecoilValue(authTokenState);
const user = useRecoilValue(userState);
const loadingText = useRecoilValue(loadingTextState);
const initialLoadIsDone = useRecoilValue(initialLoadIsDoneState);

const recoilResetKey = useRecoilValue(recoilResetKeyState);
useEffect(() => {
Expand All @@ -106,7 +106,7 @@ const App = ({ resetRecoil }) => {
if (authToken && e.newState === 'active') {
API.get({ path: '/check-auth' }) // will force logout if session is expired
.then(() => {
if (loadingText !== initialLoadingTextState) {
if (initialLoadIsDone) {
// if the app is already loaded
// will refresh data if session is still valid
refresh();
Expand All @@ -120,7 +120,7 @@ const App = ({ resetRecoil }) => {
return () => {
lifecycle.removeEventListener('statechange', onWindowFocus);
};
}, [authToken, refresh, loadingText]);
}, [authToken, refresh, initialLoadIsDone]);

return (
<div className="main-container">
Expand Down Expand Up @@ -195,8 +195,13 @@ export default function ContextedApp() {
const [recoilKey, setRecoilKey] = useState(0);
return (
<RecoilRoot key={recoilKey}>
<RecoilNexus />
<App resetRecoil={() => setRecoilKey((k) => k + 1)} />
{/* We need React.Suspense here because default values for `person`, `action` etc. tables is an async cache request */}
{/* https://recoiljs.org/docs/guides/asynchronous-data-queries#query-default-atom-values */}
<React.Suspense fallback={<div></div>}>
{/* Recoil Nexus allows to use Recoil state outside React tree */}
<RecoilNexus />
<App resetRecoil={() => setRecoilKey((k) => k + 1)} />
</React.Suspense>
</RecoilRoot>
);
}
4 changes: 3 additions & 1 deletion dashboard/src/components/ActionModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,9 @@ function ActionContent({ onClose, action, personId = null, personIds = null, isM
.filter(Boolean)
.join(' ')}>
<CommentsModule
comments={action?.comments.map((comment) => ({ ...comment, type: 'action', person: action.person }))}
comments={action?.comments
.map((comment) => ({ ...comment, type: 'action', person: action.person }))
.sort((a, b) => new Date(b.date || b.createdAt) - new Date(a.date || a.createdAt))}
color="main"
canToggleUrgentCheck
typeForNewComment="action"
Expand Down
Loading

0 comments on commit fa8c753

Please sign in to comment.