Skip to content

Commit 28ff676

Browse files
committed
Move route loaders to src/routes/loaders/ to fix Fast Refresh lint warnings
Each route file previously exported both a React component and a getLoader function, which breaks React Fast Refresh. Moving loaders to a dedicated directory means each route file exports only a component.
1 parent b00ecff commit 28ff676

11 files changed

Lines changed: 271 additions & 179 deletions

File tree

apps/nar-v3/src/main.jsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,18 @@ import ManageAccountsIcon from "@mui/icons-material/ManageAccounts";
2828
import { createTheme, ThemeProvider } from "@mui/material/styles";
2929
import { green } from "@mui/material/colors";
3030

31-
import Home, { getLoader as statsLoader } from "./routes/home";
31+
import Home from "./routes/home";
3232
import ErrorPage from "./error-page";
3333
import { initAuth, checkPermissions } from "./auth";
34-
import Datasets, { getLoader as datasetsLoader } from "./routes/datasets";
35-
import Dataset, { getLoader as datasetLoader } from "./routes/dataset";
36-
import PatchClampIndex, { getLoader as patchClampIndexLoader } from "./routes/patchClampRecordings";
37-
import PatchClamp, { getLoader as patchClampLoader } from "./routes/patchClampRecording";
34+
import Datasets from "./routes/datasets";
35+
import Dataset from "./routes/dataset";
36+
import PatchClampIndex from "./routes/patchClampRecordings";
37+
import PatchClamp from "./routes/patchClampRecording";
38+
import { getLoader as statsLoader } from "./routes/loaders/home";
39+
import { getLoader as datasetsLoader } from "./routes/loaders/datasets";
40+
import { getLoader as datasetLoader } from "./routes/loaders/dataset";
41+
import { getLoader as patchClampIndexLoader } from "./routes/loaders/patchClampRecordings";
42+
import { getLoader as patchClampLoader } from "./routes/loaders/patchClampRecording";
3843

