diff --git a/ui/lib/core/addon/components/ttl-picker2.js b/ui/lib/core/addon/components/ttl-picker2.js
index 808183d77b..622b255d81 100644
--- a/ui/lib/core/addon/components/ttl-picker2.js
+++ b/ui/lib/core/addon/components/ttl-picker2.js
@@ -18,6 +18,7 @@
* @param recalculationTimeout=5000 {Number} - This is the time, in milliseconds, that `recalculateSeconds` will be be true after time is updated
* @param initialValue=null {String} - This is the value set initially (particularly from a string like '30h')
* @param initialEnabled=null {Boolean} - Set this value if you want the toggle on when component is mounted
+ * @param changeOnInit=false {Boolean} - set this value if you'd like the passed onChange function to be called on component initialization
*/
import Ember from 'ember';
@@ -34,6 +35,7 @@ const secondsMap = {
h: 3600,
d: 86400,
};
+const validUnits = ['s', 'm', 'h', 'd'];
const convertToSeconds = (time, unit) => {
return time * secondsMap[unit];
};
@@ -52,37 +54,54 @@ export default Component.extend({
unit: 's',
recalculationTimeout: 5000,
initialValue: null,
+ changeOnInit: false,
init() {
this._super(...arguments);
const value = this.initialValue;
const enable = this.initialEnabled;
+ const changeOnInit = this.changeOnInit;
// if initial value is unset use params passed in as defaults
if (!value && value !== 0) {
return;
}
- let seconds = 30;
+ let time = 30;
+ let unit = 's';
let setEnable = this.enableTTL;
if (!!enable || typeOf(enable) === 'boolean') {
// This allows non-boolean values passed in to be evaluated for truthiness
setEnable = !!enable;
}
+
if (typeOf(value) === 'number') {
- seconds = value;
+ // if the passed value is a number, assume unit is seconds
+ time = value;
} else {
try {
- seconds = Duration.parse(value).seconds();
+ const seconds = Duration.parse(value).seconds();
+ const lastDigit = value.toString().substring(value.length - 1);
+ if (validUnits.indexOf(lastDigit) >= 0 && lastDigit !== 's') {
+ time = convertFromSeconds(seconds, lastDigit);
+ unit = lastDigit;
+ } else {
+ time = seconds;
+ }
} catch (e) {
console.error(e);
- // if parsing fails leave as default 30
+ // if parsing fails leave as default 30s
}
}
+
this.setProperties({
- time: seconds,
- unit: 's',
+ time,
+ unit,
enableTTL: setEnable,
});
+
+ if (changeOnInit) {
+ this.handleChange();
+ }
},
unitOptions: computed(function() {
diff --git a/ui/lib/core/stories/ttl-picker2.md b/ui/lib/core/stories/ttl-picker2.md
index eb12ce2650..a827de7c51 100644
--- a/ui/lib/core/stories/ttl-picker2.md
+++ b/ui/lib/core/stories/ttl-picker2.md
@@ -21,6 +21,7 @@ TtlPicker2 components are used to enable and select time to live values. Use thi
| recalculationTimeout | Number | 5000 | This is the time, in milliseconds, that `recalculateSeconds` will be be true after time is updated |
| initialValue | String | | This is the value set initially (particularly from a string like '30h') |
| initialEnabled | Boolean | | Set this value if you want the toggle on when component is mounted |
+| changeOnInit | Boolean | false | set this value if you'd like the passed onChange function to be called on component initialization |
**Example**
diff --git a/ui/lib/replication/addon/controllers/mode/secondaries/add.js b/ui/lib/replication/addon/controllers/mode/secondaries/add.js
index 6a80887200..09d290a793 100644
--- a/ui/lib/replication/addon/controllers/mode/secondaries/add.js
+++ b/ui/lib/replication/addon/controllers/mode/secondaries/add.js
@@ -1,3 +1,9 @@
import ReplicationController from 'replication/controllers/application';
-export default ReplicationController.extend();
+export default ReplicationController.extend({
+ actions: {
+ updateTtl: function(ttl) {
+ this.set('ttl', `${ttl.seconds}s`);
+ },
+ },
+});
diff --git a/ui/lib/replication/addon/templates/mode/secondaries/add.hbs b/ui/lib/replication/addon/templates/mode/secondaries/add.hbs
index c984ba44ee..2a46cc1bae 100644
--- a/ui/lib/replication/addon/templates/mode/secondaries/add.hbs
+++ b/ui/lib/replication/addon/templates/mode/secondaries/add.hbs
@@ -18,11 +18,14 @@
- This is the Time To Live for the generated secondary token. After this period, the generated token will no longer be valid. -
+