Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MVarshini committed Jan 2, 2024
1 parent 3fdfcee commit fc735b6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
22 changes: 11 additions & 11 deletions dashboard/src/actions/tocActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ import { uriTemplate } from "utils/helper";
/**
* Function to fetch contents data
* @function
* @param {String} param - Dataset ID
* @param {String} datasetId - Dataset ID
* @param {String} dataUri - URI
* @param {String} item - Active item
* @param {Boolean} isSubDir - To identify sub-directory expansion
* @return {Function} - dispatch the action and update the state
*/
export const fetchTOC =
(param, dataUri, item, isSubDir) => async (dispatch, getState) => {
(datasetId, dataUri, item, isSubDir) => async (dispatch, getState) => {
try {
dispatch({ type: TYPES.LOADING });
const endpoints = getState().apiEndpoint.endpoints;
const parent = dataUri?.split("contents/").pop();
const uri = uriTemplate(endpoints, "datasets_contents", {
dataset: param,
dataset: datasetId,
target: parent,
});
const response = await API.get(uri);
Expand Down Expand Up @@ -52,19 +52,18 @@ export const fetchTOC =
*/
export const parseToTreeView =
(contentData, activeItem, isSubDir, parent) => (dispatch, getState) => {
const treeOptions = [];
const keyPath = parent.replaceAll("/", "*");
const drillMenuData = [...getState()?.toc?.drillMenuData];
for (const item of contentData.directories) {
const drillMenuData = [...getState().toc.drillMenuData];
const treeOptions = contentData.directories.map((item) => {
const obj = {
name: item.name,
id: parent ? `${keyPath}*${item.name}` : item.name,
children: [],
isDirectory: true,
uri: item.uri,
};
treeOptions.push(obj);
}
return obj;
});
for (const item of contentData.files) {
const obj = {
name: item.name,
Expand Down Expand Up @@ -98,7 +97,7 @@ export const parseToTreeView =
* @param {Object} arr - Drill down menu
* @param {String} key - key path
* @param {Array} childrenToUpdate - Active item children obtained through API request
* @return {Function} - update the children
* @return {Array} - updated children
*/
const updateActiveItemChildren = (arr, key, childrenToUpdate) => {
// if children are undefined
Expand All @@ -110,9 +109,10 @@ const updateActiveItemChildren = (arr, key, childrenToUpdate) => {
if (entry.id === key) {
entry.children = childrenToUpdate;
}

// recursive call to traverse children
updateActiveItemChildren(entry.children, key, childrenToUpdate);
else {
updateActiveItemChildren(entry.children, key, childrenToUpdate);
}
});

return arr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const DrilldownMenu = (props) => {

return (
<div className="drilldownMenu-container">
{drillMenuData && drillMenuData.length > 0 && (
{drillMenuData?.length > 0 && (
<TreeView
data={drillMenuData}
activeItems={activeItems}
Expand Down
10 changes: 5 additions & 5 deletions dashboard/src/modules/components/TableOfContent/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { DownloadIcon } from "@patternfly/react-icons";
import DrilldownMenu from "./DrillDownMenu";
import { useParams } from "react-router";

const TableOfContent1 = () => {
const TableOfContent = () => {
const dispatch = useDispatch();
const params = useParams();

Expand All @@ -32,10 +32,10 @@ const TableOfContent1 = () => {
}, [dispatch, endpoints, params]);

const drillMenuItem = (item) => {
if (item.isDirectory && !item.children.length) {
dispatch(fetchTOC(params["dataset_id"], item.uri, item.id, true));
} else if (!item.isDirectory) {
if (!item.isDirectory) {
dispatch(setActiveFileContent(item));
} else if (!item.children.length) {
dispatch(fetchTOC(params["dataset_id"], item.uri, item.id, true));
}
};
return (
Expand Down Expand Up @@ -95,4 +95,4 @@ const TableOfContent1 = () => {
);
};

export default TableOfContent1;
export default TableOfContent;

0 comments on commit fc735b6

Please sign in to comment.