3944
const theme = createTheme({
4045
typography: {

apps/nar-v3/src/routes/dataset.jsx

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,13 @@ limitations under the License.
1919

2020

2121
import React from "react";
22-
import { Await, defer, useLoaderData } from "react-router-dom";
22+
import { Await, useLoaderData } from "react-router-dom";
2323

24-
import { getKGItem } from "../datastore";
2524
import { uuidFromUri } from "../utility.js";
2625
import Navigation from "../components/Navigation";
2726
import DatasetCard from "../components/DatasetCard";
2827
import ProgressIndicator from "../components/ProgressIndicator";
2928

30-
import { basicDatasetQuery, patchClampDatasetQuery, techniquesQuery } from "./queryLibrary";
31-
32-
export function getLoader(auth) {
33-
const loader = async ({ params }) => {
34-
const stage = auth.isCurator ? ["IN_PROGRESS", "RELEASED"] : "RELEASED";
35-
const techniques = await getKGItem(
36-
"datasets techniques",
37-
techniquesQuery,
38-
params.datasetId,
39-
auth,
40-
stage
41-
);
42-
console.log(techniques.technique);
43-
let query = basicDatasetQuery;
44-
if (techniques.technique && techniques.technique.includes("whole cell patch clamp")) {
45-
console.log("Using patch clamp dataset query");
46-
query = patchClampDatasetQuery;
47-
} else {
48-
console.log("Using basic dataset query");
49-
}
50-
const datasetPromise = getKGItem("datasets detail", query, params.datasetId, auth, stage);
51-
console.log(datasetPromise);
52-
return defer({ dataset: datasetPromise });
53-
};
54-
return loader;
55-
}
56-
5729
function Dataset() {
5830
const data = useLoaderData();
5931

apps/nar-v3/src/routes/datasets.jsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,11 @@ limitations under the License.
2020

2121

2222
import React from "react";
23-
import { Await, defer, useLoaderData } from "react-router-dom";
23+
import { Await, useLoaderData } from "react-router-dom";
2424

25-
import { getKGData } from "../datastore";
2625
import Navigation from "../components/Navigation";
2726
import DatasetList from "../components/DatasetList";
2827
import ProgressIndicator from "../components/ProgressIndicator";
29-
import { ephysDatasetsQuery } from "./queryLibrary";
30-
31-
export function getLoader(auth) {
32-
const loader = async () => {
33-
const stage = auth.isCurator ? ["IN_PROGRESS", "RELEASED"] : "RELEASED";
34-
const datasetsPromise = getKGData("datasets summary", ephysDatasetsQuery, auth, {}, stage);
35-
console.log(datasetsPromise);
36-
return defer({ datasets: datasetsPromise });
37-
};
38-
return loader;
39-
}
4028

4129
function Datasets() {
4230
const data = useLoaderData();

apps/nar-v3/src/routes/home.jsx

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121

2222
import React from "react";
23-
import { Await, defer, useLoaderData, Link as RouterLink } from "react-router-dom";
23+
import { Await, useLoaderData, Link as RouterLink } from "react-router-dom";
2424

2525
import Card from "@mui/material/Card";
2626
import CardContent from "@mui/material/CardContent";
@@ -31,27 +31,8 @@ import Typography from "@mui/material/Typography";
3131
import Container from "@mui/material/Container";
3232
import Chip from "@mui/material/Chip";
3333

34-
import { count } from "../datastore";
35-
import { query as patchClampRecordingsQuery } from "./patchClampRecordings";
36-
import { ephysDatasetsQuery } from "./queryLibrary";
3734
import ProgressIndicator from "../components/ProgressIndicator";
3835

39-
export function getLoader(auth) {
40-
const loader = async () => {
41-
let stage = "RELEASED";
42-
if (auth.isCurator) {
43-
stage = "IN_PROGRESS";
44-
}
45-
const statisticsPromise = Promise.all([
46-
count(patchClampRecordingsQuery, auth, {}, stage),
47-
count(ephysDatasetsQuery, auth, {}, stage),
48-
]);
49-
console.log(statisticsPromise);
50-
return defer({ counts: statisticsPromise });
51-
};
52-
return loader;
53-
}
54-
5536
// function getModalityCount(modality) {
5637
// console.log(modality);
5738
// if (modality === "patchclamp") {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
Copyright 2024 Andrew P. Davison, CNRS
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { defer } from "react-router-dom";
18+
19+
import { getKGItem } from "../../datastore";
20+
import { basicDatasetQuery, patchClampDatasetQuery, techniquesQuery } from "../queryLibrary";
21+
22+
export function getLoader(auth) {
23+
const loader = async ({ params }) => {
24+
const stage = auth.isCurator ? ["IN_PROGRESS", "RELEASED"] : "RELEASED";
25+
const techniques = await getKGItem(
26+
"datasets techniques",
27+
techniquesQuery,
28+
params.datasetId,
29+
auth,
30+
stage
31+
);
32+
console.log(techniques.technique);
33+
let query = basicDatasetQuery;
34+
if (techniques.technique && techniques.technique.includes("whole cell patch clamp")) {
35+
console.log("Using patch clamp dataset query");
36+
query = patchClampDatasetQuery;
37+
} else {
38+
console.log("Using basic dataset query");
39+
}
40+
const datasetPromise = getKGItem("datasets detail", query, params.datasetId, auth, stage);
41+
console.log(datasetPromise);
42+
return defer({ dataset: datasetPromise });
43+
};
44+
return loader;
45+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Copyright 2024 Andrew P. Davison, CNRS
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { defer } from "react-router-dom";
18+
19+
import { getKGData } from "../../datastore";
20+
import { ephysDatasetsQuery } from "../queryLibrary";
21+
22+
export function getLoader(auth) {
23+
const loader = async () => {
24+
const stage = auth.isCurator ? ["IN_PROGRESS", "RELEASED"] : "RELEASED";
25+
const datasetsPromise = getKGData("datasets summary", ephysDatasetsQuery, auth, {}, stage);
26+
console.log(datasetsPromise);
27+
return defer({ datasets: datasetsPromise });
28+
};
29+
return loader;
30+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright 2024 Andrew P. Davison, CNRS
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { defer } from "react-router-dom";
18+
19+
import { count } from "../../datastore";
20+
import { query as patchClampRecordingsQuery } from "./patchClampRecordings";
21+
import { ephysDatasetsQuery } from "../queryLibrary";
22+
23+
export function getLoader(auth) {
24+
const loader = async () => {
25+
let stage = "RELEASED";
26+
if (auth.isCurator) {
27+
stage = "IN_PROGRESS";
28+
}
29+
const statisticsPromise = Promise.all([
30+
count(patchClampRecordingsQuery, auth, {}, stage),
31+
count(ephysDatasetsQuery, auth, {}, stage),
32+
]);
33+
console.log(statisticsPromise);
34+
return defer({ counts: statisticsPromise });
35+
};
36+
return loader;
37+
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
Copyright 2024 Andrew P. Davison, CNRS
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { defer } from "react-router-dom";
18+
19+
import {
20+
buildKGQuery,
21+
simpleProperty as S,
22+
linkProperty as L,
23+
reverseLinkProperty as R,
24+
} from "../../queries";
25+
import { getKGItem } from "../../datastore";
26+
27+
const query = buildKGQuery("TissueSample", [
28+
S("@id"),
29+
S("lookupLabel"),
30+
L("anatomicalLocation", [S("name"), S("@type")], { expectSingle: false }),
31+
L("biologicalSex/name"),
32+
L("laterality/name"),
33+
L("origin", [S("name"), S("@type")]),
34+
L("species", [
35+
S("name"),
36+
S("@type"),
37+
R("species", "species", [S("name")], { type: "core/Strain" }),
38+
]),
39+
L("strain/name"),
40+
L("type/name"),
41+
L(
42+
"studiedState",
43+
[
44+
S("lookupLabel"),
45+
L("descendedFrom", [
46+
S("lookupLabel"),
47+
S("@type"),
48+
R("isStateOf", "studiedState", [S("lookupLabel"), S("@id"), L("type/name")]),
49+
]),
50+
L("age", [
51+
S("value"),
52+
S("uncertainty"),
53+
S("minValue"),
54+
S("maxValue"),
55+
L("unit/name"),
56+
L("minValueUnit/name"),
57+
L("maxValueUnit/name"),
58+
]),
59+
L("attribute", [S("name"), S("@type")], { expectSingle: false }),
60+
S("additionalRemarks"),
61+
L("pathology", [S("name"), S("@type")], { expectSingle: false }),
62+
],
63+
{ expectSingle: false }
64+
),
65+
R(
66+
"belongsToDataset",
67+
"studiedSpecimen",
68+
[
69+
S("fullName"),
70+
S("shortName"),
71+
S("@id"),
72+
L("technique/name", [], { filter: "patch clamp", expectSingle: false, required: true }),
73+
L("accessibility/name", [], { filter: "free access", required: true }),
74+
R("isVersionOf", "hasVersion", [S("shortName"), S("fullName")]),
75+
],
76+
{ required: true }
77+
),
78+
]);
79+
80+
export function getLoader(auth) {
81+
const loader = async ({ params }) => {
82+
const stage = auth.isCurator ? ["IN_PROGRESS", "RELEASED"] : "RELEASED";
83+
const tissueSamplePromise = getKGItem(
84+
"patch clamp recordings detail",
85+
query,
86+
params.expId,
87+
auth,
88+
stage
89+
);
90+
console.log(tissueSamplePromise);
91+
return defer({ tissueSample: tissueSamplePromise });
92+
};
93+
return loader;
94+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Copyright 2024 Andrew P. Davison, CNRS
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import { defer } from "react-router-dom";
18+
19+
import {
20+
buildKGQuery,
21+
simpleProperty as S,
22+
linkProperty as L,
23+
reverseLinkProperty as R,
24+
} from "../../queries";
25+
import { getKGData } from "../../datastore";
26+
27+
export const query = buildKGQuery("TissueSample", [
28+
S("@id"),
29+
S("lookupLabel", { sort: true }),
30+
R(
31+
"belongsToDataset",
32+
"studiedSpecimen",
33+
[
34+
L("accessibility/name", [], { filter: "free access", required: true }),
35+
L("technique/name", [], { filter: "patch clamp", expectSingle: false, required: true }),
36+
],
37+
{ required: true }
38+
),
39+
]);
40+
41+
export function getLoader(auth) {
42+
const loader = async () => {
43+
const stage = auth.isCurator ? ["IN_PROGRESS", "RELEASED"] : "RELEASED";
44+
const tissueSamplesPromise = getKGData("patch clamp recordings summary", query, auth, {}, stage);
45+
46+
console.log(tissueSamplesPromise);
47+
return defer({ tissueSamples: tissueSamplesPromise });
48+
};
49+
return loader;
50+
}

0 commit comments

Comments
 (0)