Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPMRPP-96415 || Default number of items per page is displayed when us… #4065

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/src/controllers/instance/organizations/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

import { PAGE_KEY, SIZE_KEY } from 'controllers/pagination';

export const NAMESPACE = 'organizations';

export const FETCH_ORGANIZATIONS = 'fetchOrganizations';
Expand All @@ -24,3 +26,8 @@ export const initialPaginationState = {
totalElements: 0,
totalPages: 0,
};
export const SORTING_KEY = 'order';
export const DEFAULT_PAGINATION = {
[PAGE_KEY]: 1,
[SIZE_KEY]: DEFAULT_LIMITATION,
};
2 changes: 1 addition & 1 deletion app/src/controllers/instance/organizations/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { takeEvery, all, put, select } from 'redux-saga/effects';
import { URLS } from 'common/urls';
import { showDefaultErrorNotification } from 'controllers/notification';
import { fetchDataAction } from 'controllers/fetch';
import { querySelector } from 'controllers/organization/selectors';
import { querySelector } from './selectors';
import { FETCH_ORGANIZATIONS, NAMESPACE } from './constants';

function* fetchOrganizations() {
Expand Down
15 changes: 15 additions & 0 deletions app/src/controllers/instance/organizations/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@
* limitations under the License.
*/

import {
NAMESPACE,
DEFAULT_PAGINATION,
SORTING_KEY,
} from 'controllers/instance/organizations/constants';
import { createAlternativeQueryParametersSelector } from 'controllers/pages/selectors';
import { SORTING_ASC } from 'controllers/sorting';

export const organizationsSelector = (state) => state.organizations || {};

export const organizationsListSelector = (state) => organizationsSelector(state).list || [];
Expand All @@ -22,3 +30,10 @@ export const organizationsListLoadingSelector = (state) => organizationsSelector

export const organizationsListPaginationSelector = (state) =>
organizationsSelector(state).pagination;

export const querySelector = createAlternativeQueryParametersSelector({
defaultPagination: DEFAULT_PAGINATION,
defaultDirection: SORTING_ASC,
sortingKey: SORTING_KEY,
alternativeNamespace: NAMESPACE,
});
3 changes: 2 additions & 1 deletion app/src/controllers/members/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import { createQueryParametersSelector } from '../pages';
import { DEFAULT_SORTING } from './constants';
import { DEFAULT_SORTING, NAMESPACE } from './constants';

const domainSelector = (state) => state.members || {};

Expand All @@ -25,4 +25,5 @@ export const loadingSelector = (state) => domainSelector(state).loading || false

export const querySelector = createQueryParametersSelector({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be replaced by createAlternativeQueryParametersSelector?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an old pagination and can work via namespace:
image

But then there will be such parameters:
image

with an alternative namespace:
image

defaultSorting: DEFAULT_SORTING,
alternativeNamespace: NAMESPACE,
});
3 changes: 2 additions & 1 deletion app/src/controllers/organization/projects/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import { fetch } from 'common/utils';
import { hideModalAction } from 'controllers/modal';
import { NOTIFICATION_TYPES, showNotification } from 'controllers/notification';
import { fetchOrganizationBySlugAction } from '..';
import { activeOrganizationSelector, querySelector } from '../selectors';
import { activeOrganizationSelector } from '../selectors';
import { fetchOrganizationProjectsAction } from './actionCreators';
import { CREATE_PROJECT, FETCH_ORGANIZATION_PROJECTS, ERROR_CODES, NAMESPACE } from './constants';
import { querySelector } from './selectors';

function* fetchOrganizationProjects({ payload: organizationId }) {
const query = yield select(querySelector);
Expand Down
10 changes: 10 additions & 0 deletions app/src/controllers/organization/projects/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,20 @@
* limitations under the License.
*/

import { SORTING_ASC } from 'controllers/sorting';
import { createAlternativeQueryParametersSelector } from 'controllers/pages/selectors';
import { organizationSelector } from '../selectors';
import { DEFAULT_PAGINATION, NAMESPACE, SORTING_KEY } from './constants';

const domainSelector = (state) => organizationSelector(state).projects || {};

export const projectsPaginationSelector = (state) => domainSelector(state).pagination;
export const projectsSelector = (state) => domainSelector(state).projects;
export const loadingSelector = (state) => domainSelector(state).loading || false;

export const querySelector = createAlternativeQueryParametersSelector({
defaultPagination: DEFAULT_PAGINATION,
defaultDirection: SORTING_ASC,
sortingKey: SORTING_KEY,
alternativeNamespace: NAMESPACE,
});
25 changes: 1 addition & 24 deletions app/src/controllers/organization/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { createSelector } from 'reselect';
import { createQueryParametersSelector } from 'controllers/pages';
import { getAlternativePaginationAndSortParams, PAGE_KEY, SIZE_KEY } from 'controllers/pagination';
import { SORTING_ASC } from 'controllers/sorting';

import { organizationsSelector } from 'controllers/instance/organizations/selectors';
import { SORTING_KEY } from './projects';
import { DEFAULT_PAGINATION } from './projects/constants';

export const organizationSelector = (state) => organizationsSelector(state).organization || {};

Expand All @@ -31,21 +26,3 @@ export const activeOrganizationLoadingSelector = (state) =>
export const activeOrganizationNameSelector = (state) => activeOrganizationSelector(state)?.name;

export const activeOrganizationIdSelector = (state) => activeOrganizationSelector(state)?.id;

export const createParametersSelector = ({ defaultPagination, defaultSorting, sortingKey } = {}) =>
createSelector(
createQueryParametersSelector({
defaultPagination,
defaultSorting,
sortingKey,
}),
({ [SIZE_KEY]: limit, [SORTING_KEY]: sort, [PAGE_KEY]: pageNumber, ...rest }) => {
return { ...getAlternativePaginationAndSortParams(sort, limit, pageNumber), ...rest };
},
);

export const querySelector = createParametersSelector({
defaultPagination: DEFAULT_PAGINATION,
defaultDirection: SORTING_ASC,
sortingKey: SORTING_KEY,
});
3 changes: 2 additions & 1 deletion app/src/controllers/organization/users/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
import { createFetchPredicate, fetchDataAction } from 'controllers/fetch';
import { URLS } from 'common/urls';
import { all, put, select, take, takeEvery } from 'redux-saga/effects';
import { activeOrganizationSelector, querySelector } from '../selectors';
import { querySelector } from './selectors';
import { activeOrganizationSelector } from '../selectors';
import { FETCH_ORGANIZATION_BY_SLUG } from '../constants';
import { fetchOrganizationUsersAction } from './actionCreators';
import {
Expand Down
11 changes: 11 additions & 0 deletions app/src/controllers/organization/users/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,21 @@
* limitations under the License.
*/

import { SORTING_ASC } from 'controllers/sorting';
import { createAlternativeQueryParametersSelector } from 'controllers/pages/selectors';
import { organizationSelector } from '../selectors';
import { NAMESPACE } from './constants';
import { DEFAULT_PAGINATION, SORTING_KEY } from '../projects/constants';

const domainSelector = (state) => organizationSelector(state).users || {};

export const usersPaginationSelector = (state) => domainSelector(state).pagination;
export const usersSelector = (state) => domainSelector(state).users;
export const loadingSelector = (state) => domainSelector(state).loading || false;

export const querySelector = createAlternativeQueryParametersSelector({
defaultPagination: DEFAULT_PAGINATION,
defaultDirection: SORTING_ASC,
sortingKey: SORTING_KEY,
alternativeNamespace: NAMESPACE,
});
27 changes: 25 additions & 2 deletions app/src/controllers/pages/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
import { ALL } from 'common/constants/reservedFilterIds';
import { ADMINISTRATOR } from 'common/constants/accountRoles';
import { MANAGER } from 'common/constants/projectRoles';
import { getAlternativePaginationAndSortParams } from 'controllers/pagination';
import { pageNames, NO_PAGE } from './constants';
import { stringToArray } from './utils';

Expand Down Expand Up @@ -105,6 +106,7 @@ export const prevPagePropertiesSelector = (

export const createQueryParametersSelector = ({
namespace: staticNamespace,
alternativeNamespace,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the existing staticNamespace cannot be used instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When everyone switches to the same pagination format, then you can leave one option.

defaultPagination,
defaultSorting,
sortingKey = SORTING_KEY,
Expand All @@ -124,14 +126,35 @@ export const createQueryParametersSelector = ({
if (Number(queryParameters[PAGE_KEY]) < 0) {
queryParameters[PAGE_KEY] = calculatedPagination[PAGE_KEY];
}
if ((!query[SIZE_KEY] || Number(query[SIZE_KEY]) < 0) && calculatedNamespace) {

const currentNamespace = calculatedNamespace || alternativeNamespace;

if ((!query[SIZE_KEY] || Number(query[SIZE_KEY]) < 0) && currentNamespace) {
const userId = userIdSelector(state);
const userSettings = getStorageItem(`${userId}_settings`) || {};
queryParameters[SIZE_KEY] = userSettings[`${calculatedNamespace}PageSize`] || defaultPageSize;
queryParameters[SIZE_KEY] = userSettings[`${currentNamespace}PageSize`] || defaultPageSize;
}
return queryParameters;
};

export const createAlternativeQueryParametersSelector = ({
defaultPagination,
defaultSorting,
sortingKey,
alternativeNamespace,
} = {}) =>
createSelector(
createQueryParametersSelector({
defaultPagination,
defaultSorting,
sortingKey,
alternativeNamespace,
}),
({ [SIZE_KEY]: limit, [SORTING_KEY]: sort, [PAGE_KEY]: pageNumber, ...rest }) => {
return { ...getAlternativePaginationAndSortParams(sort, limit, pageNumber), ...rest };
},
);

export const launchIdSelector = (state) => {
const testItemIds = testItemIdsArraySelector(state);
return testItemIds?.[0];
Expand Down
11 changes: 8 additions & 3 deletions app/src/controllers/pagination/withPagination.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const withPagination = ({
paginationSelector = defaultPaginationSelector,
namespace,
namespaceSelector,
alternativeNamespace,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When everyone switches to the same pagination format, then you can leave one option.

offset,
} = {}) => (WrappedComponent) => {
const getTotalElements = totalElementsSelector(paginationSelector);
Expand All @@ -47,6 +48,7 @@ export const withPagination = ({
totalElements: getTotalElements(state),
totalPages: getTotalPages(state),
namespace: namespaceSelector ? namespaceSelector(state) : namespace,
alternativeNamespace,
userId: userIdSelector(state),
}))
class PaginationWrapper extends Component {
Expand All @@ -61,6 +63,7 @@ export const withPagination = ({
totalElements: PropTypes.number,
totalPages: PropTypes.number,
namespace: PropTypes.string,
alternativeNamespace: PropTypes.string,
userId: PropTypes.string.isRequired,
};

Expand All @@ -84,7 +87,7 @@ export const withPagination = ({

getPageSize = () => {
const { size, userId } = this.props;
if (size === undefined && this.props.namespace) {
if (size === undefined && this.getNamespace()) {
const userSettings = getStorageItem(`${userId}_settings`) || {};
return userSettings[this.calculateFieldName()] || size;
}
Expand All @@ -97,7 +100,7 @@ export const withPagination = ({

changeSizeHandler = (size) => {
const { userId } = this.props;
if (this.props.namespace) {
if (this.getNamespace()) {
updateStorageItem(`${userId}_settings`, {
[this.calculateFieldName()]: size,
});
Expand All @@ -110,7 +113,9 @@ export const withPagination = ({
this.props.updatePagination(options.page || page, options.size || this.getPageSize());
};

calculateFieldName = () => `${this.props.namespace}PageSize`;
calculateFieldName = () => `${this.getNamespace()}PageSize`;

getNamespace = () => this.props.namespace || this.props.alternativeNamespace;

render() {
const { page, size, totalElements, totalPages, updatePagination, ...restProps } = this.props;
Expand Down
5 changes: 4 additions & 1 deletion app/src/controllers/user/sagas.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,10 @@ function* fetchUserWorker() {

if (!projectKey) {
projectKey = isAssignedToTargetProject
? assignedProjects[targetProjectSlug].projectKey
? (
assignedProjects[targetProjectSlug] ||
assignedProjects[`${targetOrganizationSlug}.${targetProjectSlug}`]
).projectKey
: defaultProjectKey;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ export const OrganizationsPanelView = withSortingURL({
})(
withPagination({
paginationSelector: organizationsListPaginationSelector,
namespace: NAMESPACE,
alternativeNamespace: NAMESPACE,
})(OrganizationsPanelViewWrapped),
);
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
projectsPaginationSelector,
SORTING_KEY,
} from 'controllers/organization/projects';
import { NAMESPACE } from 'controllers/project/constants';
import { NAMESPACE } from 'controllers/organization/projects/constants';
import { messages } from '../messages';
import { ProjectName } from './projectName';
import styles from './projectsListTable.scss';
Expand Down Expand Up @@ -188,6 +188,6 @@ export const ProjectsListTableWrapper = withSortingURL({
})(
withPagination({
paginationSelector: projectsPaginationSelector,
namespace: NAMESPACE,
alternativeNamespace: NAMESPACE,
})(ProjectsListTable),
);
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,6 @@ export const OrganizationTeamListTable = withSortingURL({
})(
withPagination({
paginationSelector: usersPaginationSelector,
namespace: NAMESPACE,
alternativeNamespace: NAMESPACE,
})(OrgTeamListTableWrapped),
);
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,6 @@ export const ProjectTeamListTable = withSortingURL({
})(
withPagination({
paginationSelector: membersPaginationSelector,
namespace: NAMESPACE,
alternativeNamespace: NAMESPACE,
})(ProjectTeamListTableWrapped),
);
Loading