Skip to content

Commit b675422

Browse files
committed
fix(FR-1948): fix broken Storybook components on ui.backend.ai (#5130)
Resolves #5111 ([FR-1948](https://lablup.atlassian.net/browse/FR-1948)) ## Summary Fixed three broken Storybook components on ui.backend.ai: ### 1. BAIFetchKeyButton - dayjs relativeTime error - **Issue**: `me(...).fromNow is not a function` error - **Root cause**: dayjs relativeTime plugin not loaded in Storybook - **Fix**: Added all dayjs plugins (relativeTime, duration, utc, timezone, weekday, localeData, localizedFormat) and 21 locale imports to `.storybook/decorators.tsx` to match `BAIConfigProvider` configuration ### 2. BAIAdminResourceGroupSelect - items displayed as one - **Issue**: All dropdown items displayed as a single item instead of separate options - **Root cause**: Incorrect mock resolver type `ScalingGroupV2Connection` instead of `ResourceGroupConnection` - **Fix**: Updated mock resolvers to use `ResourceGroupConnection` type across all story variants (Default, Empty, WithCustomPlaceholder, Disabled) ### 3. BAILink - Font not applied with WebUI theme - **Issue**: react-router-dom `Link` component doesn't inherit Ant Design theme styles - **Root cause**: react-router-dom Link doesn't automatically apply Ant Design theme tokens - **Fix**: Added `theme.useToken()` to access fontFamily token and applied it via inline style to ensure consistent font rendering in Storybook WebUI theme ## Changes - `packages/backend.ai-ui/.storybook/decorators.tsx`: Added dayjs plugins and locale support - `packages/backend.ai-ui/src/components/BAILink.tsx`: Applied Ant Design theme fontFamily to Link component - `packages/backend.ai-ui/src/components/fragments/BAIAdminResourceGroupSelect.stories.tsx`: Fixed mock resolver type **Checklist:** - [x] All three Storybook components now render correctly on ui.backend.ai - [x] dayjs `fromNow()` function works in BAIFetchKeyButton - [x] BAIAdminResourceGroupSelect displays items as separate options - [x] BAILink applies correct font with WebUI theme [FR-1948]: https://lablup.atlassian.net/browse/FR-1948?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent df6385f commit b675422

3 files changed

Lines changed: 49 additions & 6 deletions

File tree

packages/backend.ai-ui/.storybook/decorators.tsx

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,41 @@
11
import BAIText from '../src/components/BAIText';
22
import { i18n } from '../src/locale';
3+
import dayjs from 'dayjs';
4+
import 'dayjs/locale/de';
5+
import 'dayjs/locale/el';
6+
import 'dayjs/locale/es';
7+
import 'dayjs/locale/fi';
8+
import 'dayjs/locale/fr';
9+
import 'dayjs/locale/id';
10+
import 'dayjs/locale/it';
11+
import 'dayjs/locale/ja';
12+
import 'dayjs/locale/ko';
13+
import 'dayjs/locale/mn';
14+
import 'dayjs/locale/ms';
15+
import 'dayjs/locale/pl';
16+
import 'dayjs/locale/pt';
17+
import 'dayjs/locale/pt-br';
18+
import 'dayjs/locale/ru';
19+
import 'dayjs/locale/th';
20+
import 'dayjs/locale/tr';
21+
import 'dayjs/locale/vi';
22+
import 'dayjs/locale/zh-cn';
23+
import 'dayjs/locale/zh-tw';
24+
import duration from 'dayjs/plugin/duration';
25+
import localeData from 'dayjs/plugin/localeData';
26+
import localizedFormat from 'dayjs/plugin/localizedFormat';
27+
import relativeTime from 'dayjs/plugin/relativeTime';
28+
import timezone from 'dayjs/plugin/timezone';
29+
import utc from 'dayjs/plugin/utc';
30+
import weekday from 'dayjs/plugin/weekday';
31+
32+
dayjs.extend(weekday);
33+
dayjs.extend(localeData);
34+
dayjs.extend(localizedFormat);
35+
dayjs.extend(relativeTime);
36+
dayjs.extend(utc);
37+
dayjs.extend(timezone);
38+
dayjs.extend(duration);
339
import { getAntdLocale } from './localeConfig';
440
import { themeConfigs, type ThemeStyle } from './themeConfig';
541
import type { Decorator } from '@storybook/react-vite';
@@ -90,6 +126,7 @@ const StorybookProvider: React.FC<StorybookProviderProps> = ({
90126
}) => {
91127
useEffect(() => {
92128
i18n.changeLanguage(locale);
129+
dayjs.locale(locale);
93130
}, [locale]);
94131

95132
return (

packages/backend.ai-ui/src/components/BAILink.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Typography } from 'antd';
1+
import { theme, Typography } from 'antd';
22
import { createStyles } from 'antd-style';
33
import React from 'react';
44
import { Link, LinkProps } from 'react-router-dom';
@@ -34,8 +34,14 @@ const BAILink: React.FC<BAILinkProps> = ({
3434
...linkProps
3535
}) => {
3636
const { styles } = useStyles();
37+
const { token } = theme.useToken();
3738
return type !== 'disabled' && to ? (
38-
<Link className={type ? styles?.[type] : undefined} to={to} {...linkProps}>
39+
<Link
40+
className={type ? styles?.[type] : undefined}
41+
to={to}
42+
{...linkProps}
43+
style={{ fontFamily: token.fontFamily, ...linkProps.style }}
44+
>
3945
{children}
4046
</Link>
4147
) : (

packages/backend.ai-ui/src/components/fragments/BAIAdminResourceGroupSelect.stories.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const Default: Story = {
3838
render: () => (
3939
<RelayResolver
4040
mockResolvers={{
41-
ScalingGroupV2Connection: () => ({
41+
ResourceGroupConnection: () => ({
4242
count: 3,
4343
edges: [
4444
{ node: { id: 'rg-1', name: 'default' } },
@@ -59,7 +59,7 @@ export const Empty: Story = {
5959
render: () => (
6060
<RelayResolver
6161
mockResolvers={{
62-
ScalingGroupV2Connection: () => ({
62+
ResourceGroupConnection: () => ({
6363
count: 0,
6464
edges: [],
6565
}),
@@ -76,7 +76,7 @@ export const WithCustomPlaceholder: Story = {
7676
render: () => (
7777
<RelayResolver
7878
mockResolvers={{
79-
ScalingGroupV2Connection: () => ({
79+
ResourceGroupConnection: () => ({
8080
count: 5,
8181
edges: [
8282
{ node: { id: 'rg-1', name: 'development' } },
@@ -99,7 +99,7 @@ export const Disabled: Story = {
9999
render: () => (
100100
<RelayResolver
101101
mockResolvers={{
102-
ScalingGroupV2Connection: () => ({
102+
ResourceGroupConnection: () => ({
103103
count: 3,
104104
edges: [
105105
{ node: { id: 'rg-1', name: 'default' } },

0 commit comments

Comments
 (0)