Conversation
…ataset management
… state management
…aset management and job polling
…dataset and notebook management
… notebook management
…s directory and remove unused hooks for improved code structure and maintainability
…ed LeftPanel, CenterPanel, and RightPanel components for improved UI structure and maintainability
…tructure, moving SideBar and CenterBox to panelContainers, and implement DatasetsCenterContent for improved layout management and maintainability
…rect path for improved module organization
…oning in DatasetsContent
…rove code readability
…or improved functionality and code clarity
…hared states of dataset page
…nd streamline component interactions
…ate management and update related components for improved functionality
…Bar and removing redundant code from DatasetsContent
…otebook deletion logic and improve component interactions
…tebookEdit prop with editNotebook function for improved code clarity
…NotebookClick function in DatasetsNotebooksLeftBar and remove redundant notebook click handling from DatasetsContent for improved code organization
…ent handleNewSessionButton and handleNotebookCreated functions, removing redundant logic from DatasetsContent for improved code clarity and organization
…otebookFromDataset function to DatasetsCenterContent, removing it from DatasetsContent for improved code organization
…dDatasetFromNotebook prop, improving code clarity and organization by utilizing context for dataset creation
…ity and organization
…mproving code clarity and reducing redundancy
DashAI/front/src/components/notebooks/dataset/DatasetsCenterContent.jsx
Outdated
Show resolved
Hide resolved
| const resetUI = useCallback(() => { | ||
| setStep(0); | ||
| setSelectedOption(null); | ||
| }, []); | ||
|
|
||
| const goToDatasetFlow = useCallback(() => { | ||
| setStep(1); | ||
| setSelectedOption("dataset"); | ||
| }, []); | ||
|
|
||
| const goToNotebookFlow = useCallback(() => { | ||
| setStep(1); | ||
| setSelectedOption("notebook"); | ||
| }, []); |
There was a problem hiding this comment.
These useCallback hooks are not doing anything.
There was a problem hiding this comment.
These useCallbacks improve the performance of the component avoiding redefining the funcion every render.
Anyways I did a small refactor beacause defining all this funcions is not necesary.
const goToNextStep = useCallback(
(option) => {
if (option === "dataset") {
setStep(1);
setSelectedOption("dataset");
} else {
setStep(1);
setSelectedOption("notebook");
}
clearSelectedDataset();
clearSelectedNotebook();
if (option === "dataset" && tourContext?.run) {
setTimeout(() => {
tourContext.nextStep();
}, 600);
}
},
[tourContext],
);| setSelectedDatasetId(null); | ||
| } | ||
| await deleteDataset(id); | ||
| }; |
There was a problem hiding this comment.
You should try to delete it from the server first. If it returns a 204, 200, or 202 HTTP status code, then delete it from the local list.
There was a problem hiding this comment.
I fix it.
const deleteDatasetById = async (id) => {
try {
await deleteDataset(id);
setDatasets((prev) => prev.filter((d) => d.id !== id));
if (id === selectedDatasetId) {
setSelectedDatasetId(null);
}
return true;
} catch (error) {
enqueueSnackbar(t("datasets:error.failedToDeleteDataset"), {
variant: "error",
});
console.error("Error deleting dataset:", error);
}
return false;
};Cheking the exact status code is not necesary, beacause if it fails it will raise an exception.
| const deleteNotebookById = async (id) => { | ||
| setNotebooks((prev) => prev.filter((n) => n.id !== id)); | ||
| await deleteNotebook(id); | ||
| }; |
There was a problem hiding this comment.
You should try to delete it from the server first, and if it succeeds, delete it locally.
There was a problem hiding this comment.
I did the same changes that in deleteDatasetById.
const deleteNotebookById = async (id) => {
try{
await deleteNotebook(id);
setNotebooks((prev) => prev.filter((n) => n.id !== id));
return true;
} catch (error) {
enqueueSnackbar(t("datasets:error.failedToDeleteNotebook"), {
variant: "error",
});
console.error("Error deleting notebook:", error);
}
return false;
};…ation hook directly, improving code clarity and organization
…olidating step transitions and removing redundant functions, enhancing code clarity and maintainability
…edback, updating related translations for consistency
…proving code clarity
…eedback, adding translations for failure messages
…mponents, improving code consistency and clarity
…larations and improve code clarity
…ndling and ensure consistent state checks
…y in item handling
…d prop and streamline existing props for clarity
…ogic and enhance processing state handling
Summary
This PR refactors the
DatasetsContent.jsxmodule, which had grown in complexity by mixing business logic, state management, and UI rendering in a single file. The refactor aims to improve code readability, maintainability, and scalability by separating concerns, extracting reusable and specific components, and preparing the codebase for future extensions and performance improvements.Type of Change
Check all that apply like this [x]:
Changes (by file)
src/pages/datasets/DatasetsContent.jsx: Refactored to delegate business logic and UI state to specialized hooks, and to use new reusable layout components for a three-panel structure. Central render logic is now encapsulated in a dedicated subcomponent.src/components/threeSectionLayout/panels/LeftPanel.jsx: Reusable left sidebar panel with show/hide and resize logic, using context for state.src/components/threeSectionLayout/panels/RightPanel.jsx: Fully generic right sidebar panel, with customizable toggle button position via thetoggleButtonTopprop, and context-driven state.src/components/threeSectionLayout/panels/CenterPanel.jsx: Central panel that dynamically adjusts its width based on the state of the side panels.src/components/notebooks/dataset/DatasetsCenterContent.jsx: New subcomponent that encapsulates all conditional rendering logic for the central panel, improving modularity and readability.src/context/DatasetsAndNotebooksContext.jsx: Introduces a centralized Context Provider that exposes shared state and high-level operations for datasets and notebooks, eliminating prop drilling across the three-panel layout. The provider coordinates data access while delegating entity-specific business logic to dedicated hooks, resulting in a cleaner and more maintainable architecture.src/hooks/datasets/useDatasets.js: Encapsulates all logic related to the Dataset entity (state, lifecycle, CRUD, polling, metadata enrichment).src/hooks/datasets/useNotebooks.js: Manages state and operations for the Notebook entity, including its relationship with datasets.Testing (optional)
Notes (optional)
In summary, this refactor contains:
1) Datasets Module Hook Architecture
The Datasets module is now structured using multiple specialized hooks, each with a clearly defined responsibility. This reduces coupling, improves maintainability, and allows each part of the system to evolve independently.
2) Centralization of shared state via a Context Provider
**DatasetsAndNotebooksContent: **A Context Provider was introduced to expose shared datasets and notebooks state and actions, eliminating prop drilling and simplifying communication across the component tree.
3) Three Panel Layout Components
Reusable components were introduced to encapsulate the logic and presentation of a three-section layout (left, center, right):
toggleButtonTopprop).All panels use context to manage visibility, sizing, and user interaction events, and render their content via
children.4) Central Content Encapsulation
A new subcomponent, DatasetsCenterContent, was implemented to encapsulate and centralize the conditional rendering logic for the central panel of the datasets module. This improves readability, maintainability, and keeps the main file clean and modular.