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

Remove withRequest and related selectors and refactor <Require /> #6443

Merged
merged 12 commits into from
Aug 14, 2023
6 changes: 2 additions & 4 deletions pkg/webui/account/containers/authorizations-table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { getAuthorizationsList } from '@account/store/actions/authorizations'
import {
selectAuthorizations,
selectAuthorizationsTotalCount,
selectAuthorizationsFetching,
} from '@account/store/selectors/authorizations'
import { selectUserId } from '@account/store/selectors/user'

Expand Down Expand Up @@ -67,11 +66,10 @@ const OAuthClientAuthorizationsTable = () => {
}, [])

const baseDataSelector = createSelector(
[selectAuthorizations, selectAuthorizationsTotalCount, selectAuthorizationsFetching],
(authorizations, totalCount, fetching) => ({
[selectAuthorizations, selectAuthorizationsTotalCount],
(authorizations, totalCount) => ({
authorizations,
totalCount,
fetching,
mayAdd: false,
}),
)
Expand Down
11 changes: 3 additions & 8 deletions pkg/webui/account/containers/clients-table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ import { checkFromState, mayPerformAllClientActions } from '@account/lib/feature
import { deleteClient, restoreClient, getClientsList } from '@account/store/actions/clients'

import { selectUserIsAdmin } from '@account/store/selectors/user'
import {
selectOAuthClients,
selectOAuthClientsTotalCount,
selectOAuthClientsFetching,
} from '@account/store/selectors/clients'
import { selectOAuthClients, selectOAuthClientsTotalCount } from '@account/store/selectors/clients'

const m = defineMessages({
ownedTabTitle: 'Owned OAuth clients',
Expand Down Expand Up @@ -182,11 +178,10 @@ const ClientsTable = () => {
}, [tab, handlePurge, handleRestore, formatMessage])

const baseDataSelector = createSelector(
[selectOAuthClients, selectOAuthClientsTotalCount, selectOAuthClientsFetching, mayAddSelector],
(clients, totalCount, fetching, mayAdd) => ({
[selectOAuthClients, selectOAuthClientsTotalCount, mayAddSelector],
(clients, totalCount, mayAdd) => ({
clients,
totalCount,
fetching,
mayAdd,
}),
)
Expand Down
13 changes: 2 additions & 11 deletions pkg/webui/account/containers/collaborators-table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ import { getCollaboratorsList, deleteCollaborator } from '@ttn-lw/lib/store/acti
import {
selectCollaborators,
selectCollaboratorsTotalCount,
selectCollaboratorsFetching,
selectCollaboratorsError,
} from '@ttn-lw/lib/store/selectors/collaborators'

import { selectUserId } from '@account/store/selectors/user'
Expand Down Expand Up @@ -165,17 +163,10 @@ const CollaboratorsTable = props => {
}, [intl, currentUserId, deleteCollaborator])

const baseDataSelector = createSelector(
[
selectCollaborators,
selectCollaboratorsTotalCount,
selectCollaboratorsFetching,
selectCollaboratorsError,
],
(collaborators, totalCount, fetching, error) => ({
[selectCollaborators, selectCollaboratorsTotalCount],
(collaborators, totalCount) => ({
collaborators,
totalCount,
fetching,
error,
mayLink: false,
}),
)
Expand Down
11 changes: 3 additions & 8 deletions pkg/webui/account/containers/sessions-table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@ import attachPromise from '@ttn-lw/lib/store/actions/attach-promise'
import { getUserSessionsList, deleteUserSession } from '@account/store/actions/sessions'

import { selectUserId, selectSessionId } from '@account/store/selectors/user'
import {
selectUserSessions,
selectUserSessionsTotalCount,
selectUserSessionsFetching,
} from '@account/store/selectors/sessions'
import { selectUserSessions, selectUserSessionsTotalCount } from '@account/store/selectors/sessions'

const m = defineMessages({
deleteSessionSuccess: 'Session removed successfully',
Expand Down Expand Up @@ -76,8 +72,8 @@ const UserSessionsTable = () => {
)

const baseDataSelector = createSelector(
[selectUserSessions, selectUserSessionsTotalCount, selectUserSessionsFetching],
(sessions, totalCount, fetching) => {
[selectUserSessions, selectUserSessionsTotalCount],
(sessions, totalCount) => {
const decoratedSessions = []

if (sessions) {
Expand All @@ -95,7 +91,6 @@ const UserSessionsTable = () => {
return {
sessions: decoratedSessions,
totalCount,
fetching,
mayAdd: false,
mayLink: false,
}
Expand Down
10 changes: 2 additions & 8 deletions pkg/webui/account/containers/tokens-table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ import {
getAccessTokensList,
} from '@account/store/actions/authorizations'

import {
selectTokens,
selectTokensTotalCount,
selectTokensFetching,
} from '@account/store/selectors/authorizations'
import { selectTokens, selectTokensTotalCount } from '@account/store/selectors/authorizations'
import { selectUserId } from '@account/store/selectors/user'

const m = defineMessages({
Expand Down Expand Up @@ -169,11 +165,9 @@ const TokensTable = () => {
const baseDataSelector = createSelector(
selectTokens,
selectTokensTotalCount,
selectTokensFetching,
(tokens, totalCount, fetching) => ({
(tokens, totalCount) => ({
tokens,
totalCount,
fetching,
mayAdd: false,
mayLink: false,
}),
Expand Down
33 changes: 22 additions & 11 deletions pkg/webui/account/views/oauth-clients-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,38 @@

import React from 'react'
import { Row, Col, Container } from 'react-grid-system'
import { useSelector } from 'react-redux'

import PAGE_SIZES from '@ttn-lw/constants/page-sizes'

import PageTitle from '@ttn-lw/components/page-title'

import IntlHelmet from '@ttn-lw/lib/components/intl-helmet'
import RequireRequest from '@ttn-lw/lib/components/require-request'

import ClientsTable from '@account/containers/clients-table'

import sharedMessages from '@ttn-lw/lib/shared-messages'

const ClientsList = () => (
<Container>
<Row>
<IntlHelmet title={sharedMessages.oauthClients} />
<Col>
<PageTitle title={sharedMessages.oauthClients} hideHeading />
<ClientsTable pageSize={PAGE_SIZES.REGULAR} />
</Col>
</Row>
</Container>
)
import { getUserRights } from '@account/store/actions/user'

import { selectUserId } from '@account/store/selectors/user'

const ClientsList = () => {
const userId = useSelector(selectUserId)
return (
<RequireRequest requestAction={getUserRights(userId)}>
<Container>
<Row>
<IntlHelmet title={sharedMessages.oauthClients} />
<Col>
<PageTitle title={sharedMessages.oauthClients} hideHeading />
<ClientsTable pageSize={PAGE_SIZES.REGULAR} />
</Col>
</Row>
</Container>
</RequireRequest>
)
}

export default ClientsList
Loading
Loading