Skip to content

Commit

Permalink
[Issue #1937] Translate Loading component text (#2186)
Browse files Browse the repository at this point in the history
## Summary
Fixes #1937

### Time to review: __5 mins__

## Changes proposed
Implemented the translation library for the text on the Search loading
spinner

## Context for reviewers
This component is currently under the Search page, but seems like we'd
likely reuse it elsewhere. Since file moves are weird to PR and revert I
wanted to get more input before moving stuff around.

## Additional information
Tested by implementing Storybook for this component
<img width="1089" alt="image"
src="https://github.com/user-attachments/assets/d03d5973-ec62-49b2-85d2-f5f204de6f9f">
  • Loading branch information
mdragon authored Sep 25, 2024
1 parent 380182c commit 8c4528d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 6 deletions.
14 changes: 10 additions & 4 deletions frontend/src/app/[locale]/search/loading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ import React from "react";

import Spinner from "src/components/Spinner";

export default function Loading() {
// TODO (Issue #1937): Use translation utility for strings in this file
export interface LoadingProps {
message?: string;
}

export default function Loading({ message }: LoadingProps) {
return (
<div className="display-flex flex-align-center flex-justify-center margin-bottom-15 margin-top-15">
<Spinner />
<span className="font-body-2xl text-bold margin-left-2">
Loading results...
<span
className="font-body-2xl text-bold margin-left-2"
data-testid="loading-message"
>
{message || "Loading"}...
</span>
</div>
);
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/app/[locale]/search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ function Search({ searchParams }: { searchParams: searchParamsTypes }) {
scroll={false}
/>
</Suspense>
<Suspense key={key} fallback={<Loading />}>
<Suspense
key={key}
fallback={<Loading message={t("loading")} />}
>
<SearchResultsListFetch
searchParams={convertedSearchParams}
/>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/i18n/messages/en/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,5 +497,6 @@ export const messages = {
select: "Select All",
clear: "Clear All",
},
loading: "Loading Results",
},
};
14 changes: 14 additions & 0 deletions frontend/stories/pages/loading.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Meta } from "@storybook/react";

import Loading from "../../src/app/[locale]/search/loading";

const meta: Meta<typeof Loading> = {
component: Loading,
};
export default meta;

export const Default = {
args: {
message: "Loading Storybook",
},
};
2 changes: 1 addition & 1 deletion frontend/tests/e2e/search/search-loading.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ test.describe("Search page tests", () => {
const searchTerm = "advanced";
await fillSearchInputAndSubmit(searchTerm, page);

const loadingIndicator = page.locator("text='Loading results...'");
const loadingIndicator = page.getByTestId("loading-message");
await expect(loadingIndicator).toBeVisible();
await expect(loadingIndicator).toBeHidden();

Expand Down

0 comments on commit 8c4528d

Please sign in to comment.