From a0d12ff16430d718519a43aa811145ce13c8416a Mon Sep 17 00:00:00 2001
From: Kenia <19161242+kaxcode@users.noreply.github.com>
Date: Wed, 7 Apr 2021 12:43:04 -0400
Subject: [PATCH] ui: Reformat MaxTokenTTL to sortBy as an integer (#9969)
* Install Duration JS
* Use Duration.js to sortBy reformatted MaxTokenTTL
* Remove @icholy/duration package
* Install parse-duration package
* Use parse-duration in auth-method model
---
.../components/consul/auth-method/search-bar/index.hbs | 8 ++++----
ui/packages/consul-ui/app/models/auth-method.js | 7 +++++++
ui/packages/consul-ui/app/sort/comparators/auth-method.js | 2 +-
ui/packages/consul-ui/package.json | 1 +
ui/yarn.lock | 5 +++++
5 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/ui/packages/consul-ui/app/components/consul/auth-method/search-bar/index.hbs b/ui/packages/consul-ui/app/components/consul/auth-method/search-bar/index.hbs
index 2e7e5313fa..ec8b98336b 100644
--- a/ui/packages/consul-ui/app/components/consul/auth-method/search-bar/index.hbs
+++ b/ui/packages/consul-ui/app/components/consul/auth-method/search-bar/index.hbs
@@ -122,8 +122,8 @@ as |key value|}}
{{#let (from-entries (array
(array "MethodName:asc" (t "common.sort.alpha.asc"))
(array "MethodName:desc" (t "common.sort.alpha.desc"))
- (array "MaxTokenTTL:desc" (t "common.sort.duration.asc"))
- (array "MaxTokenTTL:asc" (t "common.sort.duration.desc"))
+ (array "TokenTTL:desc" (t "common.sort.duration.asc"))
+ (array "TokenTTL:asc" (t "common.sort.duration.desc"))
))
as |selectable|
}}
@@ -138,8 +138,8 @@ as |key value|}}
{{/let}}
diff --git a/ui/packages/consul-ui/app/models/auth-method.js b/ui/packages/consul-ui/app/models/auth-method.js
index 38da49b629..c264231816 100644
--- a/ui/packages/consul-ui/app/models/auth-method.js
+++ b/ui/packages/consul-ui/app/models/auth-method.js
@@ -1,5 +1,7 @@
import Model, { attr } from '@ember-data/model';
import { or } from '@ember/object/computed';
+import parse from 'parse-duration';
+import { computed } from '@ember/object';
export const PRIMARY_KEY = 'uid';
export const SLUG_KEY = 'Name';
@@ -22,4 +24,9 @@ export default class AuthMethod extends Model {
@attr('number') ModifyIndex;
@attr() Datacenters; // string[]
@attr() meta; // {}
+
+ @computed('MaxTokenTTL')
+ get TokenTTL() {
+ return parse(this.MaxTokenTTL);
+ }
}
diff --git a/ui/packages/consul-ui/app/sort/comparators/auth-method.js b/ui/packages/consul-ui/app/sort/comparators/auth-method.js
index fafacd3fff..56bbc1c2b2 100644
--- a/ui/packages/consul-ui/app/sort/comparators/auth-method.js
+++ b/ui/packages/consul-ui/app/sort/comparators/auth-method.js
@@ -1,3 +1,3 @@
export default ({ properties }) => (key = 'MethodName:asc') => {
- return properties(['MethodName', 'MaxTokenTTL'])(key);
+ return properties(['MethodName', 'TokenTTL'])(key);
};
diff --git a/ui/packages/consul-ui/package.json b/ui/packages/consul-ui/package.json
index 3939c98d88..f776022db5 100644
--- a/ui/packages/consul-ui/package.json
+++ b/ui/packages/consul-ui/package.json
@@ -150,6 +150,7 @@
"loader.js": "^4.7.0",
"mnemonist": "^0.38.0",
"ngraph.graph": "^19.1.0",
+ "parse-duration": "^1.0.0",
"pretender": "^3.2.0",
"prettier": "^1.10.2",
"qunit-dom": "^1.0.0",
diff --git a/ui/yarn.lock b/ui/yarn.lock
index 8e75fa2a4f..ac319b71d8 100644
--- a/ui/yarn.lock
+++ b/ui/yarn.lock
@@ -11046,6 +11046,11 @@ parse-asn1@^5.0.0, parse-asn1@^5.1.5:
pbkdf2 "^3.0.3"
safe-buffer "^5.1.1"
+parse-duration@^1.0.0:
+ version "1.0.0"
+ resolved "https://registry.yarnpkg.com/parse-duration/-/parse-duration-1.0.0.tgz#8605651745f61088f6fb14045c887526c291858c"
+ integrity sha512-X4kUkCTHU1N/kEbwK9FpUJ0UZQa90VzeczfS704frR30gljxDG0pSziws06XlK+CGRSo/1wtG1mFIdBFQTMQNw==
+
parse-entities@^1.1.0:
version "1.2.2"
resolved "https://registry.yarnpkg.com/parse-entities/-/parse-entities-1.2.2.tgz#c31bf0f653b6661354f8973559cb86dd1d5edf50"