Skip to content

Commit

Permalink
refactor(ui): better naming and messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Anis SMAIL committed Dec 3, 2024
1 parent bafac72 commit f546844
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 31 deletions.
2 changes: 1 addition & 1 deletion webapp/public/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@
"studies.filters.strictfolder": "Show only direct folder children",
"studies.filters.showAllDescendants": "Show all children",
"studies.scanFolder": "Scan folder",
"studies.requestDeepScan": "Scan the folder recursively (may be long) ?",
"studies.requestDeepScan": "Recursive scan",
"studies.moveStudy": "Move",
"studies.movefolderplaceholder": "Path separated by '/'",
"studies.importcopy": "Copy to database",
Expand Down
4 changes: 2 additions & 2 deletions webapp/public/locales/fr/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -636,9 +636,9 @@
"studies.copySuffix": "Copie",
"studies.folder": "Dossier",
"studies.filters.strictfolder": "Afficher uniquement les descendants directs",
"studies.filters.showAllDescendants": "Afficher tous les descendants",
"studies.filters.showAllDescendants": "Voir les sous-dossiers",
"studies.scanFolder": "Scanner le dossier",
"studies.requestDeepScan": "Scanner le dossier récursivement (ça peut être long) ?",
"studies.requestDeepScan": "Scan récursif",
"studies.moveStudy": "Déplacer",
"studies.movefolderplaceholder": "Chemin séparé par des '/'",
"studies.importcopy": "Copier en base",
Expand Down
16 changes: 8 additions & 8 deletions webapp/src/components/App/Studies/StudiesList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function StudiesList(props: StudiesListProps) {
const [selectedStudies, setSelectedStudies] = useState<string[]>([]);
const [selectionMode, setSelectionMode] = useState(false);
const [confirmFolderScan, setConfirmFolderScan] = useState<boolean>(false);
const [requestDeepScan, setRequestDeepScan] = useState<boolean>(false);
const [isRecursiveScan, setIsRecursiveScan] = useState<boolean>(false);

useEffect(() => {
setFolderList(folder.split("/"));
Expand Down Expand Up @@ -163,16 +163,16 @@ function StudiesList(props: StudiesListProps) {
try {
// Remove "/root" from the path
const folder = folderList.slice(1).join("/");
await scanFolder(folder, requestDeepScan);
await scanFolder(folder, isRecursiveScan);
setConfirmFolderScan(false);
setRequestDeepScan(false);
setIsRecursiveScan(false);
} catch (e) {
enqueueErrorSnackbar(t("studies.error.scanFolder"), e as AxiosError);
}
};

const handleDeepScanCheckboxChange = () => {
setRequestDeepScan(!requestDeepScan);
const handleRecursiveScan = () => {
setIsRecursiveScan(!isRecursiveScan);
};

////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -288,17 +288,17 @@ function StudiesList(props: StudiesListProps) {
titleIcon={RadarIcon}
onCancel={() => {
setConfirmFolderScan(false);
setRequestDeepScan(false);
setIsRecursiveScan(false);
}}
onConfirm={handleFolderScan}
alert="warning"
open
>
{`${t("studies.scanFolder")} ${folder}?`}
<FormControlLabel
control={<Checkbox checked={requestDeepScan} />}
control={<Checkbox checked={isRecursiveScan} />}
label={t("studies.requestDeepScan")}
onChange={handleDeepScanCheckboxChange}
onChange={handleRecursiveScan}
/>{" "}
</ConfirmationDialog>
)}
Expand Down
46 changes: 26 additions & 20 deletions webapp/src/components/App/Studies/StudyTree/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import useEnqueueErrorSnackbar from "@/hooks/useEnqueueErrorSnackbar";
import useUpdateEffectOnce from "@/hooks/useUpdateEffectOnce";
import { fetchAndInsertSubfolders, fetchAndInsertWorkspaces } from "./utils";
import { useTranslation } from "react-i18next";
import { AxiosError } from "axios";

function StudyTree() {
const initialStudiesTree = useAppSelector(getStudiesTree);
Expand Down Expand Up @@ -63,7 +64,7 @@ function StudyTree() {
setStudiesTree(initialStudiesTree);
enqueueErrorSnackbar(
t("studies.tree.error.failToFetchWorkspace"),
t("studies.tree.error.detailsInConsole"),
error as AxiosError,
);
}
};
Expand All @@ -75,36 +76,41 @@ function StudyTree() {
// Event Handlers
////////////////////////////////////////////////////////////////

const handleTreeItemClick = (
const handleTreeItemClick = async (
itemId: string,
studyTreeNode: StudyTreeNode,
) => {
dispatch(updateStudyFilters({ folder: itemId }));
if (itemId === "root") {
fetchAndInsertWorkspaces(studiesTree)
.then(setStudiesTree)
.catch((error) => {
enqueueErrorSnackbar("Failed to load list workspaces", error);
});
try {
const nextTree = await fetchAndInsertWorkspaces(studiesTree);
setStudiesTree(nextTree);
} catch (error) {
enqueueErrorSnackbar(
"studies.tree.error.failToFetchWorkspace",
error as AxiosError,
);
}
}
const chidrenPaths = studyTreeNode.children.map(
(child) => `root${child.path}`,
);
// children paths and current element path
fetchAndInsertSubfolders(chidrenPaths, studiesTree).then((r) => {
setStudiesTree(r[0]);
for (const path of r[1]) {
enqueueErrorSnackbar(
t("studies.tree.error.failToFetchFolder", {
path,
interpolation: { escapeValue: false },
}),
t("studies.tree.error.detailsInConsole"),
);
}
});
const [nextTree, failedPath] = await fetchAndInsertSubfolders(
chidrenPaths,
studiesTree,
);
setStudiesTree(nextTree);
for (const path of failedPath) {
enqueueErrorSnackbar(
t("studies.tree.error.failToFetchFolder", {
path,
interpolation: { escapeValue: false },
}),
t("studies.tree.error.detailsInConsole"),
);
}
};

////////////////////////////////////////////////////////////////
// JSX
////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit f546844

Please sign in to comment.