mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-28 17:51:21 +00:00
Add a search section to the help-popup
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { Map as makeMap } from 'immutable';
|
||||
import { Map as makeMap, Set as makeSet, List as makeList } from 'immutable';
|
||||
import _ from 'lodash';
|
||||
|
||||
import { slugify } from './string-utils';
|
||||
@@ -247,6 +247,40 @@ export function updateNodeMatches(state) {
|
||||
return state;
|
||||
}
|
||||
|
||||
|
||||
export function getSearchableFields(nodes) {
|
||||
const get = (node, key) => node.get(key) || makeList();
|
||||
|
||||
const baseLabels = makeSet(nodes.size > 0 ? SEARCH_FIELDS.valueSeq() : []);
|
||||
|
||||
const metadataLabels = nodes.reduce((labels, node) => (
|
||||
labels.union(get(node, 'metadata').map(f => f.get('label')))
|
||||
), makeSet());
|
||||
|
||||
const parentLabels = nodes.reduce((labels, node) => (
|
||||
labels.union(get(node, 'parents').map(p => p.get('topologyId')))
|
||||
), makeSet());
|
||||
|
||||
const tableRowLabels = nodes.reduce((labels, node) => (
|
||||
labels.union(get(node, 'tables').flatMap(t => (t.get('rows') || makeList)
|
||||
.map(f => f.get('label'))
|
||||
))
|
||||
), makeSet());
|
||||
|
||||
const metricLabels = nodes.reduce((labels, node) => (
|
||||
labels.union(get(node, 'metrics').map(f => f.get('label')))
|
||||
), makeSet());
|
||||
|
||||
return makeMap({
|
||||
fields: baseLabels.union(metadataLabels, parentLabels, tableRowLabels)
|
||||
.map(slugify)
|
||||
.toList()
|
||||
.sort(),
|
||||
metrics: metricLabels.toList().map(slugify).sort()
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set `filtered:true` in state's nodes if a pinned search matches
|
||||
*/
|
||||
|
||||
@@ -65,7 +65,7 @@ export const formatMetric = makeFormatMetric(renderHtml);
|
||||
export const formatMetricSvg = makeFormatMetric(renderSvg);
|
||||
export const formatDate = d3.time.format.iso;
|
||||
|
||||
const CLEAN_LABEL_REGEX = /\W/g;
|
||||
const CLEAN_LABEL_REGEX = /[^A-Za-z]/g;
|
||||
export function slugify(label) {
|
||||
return label.replace(CLEAN_LABEL_REGEX, '').toLowerCase();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user