From 317709f46998a0951f06ffbbb892ab82ca172b29 Mon Sep 17 00:00:00 2001 From: Michael Klein Date: Wed, 3 Aug 2022 15:04:19 +0200 Subject: [PATCH] ui: peering UI fixes - api contract change / wrong link in peerings list (#14007) * Don't send `Datacenter` when establishing peer * Don't surface link to non-existing peers.edit route anymore --- .../app/components/consul/peer/list/index.hbs | 8 - .../consul-ui/app/services/repository/peer.js | 158 +++++++++--------- 2 files changed, 82 insertions(+), 84 deletions(-) diff --git a/ui/packages/consul-peerings/app/components/consul/peer/list/index.hbs b/ui/packages/consul-peerings/app/components/consul/peer/list/index.hbs index 3282b987c..16005e0b7 100644 --- a/ui/packages/consul-peerings/app/components/consul/peer/list/index.hbs +++ b/ui/packages/consul-peerings/app/components/consul/peer/list/index.hbs @@ -42,14 +42,6 @@ as |item index|> {{#if (can 'delete peer' item=item)}} - - - View - - {{#if (can "write peer" item=item)}} body) + ` + )((headers, body, cache) => body); } @dataSource('/:partition/:ns/:dc/peers') async fetchAll({ dc, ns, partition }, { uri }, request) { - return (await request` + return ( + await request` GET /v1/peerings ${{ partition, }} - `)( - (headers, body, cache) => { - return { - meta: { - version: 2, - interval: 10000, - uri: uri, - }, - body: body.map(item => { - return cache( - { - ...item, - Datacenter: dc, - Partition: partition, - }, - uri => uri`peer:///${partition}/${ns}/${dc}/peer/${item.Name}` - ); - }) - }; - }); + ` + )((headers, body, cache) => { + return { + meta: { + version: 2, + interval: 10000, + uri: uri, + }, + body: body.map(item => { + return cache( + { + ...item, + Datacenter: dc, + Partition: partition, + }, + uri => uri`peer:///${partition}/${ns}/${dc}/peer/${item.Name}` + ); + }), + }; + }); } @dataSource('/:partition/:ns/:dc/peer/:name') - async fetchOne({partition, ns, dc, name}, { uri }, request) { + async fetchOne({ partition, ns, dc, name }, { uri }, request) { if (name === '') { return this.create({ Datacenter: dc, @@ -59,59 +60,62 @@ export default class PeerService extends RepositoryService { Partition: partition, }); } - return (await request` + return ( + await request` GET /v1/peering/${name} ${{ partition, }} - `)((headers, body, cache) => { - return { - meta: { - version: 2, - interval: 10000, - uri: uri, + ` + )((headers, body, cache) => { + return { + meta: { + version: 2, + interval: 10000, + uri: uri, + }, + body: cache( + { + ...body, + Datacenter: dc, + Partition: partition, }, - body: cache( - { - ...body, - Datacenter: dc, - Partition: partition, - }, - uri => uri`peer:///${partition}/${ns}/${dc}/peer/${body.Name}` - ) - }; + uri => uri`peer:///${partition}/${ns}/${dc}/peer/${body.Name}` + ), + }; }); } async persist(item, request) { // mark it as ESTABLISHING ourselves as the request is successful // and we don't have blocking queries here to get immediate updates - return (await request` + return ( + await request` POST /v1/peering/establish ${{ PeerName: item.Name, PeeringToken: item.PeeringToken, - Datacenter: item.Datacenter, Partition: item.Partition || undefined, }} - `)((headers, body, cache) => { - const partition = item.Partition; - const ns = item.Namespace; - const dc = item.Datacenter; - return { - meta: { - version: 2, + ` + )((headers, body, cache) => { + const partition = item.Partition; + const ns = item.Namespace; + const dc = item.Datacenter; + return { + meta: { + version: 2, + }, + body: cache( + { + ...item, + State: 'ESTABLISHING', }, - body: cache( - { - ...item, - State: 'ESTABLISHING' - }, - uri => uri`peer:///${partition}/${ns}/${dc}/peer/${item.Name}` - ) - }; + uri => uri`peer:///${partition}/${ns}/${dc}/peer/${item.Name}` + ), + }; }); } @@ -120,24 +124,26 @@ export default class PeerService extends RepositoryService { // we just return the item we want to delete // but mark it as DELETING ourselves as the request is successful // and we don't have blocking queries here to get immediate updates - return (await request` + return ( + await request` DELETE /v1/peering/${item.Name} - `)((headers, body, cache) => { - const partition = item.Partition; - const ns = item.Namespace; - const dc = item.Datacenter; - return { - meta: { - version: 2, + ` + )((headers, body, cache) => { + const partition = item.Partition; + const ns = item.Namespace; + const dc = item.Datacenter; + return { + meta: { + version: 2, + }, + body: cache( + { + ...item, + State: 'DELETING', }, - body: cache( - { - ...item, - State: 'DELETING' - }, - uri => uri`peer:///${partition}/${ns}/${dc}/peer/${item.Name}` - ) - }; + uri => uri`peer:///${partition}/${ns}/${dc}/peer/${item.Name}` + ), + }; }); } }