Skip to content

Commit

Permalink
[App Search] [Crawler] Add tooltip to explain path pattern (#114779)
Browse files Browse the repository at this point in the history
7.13.0 adds a wildcard character to (non-regex) path patterns. This change updates the UI help text to explain this.
  • Loading branch information
orhantoy authored Oct 13, 2021
1 parent a532ea5 commit fdd72a9
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ import React from 'react';

import { useActions } from 'kea';

import { EuiCode, EuiFieldText, EuiLink, EuiSelect, EuiText } from '@elastic/eui';
import {
EuiCode,
EuiFieldText,
EuiFlexGroup,
EuiFlexItem,
EuiIconTip,
EuiLink,
EuiSelect,
EuiText,
} from '@elastic/eui';

import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
Expand All @@ -27,6 +36,7 @@ import {
getReadableCrawlerPolicy,
getReadableCrawlerRule,
} from '../types';
import { getCrawlRulePathPatternTooltip } from '../utils';

interface CrawlRulesTableProps {
description?: React.ReactNode;
Expand Down Expand Up @@ -130,13 +140,24 @@ export const CrawlRulesTable: React.FC<CrawlRulesTableProps> = ({
},
{
editingRender: (crawlRule, onChange, { isInvalid, isLoading }) => (
<EuiFieldText
fullWidth
value={(crawlRule as CrawlRule).pattern}
onChange={(e) => onChange(e.target.value)}
disabled={isLoading}
isInvalid={isInvalid}
/>
<EuiFlexGroup alignItems="center" gutterSize="s" responsive={false}>
<EuiFlexItem>
<EuiFieldText
fullWidth
value={(crawlRule as CrawlRule).pattern}
onChange={(e) => onChange(e.target.value)}
disabled={isLoading}
isInvalid={isInvalid}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiIconTip
content={getCrawlRulePathPatternTooltip(crawlRule as CrawlRule)}
type="iInCircle"
position="top"
/>
</EuiFlexItem>
</EuiFlexGroup>
),
render: (crawlRule) => <EuiCode>{(crawlRule as CrawlRule).pattern}</EuiCode>,
name: i18n.translate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
crawlRequestServerToClient,
getDeleteDomainConfirmationMessage,
getDeleteDomainSuccessMessage,
getCrawlRulePathPatternTooltip,
} from './utils';

const DEFAULT_CRAWL_RULE: CrawlRule = {
Expand Down Expand Up @@ -292,3 +293,28 @@ describe('getDeleteDomainSuccessMessage', () => {
expect(getDeleteDomainSuccessMessage('https://elastic.co/')).toContain('https://elastic.co');
});
});

describe('getCrawlRulePathPatternTooltip', () => {
it('includes regular expression', () => {
const crawlRule: CrawlRule = {
id: '-',
policy: CrawlerPolicies.allow,
rule: CrawlerRules.regex,
pattern: '.*',
};

expect(getCrawlRulePathPatternTooltip(crawlRule)).toContain('regular expression');
});

it('includes meta', () => {
const crawlRule: CrawlRule = {
id: '-',
policy: CrawlerPolicies.allow,
rule: CrawlerRules.beginsWith,
pattern: '/elastic',
};

expect(getCrawlRulePathPatternTooltip(crawlRule)).not.toContain('regular expression');
expect(getCrawlRulePathPatternTooltip(crawlRule)).toContain('meta');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
CrawlerDomainValidationStep,
CrawlRequestFromServer,
CrawlRequest,
CrawlRule,
CrawlerRules,
CrawlEventFromServer,
CrawlEvent,
} from './types';
Expand Down Expand Up @@ -159,3 +161,23 @@ export const getDeleteDomainSuccessMessage = (domainUrl: string) => {
}
);
};

export const getCrawlRulePathPatternTooltip = (crawlRule: CrawlRule) => {
if (crawlRule.rule === CrawlerRules.regex) {
return i18n.translate(
'xpack.enterpriseSearch.appSearch.crawler.crawlRulesTable.regexPathPatternTooltip',
{
defaultMessage:
'The path pattern is a regular expression compatible with the Ruby language regular expression engine.',
}
);
}

return i18n.translate(
'xpack.enterpriseSearch.appSearch.crawler.crawlRulesTable.pathPatternTooltip',
{
defaultMessage:
'The path pattern is a literal string except for the asterisk (*) character, which is a meta character that will match anything.',
}
);
};

0 comments on commit fdd72a9

Please sign in to comment.