John Cowen 8c0473a622
ui: [BUGFIX] Ensure namespace is used for node API requests (#9410)
Nodes themselves are not namespaced, so we'd originally assumed we did not need to pass through the ns query parameter when listing or viewing nodes.

As it turns out the API endpoints we use to list and view nodes (and related things) return things that are namespaced, therefore any API requests for nodes do require a the ns query parameter to be passed through to the request.

This PR adds the necessary ns query param to all things Node, apart from the querying for the leader which only returns node related information.

Additionally here we decided to show 0 Services text in the node listing if there are nodes with no service instances within the namespace you are viewing, as this is clearer than showing nothing at all. We also cleaned up/standardized the text we use to in the empty state for service instances.
2021-01-04 16:42:44 +00:00

61 lines
1.6 KiB
JavaScript

import Adapter from './application';
// TODO: Update to use this.formatDatacenter()
// Node and Namespaces are a little strange in that Nodes don't belong in a
// namespace whereas things that belong to a Node do (Health Checks and
// Service Instances). So even though Nodes themselves don't require a
// namespace filter, you sill needs to pass the namespace through to API
// requests in order to get the correct information for the things that belong
// to the node.
export default class NodeAdapter extends Adapter {
requestForQuery(request, { dc, ns, index, id, uri }) {
return request`
GET /v1/internal/ui/nodes?${{ dc }}
X-Request-ID: ${uri}
${{
...this.formatNspace(ns),
index,
}}
`;
}
requestForQueryRecord(request, { dc, ns, index, id, uri }) {
if (typeof id === 'undefined') {
throw new Error('You must specify an id');
}
return request`
GET /v1/internal/ui/node/${id}?${{ dc }}
X-Request-ID: ${uri}
${{
...this.formatNspace(ns),
index,
}}
`;
}
requestForQueryLeader(request, { dc, uri }) {
return request`
GET /v1/status/leader?${{ dc }}
X-Request-ID: ${uri}
Refresh: 30
`;
}
queryLeader(store, type, id, snapshot) {
return this.rpc(
function(adapter, request, serialized, unserialized) {
return adapter.requestForQueryLeader(request, serialized, unserialized);
},
function(serializer, respond, serialized, unserialized) {
return serializer.respondForQueryLeader(respond, serialized, unserialized);
},
snapshot,
type.modelName
);
}
}