Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[App Search] Add accordion lists for Domains, Seed URLs, and Sitemap URLs to Crawl Details Flyout #119682

Merged
merged 17 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.appSearchAccordion--bordered {
border: $euiBorderThin;
border-radius: $euiBorderRadius;
padding: $euiSizeM;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import '../../../../__mocks__/engine_logic.mock';

import React from 'react';

import { shallow, ShallowWrapper } from 'enzyme';

import { EuiAccordion, EuiIcon, EuiTitle, EuiInMemoryTable } from '@elastic/eui';

import { AccordionList } from './accordion_list';

const MOCK_PROPS = {
title: 'Test Items',
iconType: 'globe',
items: ['first item', 'second item'],
};

describe('AccordionList', () => {
let wrapper: ShallowWrapper;

beforeAll(() => {
wrapper = shallow(<AccordionList {...MOCK_PROPS} />);
});

it('renders as an accordion with the passed in title and icon', () => {
expect(wrapper.is(EuiAccordion)).toBe(true);

const buttonContent = shallow(wrapper.prop('buttonContent'));

expect(buttonContent.find(EuiIcon).prop('type')).toEqual('globe');
expect(buttonContent.find(EuiTitle).children().text()).toEqual('Test Items');
});

it('shows the item count', () => {
const extraActionContent = shallow(wrapper.prop('extraAction'));

expect(extraActionContent.text()).toEqual('2');
});

it('contains an table displaying the items', () => {
const table = wrapper.find(EuiInMemoryTable);

expect(table.prop('items')).toEqual([{ item: 'first item' }, { item: 'second item' }]);

expect(table.prop('columns')[0].render({ item: 'first item' })).toEqual('first item');
});

it('is disabled when there are no items', () => {
const disabledWrapper = shallow(<AccordionList {...{ ...MOCK_PROPS, items: [] }} />);

expect(disabledWrapper.prop('arrowProps').isDisabled).toEqual(true);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';

import {
EuiAccordion,
EuiFlexGroup,
EuiFlexItem,
EuiIcon,
EuiInMemoryTable,
EuiNotificationBadge,
EuiTitle,
IconType,
useGeneratedHtmlId,
} from '@elastic/eui';

import './accordion_list.scss';

interface Props {
iconType: IconType;
items: string[];
hasBorder?: boolean;
initialIsOpen?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • hasBorder allows the accordion to be rendered with or without a border and padding. I've got some designs in the works that will use be making use of this component in both scenarios.
  • initialIsOpen allows the accordion to be expanded. In this case specifically, we set the prop to true when items exist in the list.

title: string;
}

export const AccordionList: React.FC<Props> = ({ iconType, items, hasBorder, initialIsOpen, title }) => {
const accordionId = useGeneratedHtmlId({
prefix: 'accordionList',
});

return (
<EuiAccordion
initialIsOpen={initialIsOpen}
arrowProps={{
isDisabled: items.length === 0,
}}
className={hasBorder ? 'appSearchAccordion--bordered' : 'appSearchAccordion'}
buttonContent={
<EuiFlexGroup direction="row" responsive={false} gutterSize="s" alignItems="center">
<EuiFlexItem grow={false}>
<EuiIcon type={iconType} />
</EuiFlexItem>
<EuiFlexItem>
<EuiTitle size="s">
<h3>{title}</h3>
</EuiTitle>
</EuiFlexItem>
</EuiFlexGroup>
}
id={accordionId}
extraAction={<EuiNotificationBadge size="m">{items.length}</EuiNotificationBadge>}
>
<EuiInMemoryTable
items={items.map((item) => ({ item }))}
columns={[
{
render: ({ item }: { item: string }) => item,
},
]}
pagination={ items.length > 10 ? {
hidePerPageOptions: true,
} : false}
/>
</EuiAccordion>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const CrawlDetailsFlyout: React.FC = () => {
}

return (
<EuiFlyout ownFocus onClose={closeFlyout} aria-labelledby="CrawlDetailsFlyoutTitle">
<EuiFlyout maxWidth="45rem" ownFocus onClose={closeFlyout} aria-labelledby="CrawlDetailsFlyoutTitle">
<EuiFlyoutHeader hasBorder>
<EuiTitle size="m">
<h2 id="CrawlDetailsFlyoutTitle">
Expand Down Expand Up @@ -70,7 +70,7 @@ export const CrawlDetailsFlyout: React.FC = () => {
<>
{selectedTab === 'preview' && <CrawlDetailsPreview />}
{selectedTab === 'json' && (
<EuiCodeBlock language="json">
<EuiCodeBlock language="json" isCopyable>
{JSON.stringify(crawlRequestFromServer, null, 2)}
</EuiCodeBlock>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,77 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { setMockValues } from '../../../../../__mocks__/kea_logic';

import React from 'react';

import { shallow } from 'enzyme';
import { shallow, ShallowWrapper } from 'enzyme';

import { CrawlDetailValues } from '../../crawl_detail_logic';
import { CrawlerStatus, CrawlType } from '../../types';

import { AccordionList } from './accordion_list';
import { CrawlDetailsPreview } from './crawl_details_preview';

const MOCK_VALUES: Partial<CrawlDetailValues> = {
crawlRequest: {
id: '507f1f77bcf86cd799439011',
status: CrawlerStatus.Pending,
createdAt: 'Mon, 31 Aug 2020 17:00:00 +0000',
beganAt: null,
completedAt: null,
type: CrawlType.Full,
crawlConfig: {
domainAllowlist: ['https://www.elastic.co', 'https://www.swiftype.com'],
seedUrls: ['https://www.elastic.co/docs', 'https://www.swiftype.com/documentation'],
sitemapUrls: ['https://www.elastic.co/sitemap.xml', 'https://www.swiftype.com/sitemap.xml'],
},
},
};

describe('CrawlDetailsPreview', () => {
it('is empty', () => {
const wrapper = shallow(<CrawlDetailsPreview />);
it('is empty when a crawl request has not been loaded', () => {
setMockValues({
crawlRequest: null,
});

const wrapper = shallow(<CrawlDetailsPreview />);
expect(wrapper.isEmptyRender()).toBe(true);
});

describe('when a crawl request has been loaded', () => {
let wrapper: ShallowWrapper;

beforeAll(() => {
setMockValues(MOCK_VALUES);
wrapper = shallow(<CrawlDetailsPreview />);
});

it('contains a list of domains', () => {
const domainList = wrapper.find(AccordionList).at(0);

expect(domainList.prop('items')).toEqual([
'https://www.elastic.co',
'https://www.swiftype.com',
]);
});

it('contains a list of seed urls', () => {
const domainList = wrapper.find(AccordionList).at(1);

expect(domainList.prop('items')).toEqual([
'https://www.elastic.co/docs',
'https://www.swiftype.com/documentation',
]);
});

it('contains a list of sitemap urls', () => {
const domainList = wrapper.find(AccordionList).at(2);

expect(domainList.prop('items')).toEqual([
'https://www.elastic.co/sitemap.xml',
'https://www.swiftype.com/sitemap.xml',
]);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,62 @@

import React from 'react';

export const CrawlDetailsPreview: React.FC = () => null;
import { useValues } from 'kea';

import { EuiSpacer } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { CrawlDetailLogic } from '../../crawl_detail_logic';

import { AccordionList } from './accordion_list';

export const CrawlDetailsPreview: React.FC = () => {
const { crawlRequest } = useValues(CrawlDetailLogic);

if (crawlRequest === null) {
return null;
}

return (
<>
<AccordionList
hasBorder
initialIsOpen={crawlRequest.crawlConfig.domainAllowlist.length > 0}
title={i18n.translate(
'xpack.enterpriseSearch.appSearch.crawler.crawlDetailsPreview.domainsTitle',
{
defaultMessage: 'Domains',
}
)}
iconType="globe"
items={crawlRequest.crawlConfig.domainAllowlist}
/>
<EuiSpacer size="s" />
<AccordionList
hasBorder
initialIsOpen={crawlRequest.crawlConfig.seedUrls.length > 0}
title={i18n.translate(
'xpack.enterpriseSearch.appSearch.crawler.crawlDetailsPreview.seedUrlsTitle',
{
defaultMessage: 'Seed URLs',
}
)}
iconType="crosshairs"
items={crawlRequest.crawlConfig.seedUrls}
/>
<EuiSpacer size="s" />
<AccordionList
hasBorder
initialIsOpen={crawlRequest.crawlConfig.sitemapUrls.length > 0}
title={i18n.translate(
'xpack.enterpriseSearch.appSearch.crawler.crawlDetailsPreview.sitemapUrlsTitle',
{
defaultMessage: 'Sitemap URLs',
}
)}
iconType="visMapRegion"
items={crawlRequest.crawlConfig.sitemapUrls}
/>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ const MOCK_EVENT: CrawlEvent = {
type: CrawlType.Full,
crawlConfig: {
domainAllowlist: ['https://www.elastic.co'],
seedUrls: [],
sitemapUrls: [],
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const values: { events: CrawlEvent[] } = {
type: CrawlType.Full,
crawlConfig: {
domainAllowlist: ['https://www.elastic.co'],
seedUrls: [],
sitemapUrls: [],
},
},
{
Expand All @@ -45,6 +47,8 @@ const values: { events: CrawlEvent[] } = {
type: CrawlType.Full,
crawlConfig: {
domainAllowlist: ['https://www.elastic.co'],
seedUrls: [],
sitemapUrls: [],
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ const crawlRequestResponse: CrawlRequestWithDetailsFromServer = {
type: CrawlType.Full,
crawl_config: {
domain_allowlist: [],
seed_urls: [],
sitemap_urls: [],
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ describe('CrawlerLogic', () => {
type: CrawlType.Full,
crawlConfig: {
domainAllowlist: ['elastic.co'],
seedUrls: [],
sitemapUrls: [],
},
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ const events: CrawlEventFromServer[] = [
type: CrawlType.Full,
crawl_config: {
domain_allowlist: ['moviedatabase.com', 'swiftype.com'],
seed_urls: [],
sitemap_urls: [],
},
},
{
Expand All @@ -90,6 +92,8 @@ const events: CrawlEventFromServer[] = [
type: CrawlType.Partial,
crawl_config: {
domain_allowlist: ['swiftype.com'],
seed_urls: [],
sitemap_urls: [],
},
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,10 +201,14 @@ export interface CrawlRequest {

export interface CrawlConfig {
domainAllowlist: string[];
seedUrls: string[];
sitemapUrls: string[];
}

export interface CrawlConfigFromServer {
domain_allowlist: string[];
seed_urls: string[];
sitemap_urls: string[];
}

export type CrawlRequestWithDetailsFromServer = CrawlRequestFromServer & {
Expand Down
Loading