Skip to content

Commit

Permalink
#1617 - Fetch store name from the GraphQL server at compile time (#3019)
Browse files Browse the repository at this point in the history
* #1617 - Fetch store name from the GraphQL server at compile time

* format the code with prettier

* remove unnecessary declarations

* Simplify the process of finding the available store

Co-authored-by: Stephen <sirugh@users.noreply.github.com>

* Simplify the assignment of current store name

Co-authored-by: Stephen <sirugh@users.noreply.github.com>

* Fix destructure syntax

* prettier

* availableStore -> availableStores

* Use runtime store name fetch in a new TitleWithStore component.

Signed-off-by: sirugh <rugh@adobe.com>

* StoreTitle

* Fix tests

* Fix error view rendering when data was still returned

Signed-off-by: sirugh <rugh@adobe.com>

* fix test snap

Signed-off-by: sirugh <rugh@adobe.com>

Co-authored-by: Stephen <sirugh@users.noreply.github.com>
Co-authored-by: Stephen <rugh@adobe.com>
Co-authored-by: Revanth Kumar Annavarapu <35203638+revanth0212@users.noreply.github.com>
Co-authored-by: Devagouda <40405790+dpatil-magento@users.noreply.github.com>
  • Loading branch information
5 people authored Mar 9, 2021
1 parent c483b3a commit e28e094
Show file tree
Hide file tree
Showing 39 changed files with 156 additions and 163 deletions.
10 changes: 5 additions & 5 deletions packages/extensions/venia-sample-language-packs/i18n/fr_FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"accountInformationPage.accountInformation": "Informations sur le compte",
"accountInformationPage.editAccount": "Modifier les informations du compte",
"accountInformationPage.errorTryAgain": "Un problème est survenu. Veuillez actualiser et réessayer.",
"accountInformationPage.titleAccount": "Information sur le compte - {name}",
"accountInformationPage.titleAccount": "Information sur le compte",
"accountMenu.accountInfoLink": "Information sur le compte",
"accountMenu.addressBookLink": "Carnet d'adresses",
"accountMenu.communicationsLink": "Les communications",
Expand Down Expand Up @@ -39,7 +39,7 @@
"cartPage.emptyCart": "Il n'y a aucun article dans votre panier.",
"cartPage.heading": "Panier",
"cartPage.signIn": "Se connecter",
"cartPage.title": "Panier - {name}",
"cartPage.title": "Panier",
"cartTrigger.ariaLabel": "Basculer le mini-panier. Vous avez {count} articles dans votre panier.",
"categoryContent.filter": "Filtre",
"categoryContent.itemsSortedBy": "Articles triés par ",
Expand Down Expand Up @@ -88,8 +88,8 @@
"checkoutPage.stockStatusMessage": "Un article de votre panier est actuellement en rupture de stock et doit être retiré pour pouvoir passer à la caisse. Veuillez retourner à votre panier pour retirer l'article.",
"checkoutPage.subscribe": "Abonnez-vous aux nouvelles et mises à jour",
"checkoutPage.thankYou": "Nous vous remercions de votre commande!",
"checkoutPage.titleCheckout": "Paiement - {name}",
"checkoutPage.titleReceipt": "Le reçu - {name}",
"checkoutPage.titleCheckout": "Paiement",
"checkoutPage.titleReceipt": "Le reçu",
"cms.shopByCategory": "Acheter par catégorie",
"cmsBlock.noBlocks": "Il n'y a aucun bloc à afficher",
"communicationsPage.changesText": "Sauvegarder les modifications",
Expand All @@ -99,7 +99,7 @@
"communicationsPage.preferencesText": "Vos préférences ont été mises à jour.",
"communicationsPage.savingText": "Économie",
"communicationsPage.subscribeText": "Restez à la pointe de la mode; abonnez-vous à la newsletter mensuelle de Venia.",
"communicationsPage.title": "Les Communications - {name}",
"communicationsPage.title": "Les Communications",
"completedView.errorLoading": "Erreur lors du chargement de la méthode d'expédition sélectionnée. Veuillez sélectionner à nouveau.",
"completedView.shippingMethod": "Méthode d'expédition",
"Contact Us": "Nous contacter",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Object {
null,
],
"loadFilters": false,
"pageTitle": "Venia",
"totalPagesFromData": null,
}
`;
Expand All @@ -46,7 +45,6 @@ Object {
},
],
"loadFilters": false,
"pageTitle": "Jewelry - Venia",
"totalPagesFromData": 1,
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const DRAWER_NAME = 'filter';
* @returns {func} result.handleOpenFilters - A callback function that actually opens the filter drawer.
* @returns {object} result.items - The items in this category.
* @returns {bool} result.loadFilters - Whether or not the user has signalled their intent to interact with the filters.
* @returns {string} result.pageTitle - The text to put in the browser tab for this page.
*/
export const useCategoryContent = props => {
const { categoryId, data, pageSize = 6 } = props;
Expand Down Expand Up @@ -68,10 +67,6 @@ export const useCategoryContent = props => {
: null;
const categoryName = data ? data.category.name : null;
const categoryDescription = data ? data.category.description : null;
// Note: STORE_NAME is injected by Webpack at build time.
const pageTitle = categoryName
? `${categoryName} - ${STORE_NAME}`
: STORE_NAME;

return {
categoryName,
Expand All @@ -81,7 +76,6 @@ export const useCategoryContent = props => {
handleOpenFilters,
items,
loadFilters,
pageTitle,
totalPagesFromData
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ query {
code
locale
secure_base_media_url
store_name
}
}
2 changes: 0 additions & 2 deletions packages/venia-concept/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
<meta name="theme-color" content="#ff6334">
<link rel="manifest" href="/manifest.json">

<title><%= STORE_NAME %></title>

<!--
Apple Specific Tags
Expand Down
13 changes: 12 additions & 1 deletion packages/venia-concept/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ module.exports = async env => {
const storeConfigData = await getStoreConfigData();
const { availableStores } = await getAvailableStoresConfigData();

/**
* Loop the available stores when there is provided STORE_VIEW_CODE
* in the .env file, because should set the store name from the
* given store code instead of the default one.
*/
const availableStore = availableStores.find(
({ code }) => code === process.env.STORE_VIEW_CODE
);

global.MAGENTO_MEDIA_BACKEND_URL = mediaUrl;
global.LOCALE = storeConfigData.locale.replace('_', '-');
global.AVAILABLE_STORE_VIEWS = availableStores;
Expand All @@ -63,7 +72,9 @@ module.exports = async env => {
* the globals object in jest.config.js.
*/
POSSIBLE_TYPES: JSON.stringify(possibleTypes),
STORE_NAME: JSON.stringify('Venia'),
STORE_NAME: availableStore
? JSON.stringify(availableStore.store_name)
: JSON.stringify(storeConfigData.store_name),
STORE_VIEW_CODE: process.env.STORE_VIEW_CODE
? JSON.stringify(process.env.STORE_VIEW_CODE)
: JSON.stringify(storeConfigData.code),
Expand Down
10 changes: 5 additions & 5 deletions packages/venia-ui/i18n/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"accountInformationPage.accountInformation": "Account Information",
"accountInformationPage.editAccount": "Edit Account Information",
"accountInformationPage.errorTryAgain": "Something went wrong. Please refresh and try again.",
"accountInformationPage.titleAccount": "Account Information - {name}",
"accountInformationPage.titleAccount": "Account Information",
"accountMenu.accountInfoLink": "Account Information",
"accountMenu.addressBookLink": "Address Book",
"accountMenu.communicationsLink": "Communications",
Expand Down Expand Up @@ -42,7 +42,7 @@
"cartPage.couponCode": "Coupon Code",
"cartPage.emptyCart": "There are no items in your cart.",
"cartPage.heading": "Cart",
"cartPage.title": "Cart - {name}",
"cartPage.title": "Cart",
"cartTrigger.ariaLabel": "Toggle mini cart. You have {count} items in your cart.",
"categoryContent.filter": "Filter",
"categoryContent.itemsSortedBy": "Items sorted by ",
Expand Down Expand Up @@ -97,8 +97,8 @@
"checkoutPage.stockStatusMessage": "An item in your cart is currently out-of-stock and must be removed in order to Checkout. Please return to your cart to remove the item.",
"checkoutPage.subscribe": "Subscribe to news and updates",
"checkoutPage.thankYou": "Thank you for your order!",
"checkoutPage.titleCheckout": "Checkout - {name}",
"checkoutPage.titleReceipt": "Receipt - {name}",
"checkoutPage.titleCheckout": "Checkout",
"checkoutPage.titleReceipt": "Receipt",
"cms.shopByCategory": "Shop by category",
"cmsBlock.noBlocks": "There are no blocks to display",
"communicationsPage.changesText": "Save Changes",
Expand All @@ -108,7 +108,7 @@
"communicationsPage.preferencesText": "Your preferences have been updated.",
"communicationsPage.savingText": "Saving",
"communicationsPage.subscribeText": "Stay on the cutting edge of fashion; subscribe to the monthly Venia Newsletter.",
"communicationsPage.title": "Communications - {name}",
"communicationsPage.title": "Communications",
"completedView.errorLoading": "Error loading selected shipping method. Please select again.",
"completedView.shippingMethod": "Shipping Method",
"Contact Us": "Contact Us",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import createTestInstance from '@magento/peregrine/lib/util/createTestInstance';
import { useQuery } from '@apollo/client';
import CategoryList from '../../../components/CategoryList';
import RichContent from '../../../components/RichContent';
import { Title } from '../../../components/Head';
import { StoreTitle } from '../../../components/Head';
import CMSPage from '../cms';
import { useAppContext } from '@magento/peregrine/lib/context/app';

jest.mock('../../../classify');

jest.mock('../../../components/Head', () => ({
HeadProvider: ({ children }) => <div>{children}</div>,
Title: () => 'Title',
StoreTitle: () => 'Title',
Meta: () => 'Meta'
}));
jest.mock('../../../components/LoadingIndicator', () => {
Expand Down Expand Up @@ -173,7 +173,7 @@ test('render meta information based on meta data from GraphQL', () => {
});

const { root } = createTestInstance(<CMSPage {...props} />);
const title = root.findByType(Title);
const title = root.findByType(StoreTitle);
expect(title).toBeTruthy();
expect(title.props.children).toEqual('Test Meta Title');

Expand Down
4 changes: 2 additions & 2 deletions packages/venia-ui/lib/RootComponents/CMS/cms.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { fullPageLoadingIndicator } from '../../components/LoadingIndicator';
import { useCmsPage } from '@magento/peregrine/lib/talons/Cms/useCmsPage';
import RichContent from '../../components/RichContent';
import CategoryList from '../../components/CategoryList';
import { Meta, Title } from '../../components/Head';
import { Meta, StoreTitle } from '../../components/Head';
import { mergeClasses } from '../../classify';
import { useIntl } from 'react-intl';

Expand Down Expand Up @@ -46,7 +46,7 @@ const CMSPage = props => {

return (
<Fragment>
<Title>{pageTitle}</Title>
<StoreTitle>{pageTitle}</StoreTitle>
<Meta name="title" content={pageTitle} />
<Meta name="description" content={meta_description} />
{headingElement}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jest.mock('@magento/peregrine/lib/talons/RootComponents/Category', () => ({

jest.mock('../../../components/Head', () => ({
HeadProvider: ({ children }) => <div>{children}</div>,
Title: () => 'Title',
StoreTitle: () => 'Title',
Meta: () => 'Meta'
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jest.mock('@magento/peregrine/lib/context/app', () => {

jest.mock('../../../components/Head', () => ({
HeadProvider: ({ children }) => <div>{children}</div>,
Title: () => 'Title'
StoreTitle: () => 'Title'
}));

jest.mock('../../../components/Breadcrumbs', () => 'Breadcrumbs');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { mergeClasses } from '../../classify';
import Breadcrumbs from '../../components/Breadcrumbs';
import Button from '../../components/Button';
import Gallery from '../../components/Gallery';
import { Title } from '../../components/Head';
import { StoreTitle } from '../../components/Head';
import Pagination from '../../components/Pagination';
import ProductSort from '../../components/ProductSort';
import RichContent from '../../components/RichContent';
Expand All @@ -33,7 +33,6 @@ const CategoryContent = props => {
handleLoadFilters,
handleOpenFilters,
items,
pageTitle,
totalPagesFromData
} = talonProps;

Expand Down Expand Up @@ -101,7 +100,7 @@ const CategoryContent = props => {
return (
<Fragment>
<Breadcrumbs categoryId={categoryId} />
<Title>{pageTitle}</Title>
<StoreTitle>{categoryName}</StoreTitle>
<article className={classes.root}>
<h1 className={classes.title}>
<div className={classes.categoryTitle}>{categoryName}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

exports[`renders product page correctly 1`] = `
<React.Fragment>
<Title>
Fitted Dress with Belt - Venia
</Title>
<StoreTitle>
Fitted Dress with Belt
</StoreTitle>
<Meta
content="Team these printed palazzo pants with a solid tank top and summer-ready sandals"
name="description"
Expand Down Expand Up @@ -99,9 +99,9 @@ exports[`renders product page correctly 1`] = `

exports[`renders product page correctly when error and product data exist 1`] = `
<React.Fragment>
<Title>
Fitted Dress with Belt - Venia
</Title>
<StoreTitle>
Fitted Dress with Belt
</StoreTitle>
<Meta
content="Team these printed palazzo pants with a solid tank top and summer-ready sandals"
name="description"
Expand Down
7 changes: 2 additions & 5 deletions packages/venia-ui/lib/RootComponents/Product/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FormattedMessage } from 'react-intl';
import { useProduct } from '@magento/peregrine/lib/talons/RootComponents/Product/useProduct';

