Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
MVarshini committed Feb 6, 2023
1 parent 83baea8 commit 4e3772c
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 60 deletions.
95 changes: 58 additions & 37 deletions dashboard/src/actions/overviewActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as CONSTANTS from "assets/constants/overviewConstants";
import * as TYPES from "./types";

import API from "../utils/axiosInstance";
import { DANGER } from "assets/constants/toastConstants";
import { findNoOfDays } from "utils/dateFunctions";
import { showToast } from "./toastActions";

Expand Down Expand Up @@ -41,7 +42,7 @@ export const getDatasets = () => async (dispatch, getState) => {
}
}
} catch (error) {
dispatch(showToast("danger", error?.response?.data?.message));
dispatch(showToast(DANGER, error?.response?.data?.message));
dispatch({ type: TYPES.NETWORK_ERROR });
}
if (alreadyRendered) {
Expand All @@ -54,12 +55,13 @@ export const getDatasets = () => async (dispatch, getState) => {
const initializeRuns = () => (dispatch, getState) => {
const data = getState().overview.datasets;
data.forEach((item) => {
item["isEdit"] = false;
item[CONSTANTS.IS_EDIT] = false;
item[CONSTANTS.NAME_COPY] = item.name;
item["isDirty"] = false;
item[CONSTANTS.NAME_VALIDATED] = "default";
item["isItemSeen"] = !!item?.metadata?.[CONSTANTS.DASHBOARD_SEEN];
item["isItemFavorited"] = !!item?.metadata?.[CONSTANTS.USER_FAVORITE];
item[CONSTANTS.IS_DIRTY] = false;
item[CONSTANTS.NAME_VALIDATED] = CONSTANTS.DEFAULT;
item[CONSTANTS.IS_ITEM_SEEN] = !!item?.metadata?.[CONSTANTS.DASHBOARD_SEEN];
item[CONSTANTS.IS_ITEM_FAVORITED] =
!!item?.metadata?.[CONSTANTS.USER_FAVORITE];
});
const defaultPerPage = getState().overview.defaultPerPage;

Expand Down Expand Up @@ -135,15 +137,20 @@ export const updateDataset =
});
dispatch(initializeRuns());
} else {
dispatch(showToast("danger", response?.data?.message));
dispatch(showToast(DANGER, response?.data?.message));
}
} catch (error) {
dispatch(showToast("danger", error?.response?.data?.message));
dispatch(showToast(DANGER, error?.response?.data?.message));
dispatch({ type: TYPES.NETWORK_ERROR });
}
dispatch({ type: TYPES.COMPLETED });
};

/**
* Function to delete the dataset
* @function
* @param {Object} dataset - Dataset which is being updated *
* @return {Object} - dispatch the action and update the state
*/
export const deleteDataset = (dataset) => async (dispatch, getState) => {
try {
dispatch({ type: TYPES.LOADING });
Expand All @@ -167,7 +174,7 @@ export const deleteDataset = (dataset) => async (dispatch, getState) => {
dispatch(showToast(CONSTANTS.SUCCESS, "Deleted!"));
}
} catch (error) {
dispatch(showToast("danger", error?.response?.data?.message));
dispatch(showToast(DANGER, error?.response?.data?.message));
dispatch({ type: TYPES.NETWORK_ERROR });
}
dispatch({ type: TYPES.COMPLETED });
Expand Down Expand Up @@ -209,7 +216,13 @@ export const updateMultipleDataset =
dispatch(showToast("warning", "Select dataset(s) for update"));
}
};

/**
* Function to publish the dataset
* @function
* @param {Object} dataset - Dataset which is being updated
* @param {string} updateValue - Access type value (Public/Private)
* @return {Object} - dispatch the action and update the state
*/
export const publishDataset =
(dataset, updateValue) => async (dispatch, getState) => {
try {
Expand All @@ -233,7 +246,7 @@ export const publishDataset =
dispatch(showToast(CONSTANTS.SUCCESS, "Updated!"));
}
} catch (error) {
dispatch(showToast("danger", error?.response?.data?.message));
dispatch(showToast(DANGER, error?.response?.data?.message));
dispatch({ type: TYPES.NETWORK_ERROR });
}
dispatch({ type: TYPES.COMPLETED });
Expand All @@ -250,57 +263,65 @@ export const setLoadingDoneFlag = () => async (dispatch, getState) => {
}, CONSTANTS.DASHBOARD_LOAD_DELAY_MS);
};

