Files
weave-scope/client/app/scripts/components/matched-results.js
Simon Howe 3c393c7808 Move truncation of docker ids to FE to allow full value in tooltips
- Reveals full id if you search for it.
- Difficult to copy and paste the full id if you want it for some reason
2016-09-28 12:18:12 +02:00

57 lines
1.5 KiB
JavaScript

import React from 'react';
import { connect } from 'react-redux';
import MatchedText from './matched-text';
const SHOW_ROW_COUNT = 2;
const MAX_MATCH_LENGTH = 24;
class MatchedResults extends React.Component {
renderMatch(matches, field) {
const match = matches.get(field);
const text = match.text;
return (
<div className="matched-results-match" key={match.label}>
<div className="matched-results-match-wrapper">
<span className="matched-results-match-label">
{match.label}:
</span>
<MatchedText text={text} match={match} maxLength={MAX_MATCH_LENGTH}
truncate={match.truncate} />
</div>
</div>
);
}
render() {
const { matches, style } = this.props;
if (!matches) {
return null;
}
let moreFieldMatches;
let moreFieldMatchesTitle;
if (matches.size > SHOW_ROW_COUNT) {
moreFieldMatches = matches
.valueSeq()
.skip(SHOW_ROW_COUNT)
.map(field => field.label);
moreFieldMatchesTitle = `More matches:\n${moreFieldMatches.join(',\n')}`;
}
return (
<div className="matched-results" style={style}>
{matches.keySeq().take(SHOW_ROW_COUNT).map(fieldId => this.renderMatch(matches, fieldId))}
{moreFieldMatches && <div className="matched-results-more" title={moreFieldMatchesTitle}>
{`${moreFieldMatches.size} more matches`}
</div>}
</div>
);
}
}
export default connect()(MatchedResults);