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): add label prop on NoItems functional component #4390

Merged
merged 12 commits into from
Sep 18, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export class AtomicCommerceNoProducts
this.ariaMessage = getSummary(
i18n,
'query' in this.summaryState ? this.summaryState.query : '',
this.summary.state.hasProducts
this.summary.state.hasProducts,
'no-products'
);

return (
Expand All @@ -78,6 +79,7 @@ export class AtomicCommerceNoProducts
<NoItems
query={'query' in this.summaryState ? this.summaryState.query : ''}
i18n={i18n}
label="no-products"
/>
<SearchTips i18n={i18n} />
</NoItemsContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ export class NoProductsPageObject extends BasePageObject<'atomic-commerce-no-pro

ariaLive(query?: string) {
const text = query
? `We couldn't find anything for ${query}`
: 'No results';
? `We couldn't find any product for ${query}`
: 'No products';

return this.page.getByRole('status').filter({hasText: text});
}

message(query?: string) {
return this.page.locator('[part="no-results"]', {
hasText: query
? `We couldn't find anything for ${query}`
: 'No results',
? `We couldn't find any product for ${query}}"`
fbeaudoincoveo marked this conversation as resolved.
Show resolved Hide resolved
: 'No products',
});
}
}
11 changes: 8 additions & 3 deletions packages/atomic/src/components/common/no-items/no-items.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ import {LocalizedString} from '../../../utils/jsx-utils';
interface NoItemsProps {
query: string;
i18n: i18n;
label: 'no-results' | 'no-products';
}
export const NoItems: FunctionalComponent<NoItemsProps> = ({i18n, query}) => {
export const NoItems: FunctionalComponent<NoItemsProps> = ({
i18n,
query,
label,
}) => {
const content = query ? (
<LocalizedString
i18n={i18n}
key="no-results-for"
key={`${label}-for`}
params={{
query: (
<span
Expand All @@ -27,7 +32,7 @@ export const NoItems: FunctionalComponent<NoItemsProps> = ({i18n, query}) => {
}}
/>
) : (
i18n.t('no-results')
i18n.t(label)
);
return (
<div
Expand Down
11 changes: 8 additions & 3 deletions packages/atomic/src/components/common/no-items/utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import {i18n} from 'i18next';

export const getSummary = (i18n: i18n, query: string, hasResults: boolean) => {
export const getSummary = (
i18n: i18n,
query: string,
hasResults: boolean,
label: 'no-products' | 'no-results'
) => {
if (hasResults) {
return '';
}

return query
? i18n.t('no-results-for', {
? i18n.t(`${label}-for`, {
interpolation: {escapeValue: false},
query,
})
: i18n.t('no-results');
: i18n.t(label);
};
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ export class AtomicInsightNoResults
<NoItemsGuard {...this.searchStatusState}>
<NoItemsContainer>
<MagnifyingGlass />
<NoItems query={this.querySummaryState.query} i18n={i18n} />
<NoItems
query={this.querySummaryState.query}
i18n={i18n}
label="no-results"
/>
<SearchTips i18n={i18n} />
</NoItemsContainer>
</NoItemsGuard>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,19 @@ export class AtomicNoResults {
this.ariaMessage = getSummary(
i18n,
this.querySummaryState.query,
this.searchStatusState.hasResults
this.searchStatusState.hasResults,
'no-results'
);

return (
<NoItemsGuard {...this.searchStatusState}>
<NoItemsContainer>
<MagnifyingGlass />
<NoItems query={this.querySummaryState.query} i18n={i18n} />
<NoItems
query={this.querySummaryState.query}
i18n={i18n}
label="no-results"
/>
<SearchTips i18n={i18n} />
{this.enableCancelLastAction && this.historyState.past.length ? (
<Cancel
Expand Down
54 changes: 54 additions & 0 deletions packages/atomic/src/locales.json
Original file line number Diff line number Diff line change
Expand Up @@ -8289,5 +8289,59 @@
"zh": "空的搜索",
"zh-CN": "空的搜索",
"zh-TW": "空的搜索"
},
"no-products": {
"en": "No products",
"fr": "Aucun produit",
"cs": "Žádné produkty",
"da": "Ingen produkter",
"de": "Keine Produkte",
"el": "Δεν υπάρχουν προϊόντα",
"es": "No hay productos",
"fi": "Ei tuotteita",
"hu": "Nincs termék",
"id": "Tidak ada produk",
"it": "Nessun prodotto",
"ja": "商品がありません",
"ko": "제품 없음",
"nl": "Geen producten",
"no": "Ingen produkter",
"pl": "Brak produktów",
"pt": "Sem produtos",
"pt-BR": "Sem produtos",
"ru": "Нет продуктов",
"sv": "Inga produkter",
"th": "ไม่มีสินค้า",
"tr": "Ürün yok",
fbeaudoincoveo marked this conversation as resolved.
Show resolved Hide resolved
"zh": "没有产品",
"zh-CN": "没有产品",
"zh-TW": "沒有產品"
},
"no-products-for": {
"en": "We couldn't find any product for {{query}}",
"fr": "Nous n'avons trouvé aucun produit pour {{query}}",
"cs": "Nepodařilo se nám najít žádný produkt pro {{query}}",
"da": "Vi kunne ikke finde noget produkt til {{query}}",
"de": "Wir konnten kein Produkt für {{query}} finden",
"el": "Δεν μπορέσαμε να βρούμε κανένα προϊόν για {{query}}",
"es": "No pudimos encontrar ningún producto para {{query}}",
"fi": "Emme löytäneet tuotetta kohteelle {{query}}",
"hu": "Nem találtunk terméket a {{query}} számára",
"id": "Kami tidak dapat menemukan produk apa pun untuk {{query}}",
"it": "Non abbiamo trovato alcun prodotto per {{query}}",
"ja": "{{query}}のための製品が見つかりませんでした",
"ko": "{{query}}에 대한 제품을 찾을 수 없습니다",
"nl": "We konden geen product vinden voor {{query}}",
"no": "Vi kunne ikke finne noen produkt for {{query}}",
"pl": "Nie udało nam się znaleźć żadnego produktu dla {{query}}",
"pt": "Não conseguimos encontrar nenhum produto para {{query}}",
"pt-BR": "Não conseguimos encontrar nenhum produto para {{query}}",
"ru": "Мы не смогли найти ни одного товара для {{query}}",
"sv": "Vi kunde inte hitta någon produkt för {{query}}",
"th": "เราไม่สามารถค้นหารายการสินค้าสำหรับ {{query}}",
"tr": "{{query}} için hiçbir ürün bulamadık",
"zh": "我们找不到任何产品为{{query}}",
"zh-CN": "我们找不到任何产品为{{query}}",
"zh-TW": "我們找不到任何產品為{{query}}"
}
}
Loading