const filterDatasetType = (type) => (getState) => {
if (type === "newRuns") {
return getState().overview.initNewRuns;
}
return getState().overview.savedRuns;
const filterDatasetType = (type, getState) => {
return type === "newRuns"
? getState().overview.initNewRuns
: getState().overview.savedRuns;
};

const updateDatasetType = (data, type) => (dispatch) => {
if (type === "newRuns") {
dispatch({
type: TYPES.INIT_NEW_RUNS,
payload: data,
});
} else {
dispatch({
type: TYPES.SAVED_RUNS,
payload: data,
});
}
const updateDatasetType = (data, type) => {
return {
type: type === "newRuns" ? TYPES.INIT_NEW_RUNS : TYPES.SAVED_RUNS,
payload: data,
};
};
/**
* Function to validate the edited dataset
* @function
* @param {string} value - new value of the metadata that is being edited
* @param {string} metadata - metadata that is being edited *
* @param {string} rId - resource_id of the dataset which is being set to edit
* @param {string} type - Type of the Dataset (Saved/New)
* @return {Object} - dispatch the action and update the state
*/
export const editMetadata =
(value, metadata, rId, type) => async (dispatch, getState) => {
const data = filterDatasetType(type)(getState);
const data = filterDatasetType(type, getState);

const rIndex = data.findIndex((item) => item.resource_id === rId);
data[rIndex][metadata] = value;
data[rIndex]["isDirty"] = true;
data[rIndex][CONSTANTS.IS_DIRTY] = true;
if (value.length > CONSTANTS.DATASET_NAME_LENGTH) {
data[rIndex][CONSTANTS.NAME_VALIDATED] = "error";
data[rIndex][CONSTANTS.NAME_VALIDATED] = CONSTANTS.ERROR;
data[rIndex][
CONSTANTS.NAME_ERROR_MSG
] = `Length should be < ${CONSTANTS.DATASET_NAME_LENGTH}`;
} else if (value.length === 0) {
data[rIndex][CONSTANTS.NAME_VALIDATED] = "error";
data[rIndex][CONSTANTS.NAME_VALIDATED] = CONSTANTS.ERROR;
data[rIndex][CONSTANTS.NAME_ERROR_MSG] = `Length cannot be 0`;
} else {
data[rIndex][CONSTANTS.NAME_VALIDATED] = CONSTANTS.SUCCESS;
}
dispatch(updateDatasetType(data, type));
};

/**
* Function which toggles the row of New runs or Saved runs Table to edit
* @function
* @param {string} rId - resource_id of the dataset which is being set to edit
* @param {boolean} isEdit - Set/not set to edit
* @param {string} type - Type of the Dataset (Saved/New)
* @return {Object} - dispatch the action and update the state
*/
export const setRowtoEdit =
(rId, isEdit, type) => async (dispatch, getState) => {
const data = filterDatasetType(type)(getState);
const data = filterDatasetType(type, getState);

const rIndex = data.findIndex((item) => item.resource_id === rId);
data[rIndex].isEdit = isEdit;
data[rIndex][CONSTANTS.IS_EDIT] = isEdit;

if (!isEdit) {
data[rIndex].name = data[rIndex][CONSTANTS.NAME_COPY];
data[rIndex]["isDirty"] = false;
data[rIndex][CONSTANTS.IS_DIRTY] = false;
data[rIndex][CONSTANTS.NAME_VALIDATED] = CONSTANTS.SUCCESS;
}
dispatch(updateDatasetType(data, type));
Expand Down
6 changes: 6 additions & 0 deletions dashboard/src/assets/constants/overviewConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ export const DATASET_CREATED = "dataset.created";
export const DATASET_NAME = "dataset.name";
export const DATASET_NAME_LENGTH = 1024;
export const DATASET_OWNER = "dataset.owner";
export const DEFAULT = "default";
export const ERROR = "error";
export const EXPIRATION_DAYS_LIMIT = 20;
export const IS_DIRTY = "isDirty";
export const IS_EDIT = "isEdit";
export const IS_ITEM_FAVORITED = "isItemFavorited";
export const IS_ITEM_SEEN = "isItemSeen";
export const NAME_COPY = "name_copy";
export const NAME_ERROR_MSG = "name_errorMsg";
export const NAME_VALIDATED = "name_validated";
Expand Down
1 change: 1 addition & 0 deletions dashboard/src/assets/constants/toastConstants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DANGER = "danger";
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from "@patternfly/react-core";

import CubesIcon from "@patternfly/react-icons/dist/esm/icons/cubes-icon";
import { HOME } from "utils/routeConstants";
import React from "react";
import { useNavigate } from "react-router-dom";

Expand All @@ -20,7 +21,7 @@ const EmptyPage = (props) => {
{props.text}
</Title>
<EmptyStateBody>
<Button type="primary" onClick={() => navigate("/")}>
<Button type="primary" onClick={() => navigate("/" + HOME)}>
Go to Home
</Button>
</EmptyStateBody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import "./index.less";

import {
DASHBOARD_SEEN,
IS_ITEM_SEEN,
ROWS_PER_PAGE,
START_PAGE_NUMBER,
USER_FAVORITE,
Expand Down Expand Up @@ -82,7 +83,7 @@ const NewRunsComponent = () => {
dispatch(updateDataset(dataset, "favorite", isFavoriting));
};
const saveRowData = (metadataType, dataset, value) => {
dispatch(updateDataset(dataset, metadataType, value, "newRuns"));
dispatch(updateDataset(dataset, metadataType, value));
};
const moreActionItems = (dataset) => [
{
Expand Down Expand Up @@ -160,7 +161,7 @@ const NewRunsComponent = () => {
return (
<Tr
key={item.resource_id}
className={item.isItemSeen ? "seen-row" : "unseen-row"}
className={item[IS_ITEM_SEEN] ? "seen-row" : "unseen-row"}
>
<NewRunsRow
key={item.resource_id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import "./index.less";
import {
DASHBOARD_SEEN,
DATASET_ACCESS,
IS_ITEM_SEEN,
} from "assets/constants/overviewConstants";
import {
InnerScrollContainer,
Expand Down Expand Up @@ -76,7 +77,7 @@ const SavedRunsComponent = () => {
};
/* Edit Dataset */
const saveRowData = (metadataType, dataset, value) => {
dispatch(updateDataset(dataset, metadataType, value, "savedRuns"));
dispatch(updateDataset(dataset, metadataType, value));
};
const toggleEdit = useCallback(
(rId, isEdit) => dispatch(setRowtoEdit(rId, isEdit, "savedRuns")),
Expand Down Expand Up @@ -121,7 +122,7 @@ const SavedRunsComponent = () => {
return (
<Tr
key={item.resource_id}
className={item.isItemSeen ? "seen-row" : "unseen-row"}
className={item[IS_ITEM_SEEN] ? "seen-row" : "unseen-row"}
>
<SavedRunsRow
item={item}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import "./index.less";

import * as CONSTANTS from "assets/constants/overviewConstants";

import { ActionsColumn, Td } from "@patternfly/react-table";
import {
Button,
Expand Down Expand Up @@ -175,7 +177,7 @@ export const RenderPagination = (props) => {
export const EditRow = (props) => {
return (
<div className="pf-c-inline-edit__action pf-m-enable-editable">
{!props.item.isEdit ? (
{!props.item[CONSTANTS.IS_EDIT] ? (
<Button
variant="plain"
onClick={() => props.toggleEdit(props.item.resource_id, true)}
Expand All @@ -185,9 +187,9 @@ export const EditRow = (props) => {
<div>
<Button
isDisabled={
!props.item.isDirty ||
!props.item[CONSTANTS.IS_DIRTY] ||
!props.item.name ||
props.item.name_validated === "error"
props.item[CONSTANTS.NAME_VALIDATED] === "error"
}
onClick={() =>
props.saveRowData("datasetName", props.item, props.item.name)
Expand All @@ -206,17 +208,15 @@ export const EditRow = (props) => {
);
};

export const DatasetNameInput = (props) => {
return (
<TextInput
validated={props.validated}
value={props.value}
type="text"
onChange={props.onChange}
aria-label="Edit Dataset name"
/>
);
};
export const DatasetNameInput = (props) => (
<TextInput
validated={props.validated}
value={props.value}
type="text"
onChange={props.onChange}
aria-label="Edit Dataset name"
/>
);

export const NewRunsRow = (props) => {
const { item, rowIndex, columnNames, isRunExpanded, setRunExpanded } = props;
Expand Down Expand Up @@ -244,9 +244,9 @@ export const NewRunsRow = (props) => {
}}
/>
<Td dataLabel={columnNames.result}>
{item.isEdit ? (
{item[CONSTANTS.IS_EDIT] ? (
<DatasetNameInput
validated={item.name_validated}
validated={item[CONSTANTS.NAME_VALIDATED]}
value={item.name}
type="text"
onChange={props.textInputEdit}
Expand Down Expand Up @@ -293,9 +293,9 @@ export const SavedRunsRow = (props) => {
}}
/>
<Td className="result_column" dataLabel={columnNames.result}>
{item.isEdit ? (
{item[CONSTANTS.IS_EDIT] ? (
<DatasetNameInput
validated={item.name_validated}
validated={item[CONSTANTS.NAME_VALIDATED]}
value={item.name}
type="text"
onChange={props.textInputEdit}
Expand Down

0 comments on commit 4e3772c

Please sign in to comment.