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: Result Component Updates #96184

Merged
merged 8 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -6,4 +6,5 @@
*/

export { ResultFieldValue } from './result_field_value';
export { ResultToken } from './result_token';
export { Result } from './result';
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'drag content actions'
'drag toggle actions';
overflow: hidden; // Prevents child background-colors from clipping outside of panel border-radius
border: $euiBorderThin; // TODO: Remove after EUI version is bumped beyond 31.8.0

&__content {
grid-area: content;
Expand Down Expand Up @@ -44,9 +45,13 @@
display: flex;
justify-content: center;
align-items: center;
width: $euiSizeL * 2;
width: $euiSize * 2;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
width: $euiSize * 2;
width: $euiSizeXL;

border-left: $euiBorderThin;

&:first-child {
border-left: none;
}

&:hover,
&:focus {
background-color: $euiPageBackgroundColor;
Expand All @@ -62,22 +67,3 @@
border-right: $euiBorderThin;
}
}

/**
* CSS for hover specific logic
* It's mildly horrific, so I pulled it out to its own section here
Copy link
Contributor

Choose a reason for hiding this comment

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

💯 I'm super glad I pulled this out into its own easily delete-able section. H E L L Y E A

*/

.appSearchResult--link {
&:hover,
&:focus {
@include euiSlightShadowHover;
}
}
.appSearchResult__content--link:hover {
cursor: pointer;

& ~ .appSearchResult__actionButtons .appSearchResult__actionButton--link {
background-color: $euiPageBackgroundColor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
import React, { useState, useMemo } from 'react';
import { DraggableProvidedDragHandleProps } from 'react-beautiful-dnd';

import classNames from 'classnames';

import './result.scss';

import { EuiPanel, EuiIcon } from '@elastic/eui';
import { EuiButtonIcon, EuiPanel, EuiFlexGroup, EuiFlexItem, EuiIcon } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { ReactRouterHelper } from '../../../shared/react_router_helpers/eui_components';

import { Schema } from '../../../shared/types';

import { ENGINE_DOCUMENT_DETAIL_PATH } from '../../routes';
import { generateEncodedPath } from '../../utils/encode_path_params';

Expand Down Expand Up @@ -56,34 +55,53 @@ export const Result: React.FC<Props> = ({
[result]
);
const numResults = resultFields.length;
const typeForField = (fieldName: string) => {
if (schemaForTypeHighlights) return schemaForTypeHighlights[fieldName];
};

const documentLink = generateEncodedPath(ENGINE_DOCUMENT_DETAIL_PATH, {
engineName: resultMeta.engine,
documentId: resultMeta.id,
});
const conditionallyLinkedArticle = (children: React.ReactNode) => {
return shouldLinkToDetailPage ? (
<ReactRouterHelper to={documentLink}>
<article className="appSearchResult__content appSearchResult__content--link">
{children}
</article>
</ReactRouterHelper>
) : (
<article className="appSearchResult__content">{children}</article>
);

const typeForField = (fieldName: string) => {
if (schemaForTypeHighlights) return schemaForTypeHighlights[fieldName];
};

const classes = classNames('appSearchResult', {
'appSearchResult--link': shouldLinkToDetailPage,
});
const ResultActions = () => {
if (!shouldLinkToDetailPage && !actions.length) return null;
return (
<EuiFlexItem grow={false}>
<EuiFlexGroup gutterSize="s">
{shouldLinkToDetailPage && (
<ReactRouterHelper to={documentLink}>
<EuiFlexItem grow={false}>
<EuiButtonIcon
iconType="eye"
aria-label={i18n.translate(
'xpack.enterpriseSearch.appSearch.result.documentDetailLink',
{ defaultMessage: 'Visit document details' }
)}
/>
</EuiFlexItem>
</ReactRouterHelper>
)}
{actions.map(({ onClick, title, iconType, iconColor }) => (
<EuiFlexItem key={title}>
<EuiButtonIcon
iconType={iconType}
onClick={onClick}
color={iconColor ? 'primary' : undefined}
Copy link
Member

Choose a reason for hiding this comment

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

Ran across this while writing tests ... I assume this is a mistake and should be:

Suggested change
color={iconColor ? 'primary' : undefined}
color={iconColor ? iconColor : 'primary'}

Can you confirm?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ha. Yes. iconColor : 'primary' 🤦🏼

aria-label={title}
/>
</EuiFlexItem>
))}
</EuiFlexGroup>
</EuiFlexItem>
);
};

return (
<EuiPanel
paddingSize="none"
className={classes}
hasShadow={false}
className="appSearchResult"
data-test-subj="AppSearchResult"
title={i18n.translate('xpack.enterpriseSearch.appSearch.result.title', {
defaultMessage: 'Document {id}',
Expand All @@ -95,26 +113,26 @@ export const Result: React.FC<Props> = ({
<EuiIcon type="grab" />
</div>
)}
{conditionallyLinkedArticle(
<>
<ResultHeader
resultMeta={resultMeta}
showScore={!!showScore}
isMetaEngine={isMetaEngine}
/>
{resultFields
.slice(0, isOpen ? resultFields.length : RESULT_CUTOFF)
.map(([field, value]: [string, FieldValue]) => (
<ResultField
key={field}
field={field}
raw={value.raw}
snippet={value.snippet}
type={typeForField(field)}
/>
))}
</>
)}
<article className="appSearchResult__content">
Copy link
Member

Choose a reason for hiding this comment

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

Nice, I'm glad this entire section is no longer linked

<ResultHeader
resultMeta={resultMeta}
showScore={!!showScore}
isMetaEngine={isMetaEngine}
shouldLinkToDetailPage={shouldLinkToDetailPage}
actions={<ResultActions />}
/>
{resultFields
.slice(0, isOpen ? resultFields.length : RESULT_CUTOFF)
.map(([field, value]: [string, FieldValue]) => (
<ResultField
key={field}
field={field}
raw={value.raw}
snippet={value.snippet}
type={typeForField(field)}
/>
))}
</article>
{numResults > RESULT_CUTOFF && (
<button
type="button"
Expand All @@ -138,33 +156,6 @@ export const Result: React.FC<Props> = ({
/>
</button>
)}
<div className="appSearchResult__actionButtons">
{shouldLinkToDetailPage && (
<ReactRouterHelper to={documentLink}>
<a
className="appSearchResult__actionButton appSearchResult__actionButton--link"
aria-label={i18n.translate(
'xpack.enterpriseSearch.appSearch.result.documentDetailLink',
{ defaultMessage: 'Visit document details' }
)}
>
<EuiIcon type="eye" />
</a>
</ReactRouterHelper>
)}
{actions.map(({ onClick, title, iconType, iconColor }) => (
<button
key={title}
aria-label={title}
title={title}
onClick={onClick}
className="appSearchResult__actionButton"
type="button"
>
<EuiIcon type={iconType} color={iconColor} />
</button>
))}
</div>
</EuiPanel>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@
}
}

&__key {
display: flex;
align-items: center;
@include euiCodeFont;

.euiToken {
margin-right: $euiSizeS;
}
}

&__value {
padding-left: $euiSize;
overflow: hidden;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React from 'react';

import { FieldType, Raw, Snippet } from './types';

import { ResultFieldValue } from '.';
import { ResultFieldValue, ResultToken } from '.';

import './result_field.scss';

Expand All @@ -23,7 +23,10 @@ interface Props {
export const ResultField: React.FC<Props> = ({ field, raw, snippet, type }) => {
return (
<div className="appSearchResultField">
<div className="appSearchResultField__key eui-textTruncate">{field}</div>
<div className="appSearchResultField__key eui-textTruncate">
{type && <ResultToken fieldType={type} />}
{field}
</div>
<div className="appSearchResultField__separator" aria-hidden />
<div className="appSearchResultField__value">
<ResultFieldValue className="eui-textTruncate" raw={raw} snippet={snippet} type={type} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
.appSearchResultHeader {
display: flex;
justify-content: space-between;
align-items: flex-start;
margin-bottom: $euiSizeS;

@include euiBreakpoint('xs') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

import React from 'react';

import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';

import { ENGINE_DOCUMENT_DETAIL_PATH } from '../../routes';
import { generateEncodedPath } from '../../utils/encode_path_params';

import { ResultHeaderItem } from './result_header_item';
import { ResultMeta } from './types';

Expand All @@ -16,33 +21,58 @@ interface Props {
showScore: boolean;
isMetaEngine: boolean;
resultMeta: ResultMeta;
actions?: React.ReactNode;
shouldLinkToDetailPage: boolean;
}

export const ResultHeader: React.FC<Props> = ({ showScore, resultMeta, isMetaEngine }) => {
export const ResultHeader: React.FC<Props> = ({
showScore,
resultMeta,
isMetaEngine,
actions,
shouldLinkToDetailPage,
}) => {
const documentLink = generateEncodedPath(ENGINE_DOCUMENT_DETAIL_PATH, {
engineName: resultMeta.engine,
documentId: resultMeta.id,
});

return (
<header className="appSearchResultHeader">
{showScore && (
<div className="appSearchResultHeader__column">
<header style={{ margin: '0 0 .75rem 0' }}>
<EuiFlexGroup alignItems="center" gutterSize="s" justifyContent="spaceBetween">
<EuiFlexItem grow>
<ResultHeaderItem
data-test-subj="ResultScore"
field="score"
value={resultMeta.score}
type="score"
href={shouldLinkToDetailPage ? documentLink : undefined}
data-test-subj="ResultId"
field="ID"
value={resultMeta.id}
type="id"
/>
</div>
)}

<div className="appSearchResultHeader__column">
</EuiFlexItem>
{/* Score */}
{showScore && (
<EuiFlexItem grow={false}>
<ResultHeaderItem
data-test-subj="ResultScore"
field="Score"
value={resultMeta.score}
type="score"
/>
</EuiFlexItem>
)}
{/* Engine Name */}
{isMetaEngine && (
<ResultHeaderItem
data-test-subj="ResultEngine"
field="engine"
value={resultMeta.engine}
type="string"
/>
<EuiFlexItem grow={false}>
<ResultHeaderItem
data-test-subj="ResultEngine"
field="Engine"
value={resultMeta.engine}
type="string"
/>
</EuiFlexItem>
)}
<ResultHeaderItem data-test-subj="ResultId" field="id" value={resultMeta.id} type="id" />
</div>
{actions}
</EuiFlexGroup>
</header>
);
};
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
.appSearchResultHeaderItem {
display: flex;
.euiFlexItem:not(:first-child):not(:last-child) .appSearchResultHeaderItem {
padding-right: .75rem;
box-shadow: inset -1px 0 0 0 $euiBorderColor;
}

&__key,
&__value {
line-height: $euiLineHeight;
font-size: $euiFontSizeXS;
}
.appSearchResultHeaderItem {
@include euiCodeFont;

&__key {
text-transform: uppercase;
font-weight: $euiFontWeightLight;
color: $euiColorDarkShade;
margin-right: $euiSizeXS;
&__score {
color: $euiColorSuccessText;
}
}
}
Loading