Skip to content

Commit d09bc1e

Browse files
authored
Merge pull request #7576 from TheThingsNetwork/fix/webhook-pubsub-pagination-console
Add pagination to webhooks and pubsubs
2 parents a3539ff + 5c3875e commit d09bc1e

File tree

10 files changed

+36
-22
lines changed

10 files changed

+36
-22
lines changed

pkg/webui/components/pagination/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ const Pagination = ({
100100

101101
// Don't show page size select if there are less than 20 items.
102102
// 20 is the smallest amount of items that can be displayed per page.
103-
if (totalCount < 20) {
103+
if (totalCount < propPageSize) {
104104
return null
105105
}
106106

pkg/webui/console/containers/pubsubs-table/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const getItemPathPrefix = item => `${item.ids.pub_sub_id}`
8484
const PubsubsTable = () => {
8585
const { appId } = useParams()
8686

87-
const getItemsAction = useCallback(() => getPubsubsList(appId), [appId])
87+
const getItemsAction = useCallback(filters => getPubsubsList(appId, { ...filters }), [appId])
8888

8989
const baseDataSelector = createSelector(
9090
[selectPubsubs, selectPubsubsTotalCount],
@@ -104,7 +104,6 @@ const PubsubsTable = () => {
104104
baseDataSelector={baseDataSelector}
105105
tableTitle={<Message content={sharedMessages.pubsubs} />}
106106
getItemPathPrefix={getItemPathPrefix}
107-
paginated={false}
108107
handlesSorting
109108
/>
110109
)

pkg/webui/console/containers/webhooks-table/index.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const WebhooksTable = () => {
4545
const { appId } = useParams()
4646
const healthStatusEnabled = useSelector(selectWebhooksHealthStatusEnabled)
4747
const getWebhooksListCallback = useCallback(
48-
() => getWebhooksList(appId, ['template_ids', 'health_status', 'paused']),
48+
filters => getWebhooksList(appId, ...filters, ['template_ids', 'health_status', 'paused']),
4949
[appId],
5050
)
5151

@@ -131,7 +131,6 @@ const WebhooksTable = () => {
131131
getItemsAction={getWebhooksListCallback}
132132
baseDataSelector={baseDataSelector}
133133
tableTitle={<Message content={sharedMessages.webhooks} />}
134-
paginated={false}
135134
handlesSorting
136135
/>
137136
)

pkg/webui/console/store/actions/pubsubs.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
// limitations under the License.
1414

1515
import createRequestActions from '@ttn-lw/lib/store/actions/create-request-actions'
16+
import {
17+
createPaginationBaseActionType,
18+
createPaginationByIdRequestActions,
19+
} from '@ttn-lw/lib/store/actions/pagination'
1620

1721
export const CREATE_PUBSUB_BASE = 'CREATE_PUBSUB'
1822
export const [
@@ -30,15 +34,15 @@ export const [
3034
(appId, pubsubId, selector) => ({ selector }),
3135
)
3236

33-
export const GET_PUBSUBS_LIST_BASE = 'GET_PUBSUBS_LIST'
37+
export const GET_PUBSUBS_LIST_BASE = createPaginationBaseActionType('PUBSUB')
3438
export const [
3539
{
3640
request: GET_PUBSUBS_LIST,
3741
success: GET_PUBSUBS_LIST_SUCCESS,
3842
failure: GET_PUBSUBS_LIST_FAILURE,
3943
},
4044
{ request: getPubsubsList, success: getPubsubsListSuccess, failure: getPubsubsListFailure },
41-
] = createRequestActions(GET_PUBSUBS_LIST_BASE, appId => ({ appId }))
45+
] = createPaginationByIdRequestActions('PUBSUB')
4246

4347
export const UPDATE_PUBSUB_BASE = 'UPDATE_PUBSUB'
4448
export const [

pkg/webui/console/store/actions/webhooks.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
// limitations under the License.
1414

1515
import createRequestActions from '@ttn-lw/lib/store/actions/create-request-actions'
16+
import {
17+
createPaginationBaseActionType,
18+
createPaginationByIdRequestActions,
19+
} from '@ttn-lw/lib/store/actions/pagination'
1620

1721
export const GET_WEBHOOK_BASE = 'GET_WEBHOOK'
1822
export const [
@@ -24,19 +28,15 @@ export const [
2428
(appId, webhookId, selector) => ({ selector }),
2529
)
2630

27-
export const GET_WEBHOOKS_LIST_BASE = 'GET_WEBHOOKS_LIST'
31+
export const GET_WEBHOOKS_LIST_BASE = createPaginationBaseActionType('WEBHOOKS')
2832
export const [
2933
{
3034
request: GET_WEBHOOKS_LIST,
3135
success: GET_WEBHOOKS_LIST_SUCCESS,
3236
failure: GET_WEBHOOKS_LIST_FAILURE,
3337
},
3438
{ request: getWebhooksList, success: getWebhooksListSuccess, failure: getWebhooksListFailure },
35-
] = createRequestActions(
36-
GET_WEBHOOKS_LIST_BASE,
37-
appId => ({ appId }),
38-
(appId, selector) => ({ selector }),
39-
)
39+
] = createPaginationByIdRequestActions('WEBHOOKS')
4040

4141
export const UPDATE_WEBHOOK_BASE = 'UPDATE_WEBHOOK'
4242
export const [

pkg/webui/console/store/middleware/logics/pubsubs.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,12 @@ const getPubsubLogic = createRequestLogic({
4343
const getPubsubsLogic = createRequestLogic({
4444
type: pubsubs.GET_PUBSUBS_LIST,
4545
process: async ({ action }) => {
46-
const { appId } = action.payload
47-
const res = await tts.Applications.PubSubs.getAll(appId)
46+
const {
47+
id: appId,
48+
params: { page, limit, order },
49+
} = action.payload
50+
const { selectors } = action.meta
51+
const res = await tts.Applications.PubSubs.getAll(appId, { page, limit, order }, selectors)
4852

4953
return { entities: res.pubsubs, totalCount: res.totalCount }
5054
},

pkg/webui/console/store/middleware/logics/webhooks.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ const getWebhooksLogic = createRequestLogic({
3636
type: webhooks.GET_WEBHOOKS_LIST,
3737
process: async ({ action }) => {
3838
const {
39-
payload: { appId },
40-
meta: { selector },
41-
} = action
42-
const res = await tts.Applications.Webhooks.getAll(appId, selector)
39+
id: appId,
40+
params: { page, limit },
41+
} = action.payload
42+
const { selectors } = action.meta
43+
44+
const res = await tts.Applications.Webhooks.getAll(appId, { page, limit }, selectors)
4345

4446
return { entities: res.webhooks, totalCount: res.totalCount }
4547
},

pkg/webui/console/store/reducers/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ export default combineReducers({
133133
getPacketBrokerNetworkId,
134134
),
135135
clients: createNamedPaginationReducer('CLIENTS', getClientId),
136+
pubsubs: createNamedPaginationReducer('PUBSUB', getApplicationId),
137+
webhooks: createNamedPaginationReducer('WEBHOOKS', getApplicationId),
136138
}),
137139
js,
138140
gatewayStatus,

sdk/js/src/service/pubsubs.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ class PubSub {
5454
}
5555
}
5656

57-
async getAll(appId, selector) {
57+
async getAll(appId, params, selector) {
5858
const result = await this._api.List(
5959
{
6060
routeParams: { 'application_ids.application_id': appId },
6161
},
6262
{
63+
...params,
6364
...Marshaler.selectorToFieldMask(selector),
6465
},
6566
)

sdk/js/src/service/webhooks.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ class Webhooks {
2222
autoBind(this)
2323
}
2424

25-
async getAll(appId, selector) {
25+
async getAll(appId, params, selector) {
2626
const fieldMask = Marshaler.selectorToFieldMask(selector)
2727
const result = await this._api.List(
2828
{
2929
routeParams: { 'application_ids.application_id': appId },
3030
},
31-
fieldMask,
31+
{
32+
...params,
33+
...fieldMask,
34+
},
3235
)
3336

3437
return Marshaler.payloadListResponse('webhooks', result)

0 commit comments

Comments
 (0)