Files
mattermost-webapp/utils/admin_console_plugin_index.js
T
Pradeep Murugesan 8d18a0237e generated texts from the plugin settings and passed the same to gener… (#3619)
* generated texts from the plugin settings and passed the same to generate index

* show the plugin section in the sidebar when its filtered by the search

* refreshed plugin cache on new plugin or admin definition

* removed the unnecessary code

* changed to strict not equals

* fixed lint issues

* fix review comments

* fix review comments, changed the method signature.

* fix lint error

* ignored the markdown link text using strip markdown util

* test label field text extraction

* removed stripmarkdown from label and display_name. added stripmarkdown to header and footer

* changed the require to import for consistency

* added the enable plugin setting by default

* renamed EnablePluginSrtting to snake case

* index the enable plugin setting by default

* updated snapshot after merge
2019-11-02 08:59:39 +01:00

61 lines
1.8 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {stripMarkdown} from 'utils/markdown';
import getEnablePluginSetting from 'components/admin_console/custom_plugin_settings/enable_plugin_setting';
function extractTextsFromPlugin(plugin) {
const texts = extractTextFromSetting(getEnablePluginSetting(plugin));
if (plugin.name) {
texts.push(plugin.name);
}
if (plugin.id) {
texts.push(plugin.id);
}
if (plugin.settings_schema) {
if (plugin.settings_schema.footer) {
texts.push(stripMarkdown(plugin.settings_schema.footer));
}
if (plugin.settings_schema.header) {
texts.push(stripMarkdown(plugin.settings_schema.header));
}
if (plugin.settings_schema.settings) {
const settings = Object.values(plugin.settings_schema.settings);
for (const setting of settings) {
const settingsTexts = extractTextFromSetting(setting, texts);
texts.push(...settingsTexts);
}
}
}
return texts;
}
function extractTextFromSetting(setting) {
const texts = [];
if (setting.label) {
texts.push(setting.label);
}
if (setting.display_name) {
texts.push(setting.display_name);
}
if (setting.help_text) {
texts.push(stripMarkdown(setting.help_text));
}
if (setting.key) {
texts.push(setting.key);
}
return texts;
}
export function getPluginEntries(pluginsObj = {}) {
const entries = {};
const plugins = pluginsObj || {};
for (const pluginId of Object.keys(plugins)) {
const url = `plugin_${pluginId}`;
entries[url] = extractTextsFromPlugin(plugins[pluginId]);
}
return entries;
}