diff --git a/pkg/webui/console/api/index.js b/pkg/webui/console/api/index.js index 166b17e26a..87be99b498 100644 --- a/pkg/webui/console/api/index.js +++ b/pkg/webui/console/api/index.js @@ -105,6 +105,12 @@ export default { gateways: { list: ttnClient.Gateways.getAll.bind(ttnClient.Gateways), }, + gateway: { + get: ttnClient.Gateways.getById.bind(ttnClient.Gateways), + 'delete': ttnClient.Gateways.deleteById.bind(ttnClient.Gateways), + create: ttnClient.Gateways.create.bind(ttnClient.Gateways), + update: ttnClient.Gateways.updateById.bind(ttnClient.Gateways), + }, rights: { applications: ttnClient.Applications.getRightsById.bind(ttnClient.Applications), }, diff --git a/pkg/webui/console/store/middleware/gateways.js b/pkg/webui/console/store/middleware/gateways.js index 2d55cf18d1..2f7930e4fd 100644 --- a/pkg/webui/console/store/middleware/gateways.js +++ b/pkg/webui/console/store/middleware/gateways.js @@ -20,20 +20,22 @@ import * as gateways from '../actions/gateways' const getGatewaysLogic = createLogic({ type: [ gateways.GET_GTWS_LIST, - gateways.CHANGE_GTWS_ORDER, - gateways.CHANGE_GTWS_PAGE, gateways.SEARCH_GTWS_LIST, ], latest: true, async process ({ getState, action }, dispatch, done) { - const { filters } = action + const { page, pageSize: limit, query } = action.filters try { - const data = filters.query - ? await api.gateways.search(filters) - : await api.gateways.list(filters) - const gtws = data.gateways.map(g => ({ ...g, antennasCount: g.antennas.length })) - dispatch(gateways.getGatewaysSuccess(gtws, data.totalCount)) + const data = query + ? await api.gateways.search({ + page, + limit, + id_contains: query, + name_contains: query, + }) + : await api.gateways.list({ page, limit }, [ 'name,description,frequency_plan_id' ]) + dispatch(gateways.getGatewaysSuccess(data.gateways, data.totalCount)) } catch (error) { dispatch(gateways.getGatewaysFailure(error)) } diff --git a/sdk/js/src/service/applications.js b/sdk/js/src/service/applications.js index 125a391e5c..7a3a3ccf5f 100644 --- a/sdk/js/src/service/applications.js +++ b/sdk/js/src/service/applications.js @@ -136,9 +136,11 @@ class Applications { // Delete async deleteById (applicationId) { - return this._api.ApplicationRegistry.Delete({ + const response = await this._api.ApplicationRegistry.Delete({ routeParams: { application_id: applicationId }, }) + + return Marshaler.payloadSingleResponse(response) } async getRightsById (applicationId) { diff --git a/sdk/js/src/service/gateways.js b/sdk/js/src/service/gateways.js index 13adf8475f..2f94ee01eb 100644 --- a/sdk/js/src/service/gateways.js +++ b/sdk/js/src/service/gateways.js @@ -17,13 +17,63 @@ import Marshaler from '../util/marshaler' class Gateways { constructor (api, { defaultUserId, stackConfig, proxy = true }) { this._api = api + this._defaultUserId = defaultUserId } - async getAll (params) { - const response = await this._api.GatewayRegistry.List(undefined, params) + // Retrieval + + async getAll (params, selector) { + const response = await this._api.GatewayRegistry.List(undefined, { + ...params, + ...Marshaler.selectorToFieldMask(selector), + }) return Marshaler.unwrapGateways(response) } + + async getById (id, selector) { + const fieldMask = Marshaler.selectorToFieldMask(selector) + const response = await this._api.GatewayRegistry.Get({ + routeParams: { 'gateway_ids.gateway_id': id }, + }, fieldMask) + + return Marshaler.unwrapGateway(response) + } + + // Update + + async updateById (id, patch, mask = Marshaler.fieldMaskFromPatch(patch)) { + const response = await this._api.GatewayRegistry.Update({ + routeParams: { 'gateway.ids.gateway_id': id }, + }, + { + gateway: patch, + field_mask: Marshaler.fieldMask(mask), + }) + + return Marshaler.unwrapGateway(response) + } + + // Create + + async create (userId = this._defaultUserId, gateway) { + const response = await this._api.GatewayRegistry.Create({ + routeParams: { 'collaborator.user_ids.user_id': userId }, + }, + { gateway }) + + return Marshaler.unwrapGateway(response) + } + + // Delete + + async deleteById (id) { + const response = await this._api.GatewayRegistry.Delete({ + routeParams: { gateway_id: id }, + }) + + return Marshaler.payloadSingleResponse(response) + } } export default Gateways diff --git a/sdk/js/src/util/marshaler.js b/sdk/js/src/util/marshaler.js index 469444db6f..33a0c31ccd 100644 --- a/sdk/js/src/util/marshaler.js +++ b/sdk/js/src/util/marshaler.js @@ -102,6 +102,10 @@ class Marshaler { return this.payloadListResponse('gateways', result, transform) } + static unwrapGateway (result, transform) { + return this.payloadSingleResponse(result, transform) + } + static fieldMaskFromPatch (patch) { return traverse(patch).paths().slice(1).map( e => e.join('.') ) }