Skip to content

Commit

Permalink
feat(foxy-store-card): add active/inactive status indicator
Browse files Browse the repository at this point in the history
  • Loading branch information
pheekus committed Aug 27, 2024
1 parent 39cca28 commit 3c20b7e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
21 changes: 21 additions & 0 deletions src/elements/public/StoreCard/StoreCard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,25 @@ describe('StoreCard', () => {

expect(await getByTestId(element, 'subtitle')).to.include.text('example.com');
});

it('renders store activity status in the subtitle', async () => {
const router = createRouter();
const href = 'https://demo.api/hapi/stores/0';
const element = await fixture<StoreCard>(html`
<foxy-store-card href=${href} @fetch=${(evt: FetchEvent) => router.handleEvent(evt)}>
</foxy-store-card>
`);

await waitUntil(() => !!element.data, undefined, { timeout: 5000 });
element.data = { ...element.data!, is_active: true };
await element.requestUpdate();
const subtitle = await getByTestId(element, 'subtitle');
expect(subtitle?.querySelector('[aria-label="status_active"]')).to.exist;
expect(subtitle?.querySelector('[aria-label="status_inactive"]')).to.not.exist;

element.data = { ...element.data!, is_active: false };
await element.requestUpdate();
expect(subtitle?.querySelector('[aria-label="status_active"]')).to.not.exist;
expect(subtitle?.querySelector('[aria-label="status_inactive"]')).to.exist;
});
});
14 changes: 13 additions & 1 deletion src/elements/public/StoreCard/StoreCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Data } from './types';

import { TranslatableMixin } from '../../../mixins/translatable';
import { TwoLineCard } from '../CustomFieldCard/TwoLineCard';
import { classMap } from '../../../utils/class-map';
import { html } from 'lit-html';

const NS = 'store-card';
Expand Down Expand Up @@ -32,7 +33,18 @@ export class StoreCard extends Base<Data> {
subtitle: data => {
const defaultD = this.defaultDomain;
const domain = data?.store_domain;
return html`${domain?.includes('.') || !defaultD ? domain : `${domain}.${defaultD}`}`;
return html`
<span
aria-label=${this.t(`status_${data.is_active ? 'active' : 'inactive'}`)}
style="width: 0.55em; height: 0.55em"
class=${classMap({
'inline-block flex-shrink-0 rounded-full': true,
'bg-success': data.is_active,
'border border-contrast-50': !data.is_active,
})}
></span>
${domain?.includes('.') || !defaultD ? domain : `${domain}.${defaultD}`}
`;
},
});
}
Expand Down
4 changes: 3 additions & 1 deletion src/static/translations/store-card/en.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"status_active": "Active",
"status_inactive": "Inactive",
"spinner": {
"loading_busy": "Loading",
"loading_empty": "No data",
"loading_error": "Unknown error"
}
}
}

0 comments on commit 3c20b7e

Please sign in to comment.