2018-06-26 14:21:38 +00:00
|
|
|
export default class FilteredSearchTokenKeys {
|
2018-08-28 10:58:15 +00:00
|
|
|
constructor(tokenKeys = [], alternativeTokenKeys = [], conditions = []) {
|
|
|
|
this.tokenKeys = tokenKeys;
|
|
|
|
this.alternativeTokenKeys = alternativeTokenKeys;
|
|
|
|
this.conditions = conditions;
|
2017-01-24 20:03:39 +00:00
|
|
|
|
2018-06-26 14:21:38 +00:00
|
|
|
this.tokenKeysWithAlternative = this.tokenKeys.concat(this.alternativeTokenKeys);
|
|
|
|
}
|
2016-12-13 04:15:31 +00:00
|
|
|
|
2018-06-26 14:21:38 +00:00
|
|
|
get() {
|
|
|
|
return this.tokenKeys;
|
2017-04-17 07:01:11 +00:00
|
|
|
}
|
2016-12-13 04:15:31 +00:00
|
|
|
|
2018-06-26 14:21:38 +00:00
|
|
|
getKeys() {
|
|
|
|
return this.tokenKeys.map(i => i.key);
|
2017-05-23 16:35:54 +00:00
|
|
|
}
|
|
|
|
|
2018-06-26 14:21:38 +00:00
|
|
|
getAlternatives() {
|
|
|
|
return this.alternativeTokenKeys;
|
2017-04-17 07:01:11 +00:00
|
|
|
}
|
2017-01-24 20:03:39 +00:00
|
|
|
|
2018-06-26 14:21:38 +00:00
|
|
|
getConditions() {
|
|
|
|
return this.conditions;
|
2017-04-17 07:01:11 +00:00
|
|
|
}
|
2016-12-15 18:54:24 +00:00
|
|
|
|
2018-10-03 08:15:00 +00:00
|
|
|
shouldUppercaseTokenName(tokenKey) {
|
|
|
|
const token = this.searchByKey(tokenKey.toLowerCase());
|
|
|
|
return token && token.uppercaseTokenName;
|
|
|
|
}
|
|
|
|
|
|
|
|
shouldCapitalizeTokenValue(tokenKey) {
|
|
|
|
const token = this.searchByKey(tokenKey.toLowerCase());
|
|
|
|
return token && token.capitalizeTokenValue;
|
|
|
|
}
|
|
|
|
|
2018-06-26 14:21:38 +00:00
|
|
|
searchByKey(key) {
|
|
|
|
return this.tokenKeys.find(tokenKey => tokenKey.key === key) || null;
|
2017-04-17 07:01:11 +00:00
|
|
|
}
|
2016-12-13 04:15:31 +00:00
|
|
|
|
2018-06-26 14:21:38 +00:00
|
|
|
searchBySymbol(symbol) {
|
|
|
|
return this.tokenKeys.find(tokenKey => tokenKey.symbol === symbol) || null;
|
2017-04-17 07:01:11 +00:00
|
|
|
}
|
2016-12-13 04:15:31 +00:00
|
|
|
|
2018-06-26 14:21:38 +00:00
|
|
|
searchByKeyParam(keyParam) {
|
2018-10-10 06:18:49 +00:00
|
|
|
return (
|
|
|
|
this.tokenKeysWithAlternative.find(tokenKey => {
|
|
|
|
let tokenKeyParam = tokenKey.key;
|
2016-12-16 16:22:09 +00:00
|
|
|
|
2018-10-10 06:18:49 +00:00
|
|
|
// Replace hyphen with underscore to compare keyParam with tokenKeyParam
|
|
|
|
// e.g. 'my-reaction' => 'my_reaction'
|
|
|
|
tokenKeyParam = tokenKeyParam.replace('-', '_');
|
2017-08-30 07:48:55 +00:00
|
|
|
|
2018-10-10 06:18:49 +00:00
|
|
|
if (tokenKey.param) {
|
|
|
|
tokenKeyParam += `_${tokenKey.param}`;
|
|
|
|
}
|
2016-12-16 16:22:09 +00:00
|
|
|
|
2018-10-10 06:18:49 +00:00
|
|
|
return keyParam === tokenKeyParam;
|
|
|
|
}) || null
|
|
|
|
);
|
2017-04-17 07:01:11 +00:00
|
|
|
}
|
2016-12-13 04:15:31 +00:00
|
|
|
|
2018-06-26 14:21:38 +00:00
|
|
|
searchByConditionUrl(url) {
|
|
|
|
return this.conditions.find(condition => condition.url === url) || null;
|
2017-04-17 07:01:11 +00:00
|
|
|
}
|
2016-12-13 04:15:31 +00:00
|
|
|
|
2018-06-26 14:21:38 +00:00
|
|
|
searchByConditionKeyValue(key, value) {
|
2018-10-10 06:18:49 +00:00
|
|
|
return (
|
|
|
|
this.conditions.find(condition => condition.tokenKey === key && condition.value === value) ||
|
|
|
|
null
|
|
|
|
);
|
2016-11-30 18:30:52 +00:00
|
|
|
}
|
2018-10-03 08:15:00 +00:00
|
|
|
|
|
|
|
addExtraTokensForMergeRequests() {
|
|
|
|
const wipToken = {
|
|
|
|
key: 'wip',
|
|
|
|
type: 'string',
|
|
|
|
param: '',
|
|
|
|
symbol: '',
|
|
|
|
icon: 'admin',
|
|
|
|
tag: 'Yes or No',
|
|
|
|
lowercaseValueOnSubmit: true,
|
|
|
|
uppercaseTokenName: true,
|
|
|
|
capitalizeTokenValue: true,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.tokenKeys.push(wipToken);
|
|
|
|
this.tokenKeysWithAlternative.push(wipToken);
|
|
|
|
}
|
2017-04-17 07:01:11 +00:00
|
|
|
}
|