import ErrorView from '@magento/venia-ui/lib/components/ErrorView';
import { Title, Meta } from '@magento/venia-ui/lib/components/Head';
import { StoreTitle, Meta } from '@magento/venia-ui/lib/components/Head';
import { fullPageLoadingIndicator } from '@magento/venia-ui/lib/components/LoadingIndicator';
import ProductFullDetail from '@magento/venia-ui/lib/components/ProductFullDetail';
import mapProduct from '@magento/venia-ui/lib/util/mapProduct';
Expand Down Expand Up @@ -38,12 +38,9 @@ const Product = () => {
);
}

// Note: STORE_NAME is injected by Webpack at build time.
const title = `${product.name} - ${STORE_NAME}`;

return (
<Fragment>
<Title>{title}</Title>
<StoreTitle>{product.name}</StoreTitle>
<Meta name="description" content={product.meta_description} />
<ProductFullDetail product={product} />
</Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const emptyFormProps = {
showUpdateMode
};

jest.mock('../../Head', () => ({ Title: () => 'Account Information' }));
jest.mock('../../Head', () => ({ StoreTitle: () => 'Account Information' }));

jest.mock('@magento/venia-drivers', () => ({
Redirect: props => <mock-Redirect {...props} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useAccountInformationPage } from '@magento/peregrine/lib/talons/Account
import { mergeClasses } from '../../classify';
import Button from '../Button';
import { Message } from '../Field';
import { Title } from '../Head';
import { StoreTitle } from '../Head';
import { fullPageLoadingIndicator } from '../LoadingIndicator';

import defaultClasses from './accountInformationPage.css';
Expand Down Expand Up @@ -123,15 +123,12 @@ const AccountInformationPage = props => {

return (
<div className={classes.root}>
<Title>
{formatMessage(
{
id: 'accountInformationPage.titleAccount',
defaultMessage: 'Account Information'
},
{ name: STORE_NAME }
)}
</Title>
<StoreTitle>
{formatMessage({
id: 'accountInformationPage.titleAccount',
defaultMessage: 'Account Information'
})}
</StoreTitle>
<h1 className={classes.title}>
<FormattedMessage
id={'accountInformationPage.accountInformation'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import AddressBookPage from '../addressBookPage';

jest.mock('@magento/venia-ui/lib/classify');

jest.mock('../../Head', () => ({ Title: () => 'Title' }));
jest.mock('../../Head', () => ({ StoreTitle: () => 'Title' }));
jest.mock('../../Icon', () => 'Icon');
jest.mock(
'@magento/peregrine/lib/talons/AddressBookPage/useAddressBookPage',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PlusSquare } from 'react-feather';

import { useAddressBookPage } from '@magento/peregrine/lib/talons/AddressBookPage/useAddressBookPage';
import { mergeClasses } from '@magento/venia-ui/lib/classify';
import { Title } from '@magento/venia-ui/lib/components/Head';
import { StoreTitle } from '@magento/venia-ui/lib/components/Head';
import Icon from '@magento/venia-ui/lib/components/Icon';
import LinkButton from '@magento/venia-ui/lib/components/LinkButton';
import { fullPageLoadingIndicator } from '@magento/venia-ui/lib/components/LoadingIndicator';
Expand Down Expand Up @@ -90,11 +90,9 @@ const AddressBookPage = props => {
return fullPageLoadingIndicator;
}

// STORE_NAME is injected by Webpack at build time.
const title = `${PAGE_TITLE} - ${STORE_NAME}`;
return (
<div className={classes.root}>
<Title>{title}</Title>
<StoreTitle>{PAGE_TITLE}</StoreTitle>
<h1 className={classes.heading}>{PAGE_TITLE}</h1>
<div className={classes.content}>
{addressBookElements}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ exports[`displays open nav or drawer 1`] = `

exports[`renders with renderErrors 1`] = `
<HeadProvider>
<Title>
Venia
</Title>
<StoreTitle />
<Main
isMasked={true}
/>
Expand All @@ -33,9 +31,7 @@ exports[`renders with renderErrors 1`] = `

exports[`renders with unhandledErrors 1`] = `
<HeadProvider>
<Title>
Venia
</Title>
<StoreTitle />
<Main
isMasked={false}
>
Expand Down
Loading

0 comments on commit e28e094

Please sign in to comment.