diff --git a/app/src/controllers/instance/organizations/constants.js b/app/src/controllers/instance/organizations/constants.js index ee0ccc1ba2..1e93837fdd 100644 --- a/app/src/controllers/instance/organizations/constants.js +++ b/app/src/controllers/instance/organizations/constants.js @@ -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'; @@ -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, +}; diff --git a/app/src/controllers/instance/organizations/sagas.js b/app/src/controllers/instance/organizations/sagas.js index c41fcedff4..398cd30330 100644 --- a/app/src/controllers/instance/organizations/sagas.js +++ b/app/src/controllers/instance/organizations/sagas.js @@ -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() { diff --git a/app/src/controllers/instance/organizations/selectors.js b/app/src/controllers/instance/organizations/selectors.js index b3a76a75a5..0512ae39ed 100644 --- a/app/src/controllers/instance/organizations/selectors.js +++ b/app/src/controllers/instance/organizations/selectors.js @@ -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 || []; @@ -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, +}); diff --git a/app/src/controllers/members/selectors.js b/app/src/controllers/members/selectors.js index 8ffb5b1c34..c1d8bf1e0a 100644 --- a/app/src/controllers/members/selectors.js +++ b/app/src/controllers/members/selectors.js @@ -15,7 +15,7 @@ */ import { createQueryParametersSelector } from '../pages'; -import { DEFAULT_SORTING } from './constants'; +import { DEFAULT_SORTING, NAMESPACE } from './constants'; const domainSelector = (state) => state.members || {}; @@ -25,4 +25,5 @@ export const loadingSelector = (state) => domainSelector(state).loading || false export const querySelector = createQueryParametersSelector({ defaultSorting: DEFAULT_SORTING, + alternativeNamespace: NAMESPACE, }); diff --git a/app/src/controllers/organization/projects/sagas.js b/app/src/controllers/organization/projects/sagas.js index c0a6af46ea..7cd1224281 100644 --- a/app/src/controllers/organization/projects/sagas.js +++ b/app/src/controllers/organization/projects/sagas.js @@ -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); diff --git a/app/src/controllers/organization/projects/selectors.js b/app/src/controllers/organization/projects/selectors.js index 243cf099ec..55bfb25b5c 100644 --- a/app/src/controllers/organization/projects/selectors.js +++ b/app/src/controllers/organization/projects/selectors.js @@ -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, +}); diff --git a/app/src/controllers/organization/selectors.js b/app/src/controllers/organization/selectors.js index af40e6cef9..10269b7e36 100644 --- a/app/src/controllers/organization/selectors.js +++ b/app/src/controllers/organization/selectors.js @@ -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 || {}; @@ -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, -}); diff --git a/app/src/controllers/organization/users/sagas.js b/app/src/controllers/organization/users/sagas.js index f3d8d4d534..face0468d1 100644 --- a/app/src/controllers/organization/users/sagas.js +++ b/app/src/controllers/organization/users/sagas.js @@ -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 { diff --git a/app/src/controllers/organization/users/selectors.js b/app/src/controllers/organization/users/selectors.js index f7df8911fe..422c510b94 100644 --- a/app/src/controllers/organization/users/selectors.js +++ b/app/src/controllers/organization/users/selectors.js @@ -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, +}); diff --git a/app/src/controllers/pages/selectors.js b/app/src/controllers/pages/selectors.js index 8054a50312..2602e2fd95 100644 --- a/app/src/controllers/pages/selectors.js +++ b/app/src/controllers/pages/selectors.js @@ -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'; @@ -105,6 +106,7 @@ export const prevPagePropertiesSelector = ( export const createQueryParametersSelector = ({ namespace: staticNamespace, + alternativeNamespace, defaultPagination, defaultSorting, sortingKey = SORTING_KEY, @@ -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]; diff --git a/app/src/controllers/pagination/withPagination.jsx b/app/src/controllers/pagination/withPagination.jsx index d8064b258a..03afc3bf5c 100644 --- a/app/src/controllers/pagination/withPagination.jsx +++ b/app/src/controllers/pagination/withPagination.jsx @@ -29,6 +29,7 @@ export const withPagination = ({ paginationSelector = defaultPaginationSelector, namespace, namespaceSelector, + alternativeNamespace, offset, } = {}) => (WrappedComponent) => { const getTotalElements = totalElementsSelector(paginationSelector); @@ -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 { @@ -61,6 +63,7 @@ export const withPagination = ({ totalElements: PropTypes.number, totalPages: PropTypes.number, namespace: PropTypes.string, + alternativeNamespace: PropTypes.string, userId: PropTypes.string.isRequired, }; @@ -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; } @@ -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, }); @@ -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; diff --git a/app/src/controllers/user/sagas.js b/app/src/controllers/user/sagas.js index 8eee8b4337..58c37662be 100644 --- a/app/src/controllers/user/sagas.js +++ b/app/src/controllers/user/sagas.js @@ -185,7 +185,10 @@ function* fetchUserWorker() { if (!projectKey) { projectKey = isAssignedToTargetProject - ? assignedProjects[targetProjectSlug].projectKey + ? ( + assignedProjects[targetProjectSlug] || + assignedProjects[`${targetOrganizationSlug}.${targetProjectSlug}`] + ).projectKey : defaultProjectKey; } diff --git a/app/src/pages/instance/organizationsPage/organizationsPanelView/organizationsPanelView.jsx b/app/src/pages/instance/organizationsPage/organizationsPanelView/organizationsPanelView.jsx index 78f86197ab..aa6360ea23 100644 --- a/app/src/pages/instance/organizationsPage/organizationsPanelView/organizationsPanelView.jsx +++ b/app/src/pages/instance/organizationsPage/organizationsPanelView/organizationsPanelView.jsx @@ -83,6 +83,6 @@ export const OrganizationsPanelView = withSortingURL({ })( withPagination({ paginationSelector: organizationsListPaginationSelector, - namespace: NAMESPACE, + alternativeNamespace: NAMESPACE, })(OrganizationsPanelViewWrapped), ); diff --git a/app/src/pages/organization/organizationProjectsPage/projectsListTable/projectsListTable.jsx b/app/src/pages/organization/organizationProjectsPage/projectsListTable/projectsListTable.jsx index 5fc1286ae4..850790986c 100644 --- a/app/src/pages/organization/organizationProjectsPage/projectsListTable/projectsListTable.jsx +++ b/app/src/pages/organization/organizationProjectsPage/projectsListTable/projectsListTable.jsx @@ -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'; @@ -188,6 +188,6 @@ export const ProjectsListTableWrapper = withSortingURL({ })( withPagination({ paginationSelector: projectsPaginationSelector, - namespace: NAMESPACE, + alternativeNamespace: NAMESPACE, })(ProjectsListTable), ); diff --git a/app/src/pages/organization/organizationUsersPage/organizationUsersListTable/organizationUsersListTable.jsx b/app/src/pages/organization/organizationUsersPage/organizationUsersListTable/organizationUsersListTable.jsx index 07d79ee9e3..b82b77ebe1 100644 --- a/app/src/pages/organization/organizationUsersPage/organizationUsersListTable/organizationUsersListTable.jsx +++ b/app/src/pages/organization/organizationUsersPage/organizationUsersListTable/organizationUsersListTable.jsx @@ -202,6 +202,6 @@ export const OrganizationTeamListTable = withSortingURL({ })( withPagination({ paginationSelector: usersPaginationSelector, - namespace: NAMESPACE, + alternativeNamespace: NAMESPACE, })(OrgTeamListTableWrapped), ); diff --git a/app/src/pages/organization/projectTeamPage/projectTeamListTable/projectTeamListTable.jsx b/app/src/pages/organization/projectTeamPage/projectTeamListTable/projectTeamListTable.jsx index 3ce0d789fe..0b2201ce97 100644 --- a/app/src/pages/organization/projectTeamPage/projectTeamListTable/projectTeamListTable.jsx +++ b/app/src/pages/organization/projectTeamPage/projectTeamListTable/projectTeamListTable.jsx @@ -202,6 +202,6 @@ export const ProjectTeamListTable = withSortingURL({ })( withPagination({ paginationSelector: membersPaginationSelector, - namespace: NAMESPACE, + alternativeNamespace: NAMESPACE, })(ProjectTeamListTableWrapped), );