Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MVarshini committed Apr 25, 2023
1 parent 061e554 commit 809145b
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 60 deletions.
64 changes: 28 additions & 36 deletions dashboard/src/actions/datasetListActions.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as CONSTANTS from "assets/constants/browsingPageConstants";
import * as TYPES from "./types";

import { DANGER, ERROR_MSG } from "assets/constants/toastConstants";

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

Expand Down Expand Up @@ -46,8 +48,8 @@ export const fetchPublicDatasets = (page) => async (dispatch, getState) => {
);

dispatch({
type: TYPES.GET_PUBLIC_DATASETS,
payload: [...publicData],
type: TYPES.UPDATE_PUBLIC_DATASETS,
payload: publicData,
});
// in case of last page, next_url is empty
if (response.data.next_url) {
Expand All @@ -65,7 +67,7 @@ export const fetchPublicDatasets = (page) => async (dispatch, getState) => {
});
}
} catch (error) {
dispatch(showToast(DANGER, "Error"));
dispatch(showToast(DANGER, ERROR_MSG));
dispatch({ type: TYPES.NETWORK_ERROR });
}
dispatch({ type: TYPES.COMPLETED });
Expand All @@ -80,49 +82,39 @@ export const getFavoritedDatasets = () => async (dispatch) => {
});
};

export const updateFavoriteRepoNames = (favorites) => async (dispatch) => {
dispatch({
type: TYPES.FAVORITED_DATASETS,
payload: [...favorites],
});
};
export const updateFavoriteRepoNames = (favorites) => ({
type: TYPES.FAVORITED_DATASETS,
payload: [...favorites],
});

export const setPageLimit = (newPerPage) => async (dispatch) => {
dispatch({
type: TYPES.SET_PAGE_LIMIT,
payload: newPerPage,
});
};
export const setPageLimit = (newPerPage) => ({
type: TYPES.SET_PAGE_LIMIT,
payload: newPerPage,
});

export const setFilterKeys = (startDate, endDate) => async (dispatch) => {
dispatch({
type: TYPES.SET_DATE_RANGE,
payload: { startDate, endDate },
});
};
export const setFilterKeys = (startDate, endDate) => ({
type: TYPES.SET_DATE_RANGE,
payload: { startDate, endDate },
});

export const nameFilter = (value) => async (dispatch) => {
dispatch({
type: TYPES.SET_SEARCH_KEY,
payload: value,
});
};
export const nameFilter = (value) => ({
type: TYPES.SET_SEARCH_KEY,
payload: value,
});

export const applyFilter = () => (dispatch) => {
dispatch({
type: TYPES.GET_PUBLIC_DATASETS,
type: TYPES.UPDATE_PUBLIC_DATASETS,
payload: [],
});
dispatch({
type: TYPES.SET_PAGE_OFFSET,
payload: 0,
});
dispatch(fetchPublicDatasets(1));
dispatch(fetchPublicDatasets(CONSTANTS.START_PAGE_NUMBER));
};

export const setPerPage = (value) => (dispatch) => {
dispatch({
type: TYPES.SET_PER_PAGE,
payload: value,
});
};
export const setPerPage = (value) => ({
type: TYPES.SET_PER_PAGE,
payload: value,
});
8 changes: 1 addition & 7 deletions dashboard/src/actions/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const NAVBAR_OPEN = "NAVBAR_OPEN";
export const NAVBAR_CLOSE = "NAVBAR_CLOSE";

/* PUBLIC DATASETS */
export const GET_PUBLIC_DATASETS = "GET_PUBLIC_DATASETS";
export const UPDATE_PUBLIC_DATASETS = "UPDATE_PUBLIC_DATASETS";
export const FAVORITED_DATASETS = "GET_FAVORITE_DATASETS";
export const SET_LOGIN_DETAILS = "SET_LOGIN_DETAILS";
export const SET_PAGE_OFFSET = "SET_PAGE_OFFSET";
Expand All @@ -32,12 +32,6 @@ export const SET_DATE_RANGE = "SET_DATE_RANGE";
export const SET_SEARCH_KEY = "SET_SEARCH_KEY";
export const SET_PER_PAGE = "SET_PER_PAGE";

/* USER DETAILS */
export const GET_USER_DETAILS = "GET_USER_DETAILS";
export const UPDATE_USER_DETAILS = "UPDATE_USER_DETAILS";
export const RESET_DATA = "RESET_DATA";
export const SET_USER_DETAILS = "SET_USER_DETAILS";

