@cxco/ui-faq
Version:
FAQ Module using @cxco default packages
89 lines (77 loc) • 2.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getFaqStateSettings = exports.DEFAULT_FAQ_PROPERTIES = exports.state = void 0;
var debug = require('debug')('cxco:ui-faq.state');
/**
* Initial State
*/
var state = {
categories: [],
faqs: [],
selectedCategories: [-1],
feedbackQueue: []
};
exports.state = state;
var DEFAULT_FAQ_PROPERTIES = {
classificationId: 1,
parentSelector: '[data-cxco-faq]',
classificationName: '',
showNumbering: false,
urlQuestion: 'help#{categoryname}/{faqid}/{question}',
maxBreakpoints: 3,
excludedCategories: [],
updateUrl: false,
urlProperties: {},
showFeedback: false,
feedback: {}
};
/**
* Default Feedback State values
*/
exports.DEFAULT_FAQ_PROPERTIES = DEFAULT_FAQ_PROPERTIES;
var DEFAULT_FEEDBACK_LABELS = {
intro: 'Was this article helpful?',
positive: 'yes',
negative: 'no',
thanks: 'thanks for leaving feedback.',
submit: 'submit feedback',
placeholder: 'What can we improve?'
};
/**
* Gets the properties defined in the config that should be applied to the state.
* These override the storage settings.
* @param {Object} config
*/
var getFaqStateSettings = function getFaqStateSettings(config) {
var settings = {};
try {
if (config) {
Object.keys(DEFAULT_FAQ_PROPERTIES).forEach(function (key) {
if (Object.prototype.hasOwnProperty.call(config, key)) {
debug("overrided FAQ mode setting: ".concat(key));
settings[key] = config[key];
} else {
settings[key] = DEFAULT_FAQ_PROPERTIES[key];
}
}); // add feedback
if (typeof config.feedback === 'undefined') {
settings.feedback = {};
} // TODO read config values.
Object.keys(DEFAULT_FEEDBACK_LABELS).forEach(function (key) {
if (config.feedback && Object.prototype.hasOwnProperty.call(config.feedback, key)) {
debug("overrided feedback mode setting: ".concat(key));
settings.feedback[key] = config.feedback[key];
} else {
// default values
settings.feedback[key] = DEFAULT_FEEDBACK_LABELS[key];
}
});
}
} catch (error) {
debug(error);
}
return settings;
};
exports.getFaqStateSettings = getFaqStateSettings;