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

feat(atomic): empty no-result-text prop hides component when no child results found #3042

Merged
merged 11 commits into from
Jul 21, 2023
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {generateComponentHTML} from '../../fixtures/test-fixture';
import {TagProps, generateComponentHTML} from '../../fixtures/test-fixture';
import {
resultChildrenComponent,
resultChildrenTemplateComponent,
Expand All @@ -7,15 +7,21 @@ import {
import {resultLinkComponent} from './result-components/result-link-selectors';
import {resultSectionTags} from './result-list-selectors';

export function buildResultTopChild(children?: HTMLElement): HTMLElement[] {
export function buildResultTopChild(
children?: HTMLElement,
props?: TagProps
): HTMLElement[] {
return [
generateComponentHTML(resultLinkComponent),
buildResultChildren(children),
buildResultChildren(children, props),
];
}

export function buildResultChildren(grandChildren?: HTMLElement): HTMLElement {
const children = generateComponentHTML(resultChildrenComponent);
export function buildResultChildren(
grandChildren?: HTMLElement,
props?: TagProps
): HTMLElement {
const children = generateComponentHTML(resultChildrenComponent, props);
const childrenTemplate = generateComponentHTML(
resultChildrenTemplateComponent
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ export const FoldedResultListSelectors = {
.find(resultComponent)
.shadow()
.eq(grandChildIndex),
noResultsLabel: () =>
FoldedResultListSelectors.resultChildren()
.should('have.attr', 'data-atomic-rendered', 'true')
.shadow()
.find('[part="no-result-root"]'),
sections: {
visual: () =>
FoldedResultListSelectors.firstResult().find(resultSectionTags.visual),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
addFoldedResultList,
buildTemplateWithoutSections,
buildTemplateWithSections,
removeResultChildrenFromResponse,
} from './result-list-actions';

const setSourceAndSortCriteria = () => {
Expand Down Expand Up @@ -51,6 +52,34 @@ describe('Folded Result List Component', () => {
.contains(ExpectedHierarchy.children[1].name);
});

it('should show a "no results" label when no child results are found', () => {
new TestFixture()
.with(setSourceAndSortCriteria)
.with(
addFoldedResultList(buildTemplateWithoutSections(buildResultTopChild()))
)
.with(removeResultChildrenFromResponse)
.init();

FoldedResultListSelectors.noResultsLabel().should('be.visible');
});

it('should not show a "no results" label when no child results are found when no-result-text is empty', () => {
new TestFixture()
.with(setSourceAndSortCriteria)
.with(
addFoldedResultList(
buildTemplateWithoutSections(
buildResultTopChild(undefined, {'no-result-text': ''})
)
)
)
.with(removeResultChildrenFromResponse)
.init();

FoldedResultListSelectors.noResultsLabel().should('not.exist');
});

it('renders content before and after children only when there are children', () => {
const components = buildResultTopChild();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {ResultWithFolding} from '@coveo/headless/dist/definitions/features/folding/folding-slice';
import {
TestFixture,
generateComponentHTML,
Expand Down Expand Up @@ -77,3 +78,11 @@ export const addFoldedResultList =
}
fixture.withElement(foldedResultList);
};

export const removeResultChildrenFromResponse = (fixture: TestFixture) => {
fixture.withCustomResponse((response) =>
response.results.forEach((result) => {
(result as ResultWithFolding).childResults = [];
})
);
};
8 changes: 4 additions & 4 deletions packages/atomic/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ export namespace Components {
*/
"inheritTemplates": boolean;
/**
* The non-localized copy for an empty result state.
* The non-localized copy for an empty result state. An empty string will result in the component being hidden.
*/
"noResultText": string;
}
Expand Down Expand Up @@ -1400,7 +1400,7 @@ export namespace Components {
*/
"inheritTemplates": boolean;
/**
* The non-localized copy for an empty result state.
* The non-localized copy for an empty result state. An empty string will result in the component being hidden.
*/
"noResultText": string;
}
Expand Down Expand Up @@ -3606,7 +3606,7 @@ declare namespace LocalJSX {
*/
"inheritTemplates"?: boolean;
/**
* The non-localized copy for an empty result state.
* The non-localized copy for an empty result state. An empty string will result in the component being hidden.
*/
"noResultText"?: string;
}
Expand Down Expand Up @@ -4309,7 +4309,7 @@ declare namespace LocalJSX {
*/
"inheritTemplates"?: boolean;
/**
* The non-localized copy for an empty result state.
* The non-localized copy for an empty result state. An empty string will result in the component being hidden.
*/
"noResultText"?: string;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ export class ResultChildrenCommon {
}

if (!collection.moreResultsAvailable && !this.hasChildren) {
return this.renderNoResult();
return this.props.getNoResultText()?.trim().length
nathanlb marked this conversation as resolved.
Show resolved Hide resolved
? this.renderNoResult()
: null;
}

if (!this.hasChildren) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
padding: $margin-lg;
}

atomic-result-children::part(show-hide-button) {
atomic-result-children::part(show-hide-button),
atomic-insight-result-children::part(show-hide-button) {
margin-top: $margin-sm;
margin-bottom: $margin-sm;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,30 @@ atomic-result-section-children {
padding-left: 1rem;
}

:host(:hover) {
.with-sections {
background-color: var(--atomic-neutral-lighter);
}

atomic-insight-result-action-bar {
@apply visible;
}
}

:host {
@apply relative;
.with-sections {

.with-sections:not(.child-result) {
@apply p-6;
}
}

:host(:first-of-type) {
.with-sections {
@apply pt-8;
&(:hover) {
.with-sections {
background-color: var(--atomic-neutral-lighter);
}

atomic-insight-result-action-bar {
@apply visible;
}
}

atomic-insight-result-action-bar {
@apply top-0;
&(:first-of-type) {
.with-sections:not(.child-result) {
@apply pt-8;
}

atomic-insight-result-action-bar {
@apply top-0;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
@import '../../../common/result-list/styles/placeholders.pcss';
@import '../styles/list-display.pcss';

.list-root {
@apply p-0;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
@import '../../../common/result-list/styles/placeholders.pcss';
@import '../styles/list-display.pcss';

.list-root {
@apply p-0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,24 @@
margin-bottom: 1rem;
}

.list-root.display-list {
display: flex;
flex-direction: column;
.list-root {
&.display-list {
display: flex;
flex-direction: column;

.result-component,
atomic-result-placeholder {
width: auto;
}
.result-component,
atomic-result-placeholder {
width: auto;
}

@mixin atomic-list-with-dividers;

@mixin atomic-list-with-dividers;
.result-component[part~='outline']::before {
@apply my-0 mx-6;
}
}

.result-component[part~='outline']::before {
@apply my-0 mx-6;
&.placeholder {
padding: 0.5rem 1.5rem;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class AtomicResultChildren
*/
@Prop({reflect: true}) imageSize?: ResultDisplayImageSize;
/**
* The non-localized copy for an empty result state.
* The non-localized copy for an empty result state. An empty string will result in the component being hidden.
*/
@Prop() public noResultText = 'no-documents-related';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class AtomicResultChildren implements InitializableComponent {
*/
@Prop({reflect: true}) imageSize?: ResultDisplayImageSize;
/**
* The non-localized copy for an empty result state.
* The non-localized copy for an empty result state. An empty string will result in the component being hidden.
*/
@Prop() public noResultText = 'no-documents-related';

Expand Down
Loading