2023-03-14 13:18:55 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
* SPDX-License-Identifier: BUSL-1.1
|
2023-03-14 13:18:55 +00:00
|
|
|
*/
|
|
|
|
|
2020-06-03 16:07:49 +00:00
|
|
|
import Service from '@ember/service';
|
2020-11-10 14:36:27 +00:00
|
|
|
import service from 'consul-ui/sort/comparators/service';
|
|
|
|
import serviceInstance from 'consul-ui/sort/comparators/service-instance';
|
2020-11-12 18:45:11 +00:00
|
|
|
import upstreamInstance from 'consul-ui/sort/comparators/upstream-instance';
|
2020-11-10 14:36:27 +00:00
|
|
|
import kv from 'consul-ui/sort/comparators/kv';
|
2020-12-07 09:14:30 +00:00
|
|
|
import healthCheck from 'consul-ui/sort/comparators/health-check';
|
2020-11-10 14:36:27 +00:00
|
|
|
import intention from 'consul-ui/sort/comparators/intention';
|
|
|
|
import token from 'consul-ui/sort/comparators/token';
|
|
|
|
import role from 'consul-ui/sort/comparators/role';
|
|
|
|
import policy from 'consul-ui/sort/comparators/policy';
|
2021-02-17 18:56:56 +00:00
|
|
|
import authMethod from 'consul-ui/sort/comparators/auth-method';
|
2020-11-10 14:36:27 +00:00
|
|
|
import nspace from 'consul-ui/sort/comparators/nspace';
|
2022-07-04 10:31:58 +00:00
|
|
|
import peer from 'consul-ui/sort/comparators/peer';
|
2020-11-10 14:36:27 +00:00
|
|
|
import node from 'consul-ui/sort/comparators/node';
|
|
|
|
|
2020-11-19 16:06:39 +00:00
|
|
|
// returns an array of Property:asc, Property:desc etc etc
|
2022-09-15 08:43:17 +00:00
|
|
|
const directionify = (arr) => {
|
2020-11-19 16:06:39 +00:00
|
|
|
return arr.reduce((prev, item) => prev.concat([`${item}:asc`, `${item}:desc`]), []);
|
|
|
|
};
|
|
|
|
// Specify a list of sortable properties, when called with a property
|
|
|
|
// returns an array ready to be passed to ember @sort
|
|
|
|
// properties(['Potential', 'Sortable', 'Properties'])('Sortable:asc') => ['Sortable:asc']
|
2022-09-15 08:43:17 +00:00
|
|
|
export const properties =
|
|
|
|
(props = []) =>
|
|
|
|
(key) => {
|
|
|
|
const comparables = directionify(props);
|
|
|
|
return [comparables.find((item) => item === key) || comparables[0]];
|
|
|
|
};
|
2020-11-19 16:06:39 +00:00
|
|
|
const options = {
|
|
|
|
properties,
|
|
|
|
directionify,
|
|
|
|
};
|
2020-11-10 14:36:27 +00:00
|
|
|
const comparators = {
|
2020-11-19 16:06:39 +00:00
|
|
|
service: service(options),
|
2020-12-01 15:45:09 +00:00
|
|
|
['service-instance']: serviceInstance(options),
|
2020-11-19 16:06:39 +00:00
|
|
|
['upstream-instance']: upstreamInstance(options),
|
2020-12-07 09:14:30 +00:00
|
|
|
['health-check']: healthCheck(options),
|
2021-02-17 18:56:56 +00:00
|
|
|
['auth-method']: authMethod(options),
|
2020-11-19 16:06:39 +00:00
|
|
|
kv: kv(options),
|
|
|
|
intention: intention(options),
|
|
|
|
token: token(options),
|
|
|
|
role: role(options),
|
|
|
|
policy: policy(options),
|
|
|
|
nspace: nspace(options),
|
2022-07-04 10:31:58 +00:00
|
|
|
peer: peer(options),
|
2020-11-19 16:06:39 +00:00
|
|
|
node: node(options),
|
2020-11-10 14:36:27 +00:00
|
|
|
};
|
2020-11-09 09:25:35 +00:00
|
|
|
export default class SortService extends Service {
|
2020-11-10 14:36:27 +00:00
|
|
|
comparator(type) {
|
|
|
|
return comparators[type];
|
|
|
|
}
|
2020-11-09 09:25:35 +00:00
|
|
|
}
|