/* DASHBOARD OVERVIEW */
export const USER_RUNS = "USER_RUNS";
export const SAVED_RUNS = "SAVED_RUNS";
Expand Down
9 changes: 7 additions & 2 deletions dashboard/src/assets/constants/browsingPageConstants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
export const DEFAULT_PER_PAGE = 20;
export const LIMIT = 60;
export const INITIAL_PAGE_LIMIT = 60;
export const START_PAGE_NUMBER = 1;
export const LIMIT_MULTIPLIER = 3;
export const OVERFETCH_FACTOR = 3;
export const PER_PAGE_OPTIONS = [
{ title: "10", value: 10 },
{ title: "20", value: 20 },
{ title: "50", value: 50 },
];
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import "./index.less";

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

import {
Button,
DatePicker,
Expand Down Expand Up @@ -43,7 +45,7 @@ const DatePickerWidget = (props) => {
if (from) {
dispatch(setFilterKeys(from, new Date(to)));
dispatch(applyFilter());
props.setPage(1);
props.setPage(CONSTANTS.START_PAGE_NUMBER);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from "actions/datasetListActions";
import { useDispatch, useSelector } from "react-redux";

import { LIMIT_MULTIPLIER } from "assets/constants/browsingPageConstants";
import { OVERFETCH_FACTOR } from "assets/constants/browsingPageConstants";
import React from "react";

const TablePagination = ({ page, setPage }) => {
Expand All @@ -23,7 +23,7 @@ const TablePagination = ({ page, setPage }) => {
fetchData(_event, pageNumber, perPage);
};
const onPerPageSelect = (_event, newPerPage, newPage) => {
dispatch(setPageLimit(newPerPage * LIMIT_MULTIPLIER));
dispatch(setPageLimit(newPerPage * OVERFETCH_FACTOR));

dispatch(setPerPage(newPerPage));
setPage(newPage);
Expand All @@ -48,11 +48,9 @@ const TablePagination = ({ page, setPage }) => {
}
}
if (left !== right) {
const offset = (newPage - 1) * newPerPage;

dispatch({
type: TYPES.SET_PAGE_OFFSET,
payload: Number(offset),
payload: startIdx,
});
dispatch(fetchPublicDatasets(newPage));
}
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/browsingPageConstants";

import {
Alert,
AlertActionCloseButton,
Expand Down Expand Up @@ -73,7 +75,7 @@ export const SearchBox = (props) => {
const search = () => {
dispatch(nameFilter(searchKey));
dispatch(applyFilter());
props.setPage(1);
props.setPage(CONSTANTS.START_PAGE_NUMBER);
};
const handleKeyPress = (e) => {
const key = e.key;
Expand Down
8 changes: 2 additions & 6 deletions dashboard/src/modules/components/TableComponent/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,7 @@ const TableWithFavorite = () => {
setFavPage(newPage);
selectedArray = favoriteRepoNames?.slice(startIdx, endIdx);
};
const perPageOptions = [
{ title: "10", value: 10 },
{ title: "20", value: 20 },
{ title: "50", value: 50 },
];

const onPerPageSelect = (_evt, newPerPage, newPage, startIdx, endIdx) => {
setfavTblPerPage(newPerPage);
setFavPage(newPage);
Expand Down Expand Up @@ -251,7 +247,7 @@ const TableWithFavorite = () => {
perPage={favTblperPage}
setPerPage={setfavTblPerPage}
onSetPage={onSetPage}
perPageOptions={perPageOptions}
perPageOptions={CONSTANTS.PER_PAGE_OPTIONS}
onPerPageSelect={onPerPageSelect}
/>
)}
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/reducers/datasetListReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const initialState = {
favoriteRepoNames: [],
tableData: [],
offset: 0,
limit: CONSTANTS.LIMIT,
limit: CONSTANTS.INITIAL_PAGE_LIMIT,
perPage: CONSTANTS.DEFAULT_PER_PAGE,
totalDatasets: 0,
searchKey: "",
Expand All @@ -19,7 +19,7 @@ const initialState = {
const DatasetListReducer = (state = initialState, action = {}) => {
const { type, payload } = action;
switch (type) {
case TYPES.GET_PUBLIC_DATASETS:
case TYPES.UPDATE_PUBLIC_DATASETS:
return {
...state,
publicData: [...payload],
Expand Down

0 comments on commit 809145b

Please sign in to comment.