diff --git a/.changeset/react-components-bookmark_app-loading.md b/.changeset/react-components-bookmark_app-loading.md new file mode 100644 index 0000000000..bfb230f638 --- /dev/null +++ b/.changeset/react-components-bookmark_app-loading.md @@ -0,0 +1,5 @@ +--- +"@equinor/fusion-framework-react-components-bookmark": patch +--- + +Show accessible loading feedback for the app name while the edit bookmark modal resolves its app manifest. diff --git a/packages/react/components/bookmark/README.md b/packages/react/components/bookmark/README.md index af3497e853..ba799db666 100644 --- a/packages/react/components/bookmark/README.md +++ b/packages/react/components/bookmark/README.md @@ -59,7 +59,7 @@ The provider manages modal state for creating, editing, and importing bookmarks. - **Filtering** — text search across bookmark names - **Grouping** — group bookmarks by app, creator, or other criteria - **Create modal** — form for creating new bookmarks -- **Edit modal** — form for updating existing bookmarks +- **Edit modal** — form for updating existing bookmarks with loading feedback while resolving the source app name - **Import modal** — import bookmarks shared via URL - **Clipboard sharing** — copy bookmark URL to clipboard diff --git a/packages/react/components/bookmark/package.json b/packages/react/components/bookmark/package.json index 66c2537993..26c3bd8ad7 100644 --- a/packages/react/components/bookmark/package.json +++ b/packages/react/components/bookmark/package.json @@ -12,7 +12,8 @@ "types": "./dist/types/index.d.ts", "scripts": { "build": "tsc -b", - "prepack": "pnpm build" + "prepack": "pnpm build", + "test": "vitest --run" }, "keywords": [], "author": "", @@ -42,7 +43,8 @@ "@types/react": "^19.2.7", "react": "^19.2.1", "styled-components": "^6.3.11", - "typescript": "^7.0.2" + "typescript": "^7.0.2", + "vitest": "^4.1.0" }, "peerDependencies": { "@equinor/eds-core-react": "^2.0.0", diff --git a/packages/react/components/bookmark/src/__tests__/AppNameField.test.tsx b/packages/react/components/bookmark/src/__tests__/AppNameField.test.tsx new file mode 100644 index 0000000000..ae0a159126 --- /dev/null +++ b/packages/react/components/bookmark/src/__tests__/AppNameField.test.tsx @@ -0,0 +1,39 @@ +import { isValidElement } from 'react'; +import { Input, Progress } from '@equinor/eds-core-react'; +import { describe, expect, it } from 'vitest'; +import { AppNameField } from '../components/edit-bookmark/AppNameField'; + +describe('AppNameField', () => { + it('shows an accessible progress indicator while the manifest is loading', () => { + const field = AppNameField({ id: 'app', isLoading: true }); + const loadingIndicator = field.props.rightAdornments; + + expect(field.type).toBe(Input); + expect(field.props.id).toBe('app'); + expect(field.props['aria-busy']).toBe(true); + expect(isValidElement(loadingIndicator)).toBe(true); + + // Guard the element shape before inspecting progress-specific props. + if (!isValidElement(loadingIndicator)) { + throw new Error('Expected a valid loading indicator'); + } + + expect(loadingIndicator.type).toBe(Progress.Circular); + expect(loadingIndicator.props).toMatchObject({ + 'aria-label': 'Loading app name', + size: 16, + }); + }); + + it('shows the resolved display name without a progress indicator', () => { + const field = AppNameField({ + id: 'app', + displayName: 'My app', + isLoading: false, + }); + + expect(field.props.value).toBe('My app'); + expect(field.props['aria-busy']).toBe(false); + expect(field.props.rightAdornments).toBeUndefined(); + }); +}); diff --git a/packages/react/components/bookmark/src/components/edit-bookmark/AppNameField.tsx b/packages/react/components/bookmark/src/components/edit-bookmark/AppNameField.tsx new file mode 100644 index 0000000000..96ce21cddb --- /dev/null +++ b/packages/react/components/bookmark/src/components/edit-bookmark/AppNameField.tsx @@ -0,0 +1,27 @@ +import { Input, Progress } from '@equinor/eds-core-react'; + +/** + * Renders the bookmark's app name while making manifest resolution visible. + * + * @param props - The resolved display name and whether the manifest request is pending. + * @returns A read-only app name field with an accessible loading indicator when needed. + */ +export const AppNameField = ({ + id, + displayName, + isLoading, +}: { + readonly id: string; + readonly displayName?: string; + readonly isLoading: boolean; +}) => ( + : undefined + } + /> +); diff --git a/packages/react/components/bookmark/src/components/edit-bookmark/EditBookmarkModal.tsx b/packages/react/components/bookmark/src/components/edit-bookmark/EditBookmarkModal.tsx index 6b3da736c6..afbd5f94c2 100644 --- a/packages/react/components/bookmark/src/components/edit-bookmark/EditBookmarkModal.tsx +++ b/packages/react/components/bookmark/src/components/edit-bookmark/EditBookmarkModal.tsx @@ -12,6 +12,7 @@ import { Button, Checkbox, Dialog, Input, Label, Textarea } from '@equinor/eds-c import styled from 'styled-components'; import { useBookmarkComponentContext } from '../BookmarkProvider'; +import { AppNameField } from './AppNameField'; const Styled = { Dialog: styled(Dialog)` @@ -60,6 +61,7 @@ export const EditBookmarkModal = ({ const nameId = useId(); const descriptionId = useId(); + const appId = useId(); const [updatePayload, setUpdatePayload] = useState(false); @@ -81,12 +83,16 @@ export const EditBookmarkModal = ({ // TODO(#5091): this should be on the bookmark object const appProvider = useFrameworkModule('app'); - const { value: appName } = useObservableState( + const { value: appName, error: appNameError } = useObservableState( useMemo( () => (bookmark && appProvider ? appProvider.getAppManifest(bookmark.appKey) : of(undefined)), [appProvider, bookmark], ), ); + // Only report a pending manifest request; missing providers and failed requests are not loading. + const isAppNameLoading = Boolean( + bookmark && appProvider && appName === undefined && appNameError === null, + ); const updateBookmark = useCallback( async (updates: BookmarkUpdate) => { @@ -145,9 +151,8 @@ export const EditBookmarkModal = ({ /> - - {/** TODO(#5092): show ghost while loading app name */} - + + diff --git a/packages/react/components/bookmark/tsconfig.json b/packages/react/components/bookmark/tsconfig.json index c9bd5c7c7a..f0c3d6df2b 100644 --- a/packages/react/components/bookmark/tsconfig.json +++ b/packages/react/components/bookmark/tsconfig.json @@ -14,5 +14,5 @@ } ], "include": ["src/**/*"], - "exclude": ["node_modules", "lib"] + "exclude": ["node_modules", "lib", "src/__tests__/**/*"] } diff --git a/packages/react/components/bookmark/vitest.config.ts b/packages/react/components/bookmark/vitest.config.ts new file mode 100644 index 0000000000..0f7388e379 --- /dev/null +++ b/packages/react/components/bookmark/vitest.config.ts @@ -0,0 +1,10 @@ +import { defineProject } from 'vitest/config'; + +import { name, version } from './package.json'; + +export default defineProject({ + test: { + include: ['src/__tests__/**/*.{test,spec}.{ts,tsx}'], + name: `${name}@${version}`, + }, +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0069041611..375ecab902 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2309,6 +2309,9 @@ importers: typescript: specifier: ^7.0.2 version: 7.0.2 + vitest: + specifier: ^4.1.0 + version: 4.1.4(@opentelemetry/api@1.9.1)(@types/node@26.1.2)(@vitest/coverage-v8@4.1.4)(happy-dom@20.11.1)(jsdom@30.0.1)(msw@2.15.0(@types/node@26.1.2)(typescript@7.0.2))(vite@8.1.5(@types/node@26.1.2)(esbuild@0.28.1)(sass-embedded@1.99.0)(sass@1.99.0)(terser@5.46.0)(tsx@4.23.1)) packages/react/components/people-resolver: dependencies: