Skip to content

Commit

Permalink
[8.x] Update Search Index Document Card design. (#194061) (#194555)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.x`:
- [Update Search Index Document Card design.
(#194061)](#194061)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Efe Gürkan
YALAMAN","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-01T11:29:31Z","message":"Update
Search Index Document Card design. (#194061)\n\n##
Summary\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/552e1198-ba95-45d6-b13b-e1b26060d34c\r\n\r\nThis
PR adds an option to add a richer design for Result card. \r\nDefaults
still stay the same with old design.\r\nScreenshot from Index
Management.\r\n<img width=\"1139\" alt=\"Screenshot 2024-09-27 at 14 52
25\"\r\nsrc=\"https://github.com/user-attachments/assets/754a22c5-c3db-4385-b1ad-4e93a8615b9c\">\r\n\r\nAdded
a bunch of options to show score, show amount of fields to show\r\nwhen
collapsed by default etc.\r\n\r\n\r\n### Checklist\r\n\r\nDelete any
items that are not applicable to this PR.\r\n\r\n- [x] Any text added
follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [x] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [x] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[x] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[x] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"5bc33cd69eeb828d519ca44b8a3c3ba35c306e19","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-minor","v8.16.0"],"title":"Update
Search Index Document Card
design.","number":194061,"url":"https://github.com/elastic/kibana/pull/194061","mergeCommit":{"message":"Update
Search Index Document Card design. (#194061)\n\n##
Summary\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/552e1198-ba95-45d6-b13b-e1b26060d34c\r\n\r\nThis
PR adds an option to add a richer design for Result card. \r\nDefaults
still stay the same with old design.\r\nScreenshot from Index
Management.\r\n<img width=\"1139\" alt=\"Screenshot 2024-09-27 at 14 52
25\"\r\nsrc=\"https://github.com/user-attachments/assets/754a22c5-c3db-4385-b1ad-4e93a8615b9c\">\r\n\r\nAdded
a bunch of options to show score, show amount of fields to show\r\nwhen
collapsed by default etc.\r\n\r\n\r\n### Checklist\r\n\r\nDelete any
items that are not applicable to this PR.\r\n\r\n- [x] Any text added
follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [x] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [x] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[x] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[x] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"5bc33cd69eeb828d519ca44b8a3c3ba35c306e19"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/194061","number":194061,"mergeCommit":{"message":"Update
Search Index Document Card design. (#194061)\n\n##
Summary\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/552e1198-ba95-45d6-b13b-e1b26060d34c\r\n\r\nThis
PR adds an option to add a richer design for Result card. \r\nDefaults
still stay the same with old design.\r\nScreenshot from Index
Management.\r\n<img width=\"1139\" alt=\"Screenshot 2024-09-27 at 14 52
25\"\r\nsrc=\"https://github.com/user-attachments/assets/754a22c5-c3db-4385-b1ad-4e93a8615b9c\">\r\n\r\nAdded
a bunch of options to show score, show amount of fields to show\r\nwhen
collapsed by default etc.\r\n\r\n\r\n### Checklist\r\n\r\nDelete any
items that are not applicable to this PR.\r\n\r\n- [x] Any text added
follows [EUI's
writing\r\nguidelines](https://elastic.github.io/eui/#/guidelines/writing),
uses\r\nsentence case text and includes
[i18n\r\nsupport](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)\r\n-
[
]\r\n[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)\r\nwas
added for features that require explanation or tutorials\r\n- [ ] [Unit
or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [ ] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests changed\r\n- [x] Any UI touched in this PR is
usable by keyboard only (learn more\r\nabout [keyboard
accessibility](https://webaim.org/techniques/keyboard/))\r\n- [x] Any UI
touched in this PR does not create any new axe failures\r\n(run axe in
browser:\r\n[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),\r\n[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))\r\n-
[x] This renders correctly on smaller devices using a
responsive\r\nlayout. (You can test this [in
your\r\nbrowser](https://www.browserstack.com/guide/responsive-testing-on-local-server))\r\n-
[x] This was checked for
[cross-browser\r\ncompatibility](https://www.elastic.co/support/matrix#matrix_browsers)\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<[email protected]>","sha":"5bc33cd69eeb828d519ca44b8a3c3ba35c306e19"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Efe Gürkan YALAMAN <[email protected]>
Co-authored-by: Elastic Machine <[email protected]>
Co-authored-by: Alex Szabo <[email protected]>
  • Loading branch information
4 people authored Oct 2, 2024
1 parent 5c4afed commit 272f3bb
Show file tree
Hide file tree
Showing 20 changed files with 611 additions and 247 deletions.
163 changes: 88 additions & 75 deletions packages/kbn-search-index-documents/components/document_list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import React, { useState } from 'react';

import { MappingProperty, SearchHit } from '@elastic/elasticsearch/lib/api/types';
import type { IndicesGetMappingResponse, SearchHit } from '@elastic/elasticsearch/lib/api/types';

import {
EuiButtonEmpty,
Expand All @@ -30,18 +30,22 @@ import { i18n } from '@kbn/i18n';

import { FormattedMessage, FormattedNumber } from '@kbn/i18n-react';

import { resultMetaData, resultToField } from './result/result_metadata';
import { resultMetaData, resultToFieldFromMappingResponse } from './result/result_metadata';

import { Result } from '..';
import { type ResultProps } from './result/result';

interface DocumentListProps {
dataTelemetryIdPrefix: string;
docs: SearchHit[];
docsPerPage: number;
isLoading: boolean;
mappings: Record<string, MappingProperty> | undefined;
mappings: IndicesGetMappingResponse | undefined;
meta: Pagination;
onPaginate: (newPageIndex: number) => void;
setDocsPerPage: (docsPerPage: number) => void;
setDocsPerPage?: (docsPerPage: number) => void;
onDocumentClick?: (doc: SearchHit) => void;
resultProps?: Partial<ResultProps>;
}

export const DocumentList: React.FC<DocumentListProps> = ({
Expand All @@ -53,6 +57,8 @@ export const DocumentList: React.FC<DocumentListProps> = ({
meta,
onPaginate,
setDocsPerPage,
onDocumentClick,
resultProps = {},
}) => {
const [isPopoverOpen, setIsPopoverOpen] = useState(false);

Expand Down Expand Up @@ -99,7 +105,12 @@ export const DocumentList: React.FC<DocumentListProps> = ({
{docs.map((doc) => {
return (
<React.Fragment key={doc._id}>
<Result fields={resultToField(doc, mappings)} metaData={resultMetaData(doc)} />
<Result
fields={resultToFieldFromMappingResponse(doc, mappings)}
metaData={resultMetaData(doc)}
onDocumentClick={onDocumentClick ? () => onDocumentClick(doc) : undefined}
{...resultProps}
/>
<EuiSpacer size="s" />
</React.Fragment>
);
Expand All @@ -116,81 +127,83 @@ export const DocumentList: React.FC<DocumentListProps> = ({
onPageClick={onPaginate}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiPopover
aria-label={i18n.translate('searchIndexDocuments.documentList.docsPerPage', {
defaultMessage: 'Document count per page dropdown',
})}
button={
<EuiButtonEmpty
data-telemetry-id={`${dataTelemetryIdPrefix}-documents-docsPerPage`}
size="s"
iconType="arrowDown"
iconSide="right"
onClick={() => {
setIsPopoverOpen(true);
}}
>
{i18n.translate('searchIndexDocuments.documentList.pagination.itemsPerPage', {
defaultMessage: 'Documents per page: {docPerPage}',
values: { docPerPage: docsPerPage },
})}
</EuiButtonEmpty>
}
isOpen={isPopoverOpen}
closePopover={() => {
setIsPopoverOpen(false);
}}
panelPaddingSize="none"
anchorPosition="downLeft"
>
<EuiContextMenuPanel
size="s"
items={[
<EuiContextMenuItem
key="10 rows"
icon={getIconType(10)}
{setDocsPerPage && (
<EuiFlexItem grow={false}>
<EuiPopover
aria-label={i18n.translate('searchIndexDocuments.documentList.docsPerPage', {
defaultMessage: 'Document count per page dropdown',
})}
button={
<EuiButtonEmpty
data-telemetry-id={`${dataTelemetryIdPrefix}-documents-docsPerPage`}
size="s"
iconType="arrowDown"
iconSide="right"
onClick={() => {
setIsPopoverOpen(false);
setDocsPerPage(10);
setIsPopoverOpen(true);
}}
>
{i18n.translate('searchIndexDocuments.documentList.paginationOptions.option', {
defaultMessage: '{docCount} documents',
values: { docCount: 10 },
{i18n.translate('searchIndexDocuments.documentList.pagination.itemsPerPage', {
defaultMessage: 'Documents per page: {docPerPage}',
values: { docPerPage: docsPerPage },
})}
</EuiContextMenuItem>,
</EuiButtonEmpty>
}
isOpen={isPopoverOpen}
closePopover={() => {
setIsPopoverOpen(false);
}}
panelPaddingSize="none"
anchorPosition="downLeft"
>
<EuiContextMenuPanel
size="s"
items={[
<EuiContextMenuItem
key="10 rows"
icon={getIconType(10)}
onClick={() => {
setIsPopoverOpen(false);
setDocsPerPage(10);
}}
>
{i18n.translate('searchIndexDocuments.documentList.paginationOptions.option', {
defaultMessage: '{docCount} documents',
values: { docCount: 10 },
})}
</EuiContextMenuItem>,

<EuiContextMenuItem
key="25 rows"
icon={getIconType(25)}
onClick={() => {
setIsPopoverOpen(false);
setDocsPerPage(25);
}}
>
{i18n.translate('searchIndexDocuments.documentList.paginationOptions.option', {
defaultMessage: '{docCount} documents',
values: { docCount: 25 },
})}
</EuiContextMenuItem>,
<EuiContextMenuItem
key="50 rows"
icon={getIconType(50)}
onClick={() => {
setIsPopoverOpen(false);
setDocsPerPage(50);
}}
>
{i18n.translate('searchIndexDocuments.documentList.paginationOptions.option', {
defaultMessage: '{docCount} documents',
values: { docCount: 50 },
})}
</EuiContextMenuItem>,
]}
/>
</EuiPopover>
</EuiFlexItem>
<EuiContextMenuItem
key="25 rows"
icon={getIconType(25)}
onClick={() => {
setIsPopoverOpen(false);
setDocsPerPage(25);
}}
>
{i18n.translate('searchIndexDocuments.documentList.paginationOptions.option', {
defaultMessage: '{docCount} documents',
values: { docCount: 25 },
})}
</EuiContextMenuItem>,
<EuiContextMenuItem
key="50 rows"
icon={getIconType(50)}
onClick={() => {
setIsPopoverOpen(false);
setDocsPerPage(50);
}}
>
{i18n.translate('searchIndexDocuments.documentList.paginationOptions.option', {
defaultMessage: '{docCount} documents',
values: { docCount: 50 },
})}
</EuiContextMenuItem>,
]}
/>
</EuiPopover>
</EuiFlexItem>
)}
</EuiFlexGroup>

<EuiSpacer />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,14 @@ describe('DocumentList', () => {
},
],
mappings: {
AvgTicketPrice: {
type: 'float' as const,
kibana_sample_data_flights: {
mappings: {
properties: {
AvgTicketPrice: {
type: 'float' as const,
},
},
},
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
*/

export { Result } from './result';
export { resultMetaData, resultToField } from './result_metadata';
export {
resultMetaData,
resultToFieldFromMappingResponse,
resultToFieldFromMappings as resultToField,
} from './result_metadata';
Loading

0 comments on commit 272f3bb

Please sign in to comment.