From 6f94bf7d2aaac6f329456357b0f4164a6a8cbe30 Mon Sep 17 00:00:00 2001 From: Scotty Bollinger Date: Wed, 2 Sep 2020 13:55:02 -0500 Subject: [PATCH] [Enterprise Search] Migrate shared components used in Workplace Search Groups (#76345) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add shared images and export file * Migrate SourceIcon component * Add util to format routes We need a way to format routes using parametrized routes in Workplace Search. We used to the `react-router-named-routes` library, but it is 5 years old has has no typings. I extracted the function we needed into a util. * Update recent_activity to use formatRoute For the 7.9 Kibana MVP, we used a temporary function to generate this route. Aligning this component to use the helper other parts of the app will use after migration. * Add types and constants Various types and constants migrated for use in groups component * Migrate SourceRow component Also adds a mock for contentSources. For now the array only has one item needed for this test, but in future tests, more sources will be added to that array. * Migrate SourcesTable component * Migrate TablePaginationBar component * Migrate UserIcon component * Migrate UserRow component * Refactor format_route Uses Object.entries instead of for…in. This is more modern and allows for 100% test coverage. Also removed `toString()` as `encodeURIComponent()` seems to automatically cast to string * Remove unused import * Use forEach instead of map We’re not returning anything so map is not needed * Minify images * Remove formatRoute in favor of generatePath Unike formatRoute, generatePath adds the trailing slash automatically * Stop renaming methods Co-authored-by: Elastic Machine --- .../__mocks__/content_sources.mock.ts | 36 ++++ .../workplace_search/__mocks__/users.mock.ts | 17 ++ .../components/shared/assets/box.svg | 1 + .../components/shared/assets/confluence.svg | 1 + .../shared/assets/connection_illustration.svg | 1 + .../components/shared/assets/crawler.svg | 1 + .../components/shared/assets/custom.svg | 1 + .../components/shared/assets/drive.svg | 1 + .../components/shared/assets/dropbox.svg | 1 + .../components/shared/assets/github.svg | 1 + .../components/shared/assets/gmail.svg | 1 + .../components/shared/assets/google.svg | 1 + .../components/shared/assets/google_drive.svg | 1 + .../components/shared/assets/index.ts | 53 ++++++ .../components/shared/assets/jira.svg | 1 + .../components/shared/assets/jira_server.svg | 1 + .../shared/assets/loading_small.svg | 1 + .../components/shared/assets/office365.svg | 1 + .../components/shared/assets/one_drive.svg | 1 + .../components/shared/assets/outlook.svg | 1 + .../components/shared/assets/people.svg | 1 + .../components/shared/assets/salesforce.svg | 1 + .../components/shared/assets/service_now.svg | 1 + .../components/shared/assets/share_point.svg | 1 + .../components/shared/assets/slack.svg | 1 + .../components/shared/assets/zendesk.svg | 1 + .../components/shared/source_icon/index.ts | 7 + .../shared/source_icon/source_icon.test.tsx | 27 +++ .../shared/source_icon/source_icon.tsx | 34 ++++ .../components/shared/source_row/index.ts | 7 + .../shared/source_row/source_row.test.tsx | 83 +++++++++ .../shared/source_row/source_row.tsx | 171 ++++++++++++++++++ .../components/shared/sources_table/index.ts | 7 + .../sources_table/sources_table.test.tsx | 35 ++++ .../shared/sources_table/sources_table.tsx | 44 +++++ .../shared/table_pagination_bar/index.ts | 7 + .../table_pagination_bar.test.tsx | 35 ++++ .../table_pagination_bar.tsx | 82 +++++++++ .../components/shared/user_icon/index.ts | 7 + .../shared/user_icon/user_icon.test.tsx | 42 +++++ .../components/shared/user_icon/user_icon.tsx | 19 ++ .../components/shared/user_row/index.ts | 7 + .../shared/user_row/user_row.test.tsx | 29 +++ .../components/shared/user_row/user_row.tsx | 23 +++ .../workplace_search/constants.ts | 19 ++ .../workplace_search/routes.test.tsx | 38 ++++ .../applications/workplace_search/routes.ts | 8 +- .../applications/workplace_search/types.ts | 40 ++++ .../views/overview/recent_activity.tsx | 4 +- 49 files changed, 901 insertions(+), 3 deletions(-) create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/content_sources.mock.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/users.mock.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/box.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/confluence.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/connection_illustration.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/crawler.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/custom.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/drive.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/dropbox.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/github.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/gmail.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/google.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/google_drive.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/index.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/jira.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/jira_server.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/loading_small.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/office365.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/one_drive.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/outlook.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/people.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/salesforce.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/service_now.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/share_point.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/slack.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/zendesk.svg create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_icon/index.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_icon/source_icon.test.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_icon/source_icon.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_row/index.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_row/source_row.test.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_row/source_row.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/sources_table/index.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/sources_table/sources_table.test.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/sources_table/sources_table.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/table_pagination_bar/index.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/table_pagination_bar/table_pagination_bar.test.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/table_pagination_bar/table_pagination_bar.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_icon/index.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_icon/user_icon.test.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_icon/user_icon.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_row/index.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_row/user_row.test.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_row/user_row.tsx create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/constants.ts create mode 100644 x-pack/plugins/enterprise_search/public/applications/workplace_search/routes.test.tsx diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/content_sources.mock.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/content_sources.mock.ts new file mode 100644 index 0000000000000..7789d0caba345 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/content_sources.mock.ts @@ -0,0 +1,36 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const contentSources = [ + { + id: '123', + serviceType: 'custom', + searchable: true, + supportedByLicense: true, + status: 'foo', + statusMessage: 'bar', + name: 'source', + documentCount: '123', + isFederatedSource: false, + errorReason: 0, + allowsReauth: true, + boost: 1, + }, + { + id: '123', + serviceType: 'jira', + searchable: true, + supportedByLicense: true, + status: 'synced', + statusMessage: 'all green', + name: 'Jira', + documentCount: '34234', + isFederatedSource: false, + errorReason: 0, + allowsReauth: true, + boost: 0.5, + }, +]; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/users.mock.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/users.mock.ts new file mode 100644 index 0000000000000..0294803042ada --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/__mocks__/users.mock.ts @@ -0,0 +1,17 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const users = [ + { + id: '1z1z', + name: 'John Does', + pictureUrl: 'http://google.cats', + color: '#ededed', + initials: 'JD', + email: 'jd@elastic.co', + groupIds: [], + }, +]; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/box.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/box.svg new file mode 100644 index 0000000000000..1e7324d9581a7 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/box.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/confluence.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/confluence.svg new file mode 100644 index 0000000000000..23eff13915401 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/confluence.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/connection_illustration.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/connection_illustration.svg new file mode 100644 index 0000000000000..c1c3c3b3ee9ee --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/connection_illustration.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/crawler.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/crawler.svg new file mode 100644 index 0000000000000..d241989f1aff1 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/crawler.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/custom.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/custom.svg new file mode 100644 index 0000000000000..f8f6415dea22b --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/custom.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/drive.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/drive.svg new file mode 100644 index 0000000000000..40b65df3a1ce3 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/drive.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/dropbox.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/dropbox.svg new file mode 100644 index 0000000000000..d16f293fde6dc --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/dropbox.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/github.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/github.svg new file mode 100644 index 0000000000000..c4b4176560d5b --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/github.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/gmail.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/gmail.svg new file mode 100644 index 0000000000000..ee824f730aca6 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/gmail.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/google.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/google.svg new file mode 100644 index 0000000000000..22630f533dcbf --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/google.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/google_drive.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/google_drive.svg new file mode 100644 index 0000000000000..59469d814e35f --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/google_drive.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/index.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/index.ts new file mode 100644 index 0000000000000..5f93694da09b8 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/index.ts @@ -0,0 +1,53 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import box from './box.svg'; +import confluence from './confluence.svg'; +import crawler from './crawler.svg'; +import custom from './custom.svg'; +import drive from './drive.svg'; +import dropbox from './dropbox.svg'; +import github from './github.svg'; +import gmail from './gmail.svg'; +import google from './google.svg'; +import googleDrive from './google_drive.svg'; +import jira from './jira.svg'; +import jiraServer from './jira_server.svg'; +import loadingSmall from './loading_small.svg'; +import office365 from './office365.svg'; +import oneDrive from './one_drive.svg'; +import outlook from './outlook.svg'; +import people from './people.svg'; +import salesforce from './salesforce.svg'; +import serviceNow from './service_now.svg'; +import sharePoint from './share_point.svg'; +import slack from './slack.svg'; +import zendesk from './zendesk.svg'; + +export const images = { + box, + confluence, + crawler, + custom, + drive, + dropbox, + github, + gmail, + googleDrive, + google, + jira, + jiraServer, + loadingSmall, + office365, + oneDrive, + outlook, + people, + salesforce, + serviceNow, + sharePoint, + slack, + zendesk, +} as { [key: string]: string }; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/jira.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/jira.svg new file mode 100644 index 0000000000000..224bb822a581c --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/jira.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/jira_server.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/jira_server.svg new file mode 100644 index 0000000000000..71750fb6e25a0 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/jira_server.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/loading_small.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/loading_small.svg new file mode 100644 index 0000000000000..159408ea02938 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/loading_small.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/office365.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/office365.svg new file mode 100644 index 0000000000000..fdce5d02da3cd --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/office365.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/one_drive.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/one_drive.svg new file mode 100644 index 0000000000000..1856e5e3ce1af --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/one_drive.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/outlook.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/outlook.svg new file mode 100644 index 0000000000000..2680bc99cc367 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/outlook.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/people.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/people.svg new file mode 100644 index 0000000000000..4500c494c23b7 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/people.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/salesforce.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/salesforce.svg new file mode 100644 index 0000000000000..510c438a28195 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/salesforce.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/service_now.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/service_now.svg new file mode 100644 index 0000000000000..2d0c09db4e1c3 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/service_now.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/share_point.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/share_point.svg new file mode 100644 index 0000000000000..8724be9da88cf --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/share_point.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/slack.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/slack.svg new file mode 100644 index 0000000000000..14dbd0289da84 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/slack.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/zendesk.svg b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/zendesk.svg new file mode 100644 index 0000000000000..f7bc1fda0c9ac --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/assets/zendesk.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_icon/index.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_icon/index.ts new file mode 100644 index 0000000000000..da0d11cc1fdc5 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_icon/index.ts @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export { SourceIcon } from './source_icon'; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_icon/source_icon.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_icon/source_icon.test.tsx new file mode 100644 index 0000000000000..dd37ba9b6d859 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_icon/source_icon.test.tsx @@ -0,0 +1,27 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import '../../../../__mocks__/shallow_usecontext.mock'; + +import React from 'react'; +import { shallow } from 'enzyme'; + +import { SourceIcon } from './'; + +describe('SourceIcon', () => { + it('renders unwrapped icon', () => { + const wrapper = shallow(); + + expect(wrapper.find('img')).toHaveLength(1); + expect(wrapper.find('.user-group-source')).toHaveLength(0); + }); + + it('renders wrapped icon', () => { + const wrapper = shallow(); + + expect(wrapper.find('.user-group-source')).toHaveLength(1); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_icon/source_icon.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_icon/source_icon.tsx new file mode 100644 index 0000000000000..ddbe327a40a30 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_icon/source_icon.tsx @@ -0,0 +1,34 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; + +import _camelCase from 'lodash/camelCase'; + +import { images } from '../assets'; + +interface ISourceIconProps { + serviceType: string; + name: string; + className?: string; + wrapped?: boolean; +} + +export const SourceIcon: React.FC = ({ + name, + serviceType, + className, + wrapped, +}) => { + const icon = {name}; + return wrapped ? ( +
+ {icon} +
+ ) : ( + <>{icon} + ); +}; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_row/index.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_row/index.ts new file mode 100644 index 0000000000000..f7a99b59837a5 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_row/index.ts @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export { SourceRow, ISourceRow } from './source_row'; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_row/source_row.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_row/source_row.test.tsx new file mode 100644 index 0000000000000..2bde3b70f82b5 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_row/source_row.test.tsx @@ -0,0 +1,83 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import '../../../../__mocks__/shallow_usecontext.mock'; + +import React from 'react'; +import { shallow } from 'enzyme'; + +import { EuiTableRow, EuiSwitch, EuiIcon } from '@elastic/eui'; +import { contentSources } from '../../../__mocks__/content_sources.mock'; + +import { SourceIcon } from '../source_icon'; + +import { SourceRow } from './'; + +const onToggle = jest.fn(); + +describe('SourceRow', () => { + it('renders with no "Fix" link', () => { + const wrapper = shallow(); + + expect(wrapper.find(EuiTableRow)).toHaveLength(1); + expect(wrapper.contains('Fix')).toBeFalsy(); + expect(wrapper.find(SourceIcon).prop('serviceType')).toEqual('custom'); + }); + + it('calls handler on click', () => { + const wrapper = shallow(); + wrapper.find(EuiSwitch).simulate('change', { target: { checked: true } }); + + expect(onToggle).toHaveBeenCalled(); + }); + + it('renders "Fix" link', () => { + const source = { + ...contentSources[0], + status: 'error', + errorReason: 1, + }; + const wrapper = shallow(); + + expect(wrapper.contains('Fix')).toBeTruthy(); + }); + + it('renders loading icon when indexing', () => { + const source = { + ...contentSources[0], + status: 'indexing', + }; + const wrapper = shallow(); + + expect(wrapper.find(SourceIcon).prop('serviceType')).toEqual('loadingSmall'); + }); + + it('renders warning dot when more config needed', () => { + const source = { + ...contentSources[0], + status: 'need-more-config', + }; + const wrapper = shallow(); + + expect(wrapper.find(EuiIcon).prop('color')).toEqual('warning'); + }); + + it('renders remote tooltip when source is federated', () => { + const source = { + ...contentSources[0], + isFederatedSource: true, + }; + const wrapper = shallow(); + + expect(wrapper.find('.source-row__document-count').contains('Remote')).toBeTruthy(); + }); + + it('renders details link', () => { + const wrapper = shallow(); + + expect(wrapper.find('[data-test-subj="SourceDetailsLink"]')).toHaveLength(1); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_row/source_row.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_row/source_row.tsx new file mode 100644 index 0000000000000..17ca8e58a80fa --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/source_row/source_row.tsx @@ -0,0 +1,171 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; + +import classNames from 'classnames'; +import _kebabCase from 'lodash/kebabCase'; +import { Link } from 'react-router-dom'; + +import { + EuiFlexGroup, + EuiFlexItem, + EuiIcon, + EuiSwitch, + EuiSwitchEvent, + EuiTableRow, + EuiTableRowCell, + EuiText, + EuiToolTip, +} from '@elastic/eui'; + +import { SOURCE_STATUSES as statuses } from '../../../constants'; +import { IContentSourceDetails } from '../../../types'; +import { ADD_SOURCE_PATH, SOURCE_DETAILS_PATH, getContentSourcePath } from '../../../routes'; + +import { SourceIcon } from '../source_icon'; + +const CREDENTIALS_INVALID_ERROR_REASON = 1; + +export interface ISourceRow { + showDetails?: boolean; + isOrganization?: boolean; + onSearchableToggle?(sourceId: string, isSearchable: boolean): void; +} + +interface ISourceRowProps extends ISourceRow { + source: IContentSourceDetails; +} + +export const SourceRow: React.FC = ({ + source: { + id, + serviceType, + searchable, + supportedByLicense, + status, + statusMessage, + name, + documentCount, + isFederatedSource, + errorReason, + allowsReauth, + }, + onSearchableToggle, + isOrganization, + showDetails, +}) => { + const isIndexing = status === statuses.INDEXING; + const hasError = status === statuses.ERROR || status === statuses.DISCONNECTED; + const showFix = + isOrganization && hasError && allowsReauth && errorReason === CREDENTIALS_INVALID_ERROR_REASON; + + const rowClass = classNames( + 'source-row', + { 'content-section--disabled': !searchable }, + { 'source-row source-row--error': hasError } + ); + + // eslint-disable-next-line @typescript-eslint/naming-convention + const imageClass = classNames('source-row__icon', { 'source-row__icon--loading': isIndexing }); + + const fixLink = ( + + Fix + + ); + + const remoteTooltip = ( + <> + Remote + + + + + ); + + return ( + + + + + + + + {name} + + + + + + {status === 'need-more-config' && ( + + + + )} + + + {statusMessage} + + + + + + {isFederatedSource ? remoteTooltip : parseInt(documentCount, 10).toLocaleString('en-US')} + + {onSearchableToggle && ( + + onSearchableToggle(id, e.target.checked)} + disabled={!supportedByLicense} + compressed + label="Source Searchable Toggle" + showLabel={false} + data-test-subj="SourceSearchableToggle" + /> + + )} + + + {showFix && {fixLink}} + + {showDetails && ( + + Details + + )} + + + + + ); +}; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/sources_table/index.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/sources_table/index.ts new file mode 100644 index 0000000000000..bb5f490ed472b --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/sources_table/index.ts @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export { SourcesTable } from './sources_table'; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/sources_table/sources_table.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/sources_table/sources_table.test.tsx new file mode 100644 index 0000000000000..dfac8525471b4 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/sources_table/sources_table.test.tsx @@ -0,0 +1,35 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { shallow } from 'enzyme'; + +import { EuiTable } from '@elastic/eui'; +import { TableHeader } from '../../../../shared/table_header/table_header'; +import { contentSources } from '../../../__mocks__/content_sources.mock'; + +import { SourceRow } from '../source_row'; + +import { SourcesTable } from './'; + +const onToggle = jest.fn(); + +describe('SourcesTable', () => { + it('renders', () => { + const wrapper = shallow(); + + expect(wrapper.find(EuiTable)).toHaveLength(1); + expect(wrapper.find(SourceRow)).toHaveLength(2); + }); + + it('renders "Searchable" header item when toggle fn present', () => { + const wrapper = shallow( + + ); + + expect(wrapper.find(TableHeader).prop('headerItems')).toContain('Searchable'); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/sources_table/sources_table.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/sources_table/sources_table.tsx new file mode 100644 index 0000000000000..184aadc1dad84 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/sources_table/sources_table.tsx @@ -0,0 +1,44 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; + +import { EuiTable, EuiTableBody } from '@elastic/eui'; + +import { TableHeader } from '../../../../shared/table_header/table_header'; +import { SourceRow, ISourceRow } from '../source_row'; +import { IContentSourceDetails } from '../../../types'; + +interface ISourcesTableProps extends ISourceRow { + sources: IContentSourceDetails[]; +} + +export const SourcesTable: React.FC = ({ + sources, + showDetails, + isOrganization, + onSearchableToggle, +}) => { + const headerItems = ['Source', 'Status', 'Documents']; + if (onSearchableToggle) headerItems.push('Searchable'); + + return ( + + + + {sources.map((source) => ( + + ))} + + + ); +}; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/table_pagination_bar/index.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/table_pagination_bar/index.ts new file mode 100644 index 0000000000000..1598ee760c059 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/table_pagination_bar/index.ts @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export { TablePaginationBar } from './table_pagination_bar'; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/table_pagination_bar/table_pagination_bar.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/table_pagination_bar/table_pagination_bar.test.tsx new file mode 100644 index 0000000000000..14d4dfecd0094 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/table_pagination_bar/table_pagination_bar.test.tsx @@ -0,0 +1,35 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { shallow } from 'enzyme'; + +import { EuiFlexGroup, EuiTablePagination } from '@elastic/eui'; + +import { TablePaginationBar } from './'; + +const onChange = jest.fn(); + +describe('TablePaginationBar', () => { + it('renders', () => { + const wrapper = shallow( + + ); + + expect(wrapper.find(EuiTablePagination)).toHaveLength(1); + expect(wrapper.find(EuiFlexGroup)).toHaveLength(2); + expect(wrapper.find(EuiTablePagination).prop('itemsPerPage')).toEqual(10); + expect(wrapper.find(EuiTablePagination).prop('pageCount')).toEqual(1); + }); + + it('passes max page count when showAllPages false', () => { + const wrapper = shallow( + + ); + + expect(wrapper.find(EuiTablePagination).prop('pageCount')).toEqual(100); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/table_pagination_bar/table_pagination_bar.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/table_pagination_bar/table_pagination_bar.tsx new file mode 100644 index 0000000000000..04f5b9a477058 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/table_pagination_bar/table_pagination_bar.tsx @@ -0,0 +1,82 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; + +import { EuiFlexGroup, EuiFlexItem, EuiTablePagination } from '@elastic/eui'; + +interface ITablePaginationBarProps { + itemLabel?: string; + itemsPerPage?: number; + totalPages: number; + totalItems: number; + activePage?: number; + hidePerPageOptions?: boolean; + hideLabelCount?: boolean; + clearFiltersLink?: React.ReactElement; + onChangePage(nextPage: number): void; +} + +const MAX_PAGES = 100; + +export const TablePaginationBar: React.FC = ({ + itemLabel = 'Items', + itemsPerPage = 10, + totalPages, + totalItems, + activePage = 1, + hidePerPageOptions = true, + hideLabelCount = false, + onChangePage, + clearFiltersLink, +}) => { + // EUI component starts page at 0. API starts at 1. + const currentPage = activePage - 1; + const showAllPages = totalPages < MAX_PAGES; + + const pageRangeText = () => { + const rangeEnd = activePage === totalPages ? totalItems : itemsPerPage * activePage; + const rangeStart = currentPage * itemsPerPage + 1; + const rangeEl = ( + + {rangeStart}-{rangeEnd} + + ); + const totalEl = {totalItems.toLocaleString()}; + + return ( + + +
+ Showing {rangeEl} + {showAllPages && ( + <> + {' '} + of {totalEl} {itemLabel} + + )} +
+
+ {clearFiltersLink} +
+ ); + }; + + return ( + + {!hideLabelCount && {pageRangeText()}} + + + + + ); +}; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_icon/index.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_icon/index.ts new file mode 100644 index 0000000000000..e9ee92bed68ca --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_icon/index.ts @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export { UserIcon } from './user_icon'; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_icon/user_icon.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_icon/user_icon.test.tsx new file mode 100644 index 0000000000000..f8c1d00047825 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_icon/user_icon.test.tsx @@ -0,0 +1,42 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { shallow } from 'enzyme'; + +import { users } from '../../../__mocks__/users.mock'; + +import { UserIcon } from './user_icon'; + +describe('SourcesTable', () => { + it('renders with picture', () => { + const wrapper = shallow(); + + expect(wrapper.find('.avatar')).toHaveLength(1); + expect(wrapper.find('.avatar__image')).toHaveLength(1); + }); + + it('renders without picture', () => { + const user = { + ...users[0], + pictureUrl: null, + }; + const wrapper = shallow(); + + expect(wrapper.find('.avatar')).toHaveLength(1); + expect(wrapper.find('.avatar__text')).toHaveLength(1); + }); + + it('renders fallback "alt" value when name not present', () => { + const user = { + ...users[0], + name: null, + }; + const wrapper = shallow(); + + expect(wrapper.find('img').prop('alt')).toEqual(user.email); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_icon/user_icon.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_icon/user_icon.tsx new file mode 100644 index 0000000000000..28ea303d14eaf --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_icon/user_icon.tsx @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; + +import { IUser } from '../../../types'; + +export const UserIcon: React.FC = ({ name, pictureUrl, color, initials, email }) => ( +
+ {pictureUrl ? ( + {name + ) : ( + {initials} + )} +
+); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_row/index.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_row/index.ts new file mode 100644 index 0000000000000..cc4650d70dad0 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_row/index.ts @@ -0,0 +1,7 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export { UserRow } from './user_row'; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_row/user_row.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_row/user_row.test.tsx new file mode 100644 index 0000000000000..20d2732e8c82a --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_row/user_row.test.tsx @@ -0,0 +1,29 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { shallow } from 'enzyme'; + +import { EuiTableRow } from '@elastic/eui'; + +import { users } from '../../../__mocks__/users.mock'; + +import { UserRow } from './'; + +describe('SourcesTable', () => { + it('renders', () => { + const wrapper = shallow(); + + expect(wrapper.find(EuiTableRow)).toHaveLength(1); + expect(wrapper.find('span')).toHaveLength(0); + }); + + it('renders with email visible', () => { + const wrapper = shallow(); + + expect(wrapper.find('span')).toHaveLength(1); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_row/user_row.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_row/user_row.tsx new file mode 100644 index 0000000000000..45866c10a5b21 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/components/shared/user_row/user_row.tsx @@ -0,0 +1,23 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; + +import { EuiTableRow, EuiTableRowCell } from '@elastic/eui'; + +import { IUser } from '../../../types'; + +interface IUserRowProps { + user: IUser; + showEmail?: boolean; +} + +export const UserRow: React.FC = ({ user: { name, email }, showEmail }) => ( + + {name} + {showEmail && {email}} + +); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/constants.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/constants.ts new file mode 100644 index 0000000000000..9f313a6995ad5 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/constants.ts @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +export const MAX_TABLE_ROW_ICONS = 3; + +export const SOURCE_STATUSES = { + INDEXING: 'indexing', + SYNCED: 'synced', + SYNCING: 'syncing', + AWAITING_USER_ACTION: 'awaiting_user_action', + ERROR: 'error', + DISCONNECTED: 'disconnected', + ALWAYS_SYNCED: 'always_synced', +}; + +export const CUSTOM_SERVICE_TYPE = 'custom'; diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/routes.test.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/routes.test.tsx new file mode 100644 index 0000000000000..d03c0abb441b9 --- /dev/null +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/routes.test.tsx @@ -0,0 +1,38 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License; + * you may not use this file except in compliance with the Elastic License. + */ + +import React from 'react'; +import { shallow } from 'enzyme'; + +import { EuiLink } from '@elastic/eui'; + +import { + getContentSourcePath, + SOURCES_PATH, + ORG_SOURCES_PATH, + SOURCE_DETAILS_PATH, +} from './routes'; + +const TestComponent = ({ id, isOrg }: { id: string; isOrg?: boolean }) => { + const href = getContentSourcePath(SOURCE_DETAILS_PATH, id, !!isOrg); + return test; +}; + +describe('getContentSourcePath', () => { + it('should format org route', () => { + const wrapper = shallow(); + const path = wrapper.find(EuiLink).prop('href'); + + expect(path).toEqual(`${ORG_SOURCES_PATH}/123`); + }); + + it('should format user route', () => { + const wrapper = shallow(); + const path = wrapper.find(EuiLink).prop('href'); + + expect(path).toEqual(`${SOURCES_PATH}/123`); + }); +}); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/routes.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/routes.ts index 993a1a378e738..e833dde4c1b72 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/routes.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/routes.ts @@ -4,6 +4,8 @@ * you may not use this file except in compliance with the Elastic License. */ +import { generatePath } from 'react-router-dom'; + import { CURRENT_MAJOR_VERSION } from '../../../common/version'; export const SETUP_GUIDE_PATH = '/setup_guide'; @@ -107,4 +109,8 @@ export const EDIT_SLACK_PATH = `${ORG_SETTINGS_CONNECTORS_PATH}/slack/edit`; export const EDIT_ZENDESK_PATH = `${ORG_SETTINGS_CONNECTORS_PATH}/zendesk/edit`; export const EDIT_CUSTOM_PATH = `${ORG_SETTINGS_CONNECTORS_PATH}/custom/edit`; -export const getSourcePath = (sourceId: string): string => `${ORG_SOURCES_PATH}/${sourceId}`; +export const getContentSourcePath = ( + path: string, + sourceId: string, + isOrganization: boolean +): string => generatePath(isOrganization ? ORG_PATH + path : path, { sourceId }); diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/types.ts b/x-pack/plugins/enterprise_search/public/applications/workplace_search/types.ts index a8348a6f69a39..3866da738cbb6 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/types.ts +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/types.ts @@ -7,3 +7,43 @@ export * from '../../../common/types/workplace_search'; export type TSpacerSize = 'xs' | 's' | 'm' | 'l' | 'xl' | 'xxl'; + +export interface IGroup { + id: string; + name: string; + createdAt: string; + updatedAt: string; + contentSources: IContentSource[]; + users: IUser[]; + usersCount: number; + color?: string; +} + +export interface IUser { + id: string; + name: string | null; + initials: string; + pictureUrl: string | null; + color: string; + email: string; + role?: string; + groupIds: string[]; +} + +export interface IContentSource { + id: string; + serviceType: string; + name: string; +} + +export interface IContentSourceDetails extends IContentSource { + status: string; + statusMessage: string; + documentCount: string; + isFederatedSource: boolean; + searchable: boolean; + supportedByLicense: boolean; + errorReason: number; + allowsReauth: boolean; + boost: number; +} diff --git a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/recent_activity.tsx b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/recent_activity.tsx index 3c476be8d10e6..441f45a947a49 100644 --- a/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/recent_activity.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/workplace_search/views/overview/recent_activity.tsx @@ -15,7 +15,7 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { ContentSection } from '../../components/shared/content_section'; import { sendTelemetry } from '../../../shared/telemetry'; import { KibanaContext, IKibanaContext } from '../../../index'; -import { getSourcePath } from '../../routes'; +import { SOURCE_DETAILS_PATH, getContentSourcePath } from '../../routes'; import { OverviewLogic } from './overview_logic'; @@ -107,7 +107,7 @@ export const RecentActivityItem: React.FC = ({ const linkProps = { onClick, target: '_blank', - href: getWorkplaceSearchUrl(getSourcePath(sourceId)), + href: getWorkplaceSearchUrl(getContentSourcePath(SOURCE_DETAILS_PATH, sourceId, true)), external: true, color: status === 'error' ? 'danger' : 'primary', 'data-test-subj': 'viewSourceDetailsLink',