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

Update Search Index Document Card design. #194061

Merged
Merged
165 changes: 91 additions & 74 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 Down Expand Up @@ -38,10 +38,14 @@ interface DocumentListProps {
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;
defaultVisibleFields?: number;
compactCard?: boolean;
showScore?: boolean;
onDocumentClick?: (doc: SearchHit) => void;
}

export const DocumentList: React.FC<DocumentListProps> = ({
Expand All @@ -53,6 +57,10 @@ export const DocumentList: React.FC<DocumentListProps> = ({
meta,
onPaginate,
setDocsPerPage,
defaultVisibleFields = 3,
Copy link
Member

Choose a reason for hiding this comment

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

suggestion - have a resultProps prop which passes down these to the Result component?

compactCard = true,
showScore = false,
onDocumentClick,
}) => {
const [isPopoverOpen, setIsPopoverOpen] = useState(false);

Expand Down Expand Up @@ -99,7 +107,14 @@ 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={resultToField(doc, mappings)}
metaData={resultMetaData(doc)}
defaultVisibleFields={defaultVisibleFields}
showScore={showScore}
compactCard={compactCard}
onDocumentClick={onDocumentClick ? () => onDocumentClick(doc) : undefined}
/>
<EuiSpacer size="s" />
</React.Fragment>
);
Expand All @@ -116,81 +131,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
Loading