Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# React Aria controlled props are cleared with null, not undefined

- **Status:** Accepted
- **Revisions:** v1 2026-11-13 (initial)
- **Revisions:** v1 2026-11-13 (initial) · v2 2026-11-17 (example component removed)
- **Deciders:** Chirag Madlani
- **Guard:** ESLint `openmetadata-ui-patterns/no-undefined-controlled-prop` (error)
- **Related:** #37771, #37772
Expand All @@ -25,6 +25,10 @@ passes nothing, from its first render to its last.
## Consequences
The lint rule catches a literal `undefined` fallback in a JSX prop. It cannot see a variable whose type
merely includes `undefined` (`useState<string>()` passed straight through); review those, and prefer
initialising such state to `null`. A component that deliberately flips — `CopyToClipboardButton`
forcing its tooltip open after a copy while leaving hover to React Aria — disables the rule on that
line with the reason beside it.
initialising such state to `null`. A component that deliberately flips — a tooltip forced open
after an action while hover is left to React Aria — disables the rule on that line with the reason
beside it.

## Amendment
v2 2026-11-17: the original example, `CopyToClipboardButton`, was removed by
ADR:2026-11-17-copy-actions-use-the-shared-copy-button; the rule and its exception are unchanged.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copy-to-clipboard actions use the shared CopyButton

- **Status:** Accepted
- **Revisions:** v1 2026-11-17 (initial)
- **Deciders:** Rohit Jain
- **Guard:** `CopyButton.test.tsx` (success state, accessible name, click does not reach a parent
row, labeled variant); reviewer for new call sites
- **Related:** open-metadata/OpenMetadata#37953

## Context
The UI had three copy components (`CopyLinkButton` in Context Center, `common/CopyLinkButton` for
field links, `common/CopyToClipboardButton`) and about thirty hand-rolled `ButtonUtility icon={Copy01}`
+ `useClipboard` blocks. Each gave different feedback — a toast, a tooltip swap, an icon swap, or
nothing — and some copy buttons inside clickable rows also triggered the row.

## Decision
- Every copy-to-clipboard action renders `components/common/CopyButton/CopyButton`: icon-only by
default, or a text button with `label`. Duplicate/clone actions that merely reuse the `Copy01`
glyph, and dropdown menu items, are not copy buttons and stay as they are.
- Success is shown by the button itself: icon-only turns into a green circle with a check and a ring
pulse, and its tooltip reads "Copied"; the labeled variant turns green and its text reads "Copied".
A copy action does not also raise a success toast.
- The copied state resets after 1200 ms — long enough to read the check, short enough to copy again.
- `CopyButton` stops propagation and prevents default on click, so copying inside a clickable row,
card or form never activates it.
- Callers pass layout classes only; the copied colours are applied after the caller's `className`
so they always win.

## Consequences
Copy feedback looks and behaves the same everywhere, and a new copy action is one element. A failed
copy (clipboard API and `execCommand` both refused) leaves the button idle without a message; add an
error path to `useClipboard` if that turns out to matter. Revisit if a surface needs a copy action
whose feedback must outlive the 1200 ms state (for example a one-time secret that must be
acknowledged).
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jest.mock('../../Database/TableTags/TableTags.component', () =>
</div>
))
);
jest.mock('../../common/CopyLinkButton/CopyLinkButton', () =>
jest.mock('../../common/CopyButton/CopyButton', () =>
jest.fn(() => <div data-testid="copy-link-button" />)
);
jest.mock('../../common/ToggleExpandButton/ToggleExpandButton', () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import { getEntityName } from '../../../utils/EntityNameUtils';
import { getColumnSorter } from '../../../utils/EntitySortUtils';
import { getDerivedPermissionFlags } from '../../../utils/PermissionDerivation';
import { getEntityDetailsUrl } from '../../../utils/RouterUtils';
import { getVersionedSchema } from '../../../utils/SchemaVersionUtils';
import { columnFilterIcon } from '../../../utils/TableColumn.util';
import {
Expand All @@ -76,7 +77,7 @@
import { getAllTags } from '../../../utils/TableTags/TableTags.utils';
import { getTableExpandableConfig } from '../../../utils/TableUtils';
import withSuspenseFallback from '../../AppRouter/withSuspenseFallback';
import CopyLinkButton from '../../common/CopyLinkButton/CopyLinkButton';
import CopyButton from '../../common/CopyButton/CopyButton';
import { EntityAttachmentProvider } from '../../common/EntityDescription/EntityAttachmentProvider/EntityAttachmentProvider';
import RichTextEditorPreviewerV1 from '../../common/RichTextEditor/RichTextEditorPreviewerV1';
import Table from '../../common/Table/TableV2';
Expand Down Expand Up @@ -321,9 +322,15 @@
</span>
</Tooltip>
{!isVersionView && record.fullyQualifiedName && (
<CopyLinkButton
entityType={EntityType.API_ENDPOINT}
fieldFqn={record.fullyQualifiedName}
<CopyButton
className="hover-cell-icon"
isDisabled={!record.fullyQualifiedName}
size="xs"
testId="copy-field-link-button"
value={getEntityDetailsUrl(
EntityType.API_ENDPOINT,
record.fullyQualifiedName ?? ''
)}
/>
)}
</div>
Expand Down Expand Up @@ -489,7 +496,7 @@
filteredValue: tagFilterState[TABLE_COLUMNS_KEYS.GLOSSARY] ?? null,
},
],
[

Check warning on line 499 in openmetadata-ui/src/main/resources/ui/src/components/APIEndpoint/APIEndpointSchema/APIEndpointSchema.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

React Hook useMemo has a missing dependency: 't'. Either include it or remove the dependency array
apiEndpointDetails,
editFieldDescription,
renderSchemaName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,39 +10,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { ButtonUtility, Tooltip } from '@openmetadata/ui-core-components';
import { Copy01 } from '@openmetadata/ui-core-components/icons';
import { NodeViewContent, NodeViewProps, NodeViewWrapper } from '@tiptap/react';
import { FC, useCallback, useState } from 'react';
import { FC } from 'react';
import { useTranslation } from 'react-i18next';
import { useClipboard } from '../../../../hooks/useClipBoard';
import CopyButton from '../../../common/CopyButton/CopyButton';

const CodeBlockComponent: FC<NodeViewProps> = ({ node }) => {
const { t } = useTranslation();
const { onCopyToClipBoard, hasCopied } = useClipboard('', 2000);
const [isTooltipOpen, setIsTooltipOpen] = useState(false);

const handleCopy = useCallback(async () => {
await onCopyToClipBoard(node.textContent);
}, [node, onCopyToClipBoard]);

return (
<NodeViewWrapper as="pre" className="relative code-block">
<NodeViewWrapper as="pre" className="tw:group tw:relative code-block">
<NodeViewContent<'code'> as="code" />
<span className="code-copy-button" data-copied={hasCopied}>
<Tooltip
isOpen={hasCopied || isTooltipOpen}
title={hasCopied ? t('label.copied') : t('label.copy')}
onOpenChange={setIsTooltipOpen}>
<ButtonUtility
aria-label={t('label.copy')}
data-testid="code-block-copy-icon"
icon={Copy01}
size="lg"
onClick={handleCopy}
/>
</Tooltip>
</span>
<CopyButton
className="tw:absolute tw:top-1.5 tw:right-1.5 tw:opacity-0 tw:group-hover:opacity-60 tw:hover:opacity-100 tw:focus-visible:opacity-100"
testId="code-block-copy-icon"
tooltip={t('label.copy')}
value={node.textContent}
/>
</NodeViewWrapper>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ jest.mock('../../../utils/RouterUtils', () => ({
getEntityDetailsPath: jest
.fn()
.mockImplementation((_entityType, fqn) => `/container/${fqn}`),
getEntityDetailsUrl: jest
.fn()
.mockImplementation(
(_entityType, fqn) => `http://localhost/container/${fqn}`
),
}));

jest.mock(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
updateContainerColumnTags,
} from '../../../utils/ContainerDetailPureUtils';
import { getEntityName } from '../../../utils/EntityNameUtils';
import { getEntityDetailsUrl } from '../../../utils/RouterUtils';
import { columnFilterIcon } from '../../../utils/TableColumn.util';
import {
getHighlightedRowClassName,
Expand All @@ -55,7 +56,7 @@
import { getAllTags } from '../../../utils/TableTags/TableTags.utils';
import { getTableExpandableConfig } from '../../../utils/TableUtils';
import withSuspenseFallback from '../../AppRouter/withSuspenseFallback';
import CopyLinkButton from '../../common/CopyLinkButton/CopyLinkButton';
import CopyButton from '../../common/CopyButton/CopyButton';
import NoDataPlaceholder from '../../common/EmptyPlaceholder/NoDataPlaceholder';
import { EntityAttachmentProvider } from '../../common/EntityDescription/EntityAttachmentProvider/EntityAttachmentProvider';
import { ColumnsType } from '../../common/Table/Table.interface';
Expand Down Expand Up @@ -207,10 +208,15 @@
</Typography>
</Tooltip>
{record.fullyQualifiedName && (
<CopyLinkButton
entityType={EntityType.CONTAINER}
fieldFqn={record.fullyQualifiedName}
<CopyButton
className="hover-cell-icon"
isDisabled={!record.fullyQualifiedName}
size="xs"
testId="copy-column-link-button"
value={getEntityDetailsUrl(
EntityType.CONTAINER,
record.fullyQualifiedName ?? ''
)}
/>
)}
</div>
Expand Down Expand Up @@ -306,7 +312,7 @@
),
},
],
[

Check warning on line 315 in openmetadata-ui/src/main/resources/ui/src/components/Container/ContainerDataModel/ContainerDataModel.tsx

View workflow job for this annotation

GitHub Actions / checkstyle

React Hook useMemo has missing dependencies: 't', 'tagFilter.Classification', and 'tagFilter.Glossary'. Either include them or remove the dependency array. Outer scope values like 'getEntityName' aren't valid dependencies because mutating them doesn't re-render the component
isReadOnly,
entityFqn,
hasTagEditAccess,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {
} from '@openmetadata/ui-core-components';
import {
Conversation,
Copy01,
DotsVertical,
Edit01,
ExpandPanel,
Expand Down Expand Up @@ -81,11 +80,11 @@ import { getKnowledgePageName } from '../../../utils/KnowledgePagePureUtils';
import { updateKnowledgeCenterRecentViewed } from '../../../utils/KnowledgePageUtils';
import { getDerivedPermissionFlags } from '../../../utils/PermissionDerivation';
import { showErrorToast } from '../../../utils/ToastUtils';
import CopyButton from '../../common/CopyButton/CopyButton';
import DomainSelectableList from '../../common/DomainSelectableList/DomainSelectableList.component';
import HeaderBreadcrumb from '../../common/HeaderBreadcrumb/HeaderBreadcrumb.component';
import { HeaderVersionButton } from '../../common/HeaderVersionButton/HeaderVersionButton.component';
import { UserTeamSelectableList } from '../../common/UserTeamSelectableList/UserTeamSelectableList.component';
import CopyLinkButton from '../../CopyLinkButton/CopyLinkButton.component';
import { ArticleDetailHeaderProps } from './ArticleDetailHeader.interface';

const TOOLTIP_TRIGGER_CLASS = 'tw:leading-0';
Expand Down Expand Up @@ -547,9 +546,7 @@ const ArticleDetailHeader: FC<ArticleDetailHeaderProps> = ({
tooltip={isFollowing ? t('label.un-follow') : t('label.follow')}
onClick={handleFollowClick}
/>
<CopyLinkButton testId="copy-btn" url={window.location.href}>
<Copy01 data-icon />
</CopyLinkButton>
<CopyButton testId="copy-btn" value={window.location.href} />

{permissions?.Delete && (
<Dropdown.Root>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
FileIcon,
Typography,
} from '@openmetadata/ui-core-components';
import { Copy01, XClose } from '@openmetadata/ui-core-components/icons';
import { XClose } from '@openmetadata/ui-core-components/icons';
import { FC, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { CONTEXT_FILE_ENTITY_TYPE } from '../../../constants/ContextCenter.constants';
Expand All @@ -31,7 +31,7 @@ import { formatBytes } from '../../../utils/ContextCenterPureUtils';
import { getShortRelativeTime } from '../../../utils/date-time/DateTimeUtils';
import { getFileExtractionAction } from '../../../utils/discovery/context-center/memoryExtraction.utils';
import { getEntityName } from '../../../utils/EntityNameUtils';
import CopyLinkButton from '../../CopyLinkButton/CopyLinkButton.component';
import CopyButton from '../../common/CopyButton/CopyButton';
import MemoryExtractionButton from '../../discovery/context-center/MemoryExtractionButton/MemoryExtractionButton';
import DocumentStatusBadge from '../DocumentStatusBadge/DocumentStatusBadge.component';
import ExtractedMemoriesCard from '../ExtractedMemoriesCard/ExtractedMemoriesCard.component';
Expand Down Expand Up @@ -100,9 +100,7 @@ const DocumentPreviewPanel: FC<DocumentPreviewPanelProps> = ({
</div>
</Box>
<Box align="center" gap={2}>
<CopyLinkButton size="lg" url={url}>
<Copy01 data-icon aria-hidden="true" />
</CopyLinkButton>
<CopyButton size="lg" value={url} />
<ButtonUtility
data-testid="close-preview-btn"
icon={XClose}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ jest.mock('@openmetadata/ui-core-components', () => ({
),
}));

jest.mock('../../CopyLinkButton/CopyLinkButton.component', () =>
jest.fn(({ url }: { url: string }) => (
<button data-testid="copy-link-btn" data-url={url}>
jest.mock('../../common/CopyButton/CopyButton', () =>
jest.fn(({ value }: { value: string }) => (
<button data-testid="copy-link-btn" data-url={value}>
copy
</button>
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
import {
Check,
ChevronRight,
Copy01,
Documents,
DotsVertical,
Download01,
Expand Down Expand Up @@ -63,13 +62,13 @@ import { getShortRelativeTime } from '../../../utils/date-time/DateTimeUtils';
import { getFileExtractionAction } from '../../../utils/discovery/context-center/memoryExtraction.utils';
import { getEntityName } from '../../../utils/EntityNameUtils';
import { showErrorToast, showSuccessToast } from '../../../utils/ToastUtils';
import CopyButton from '../../common/CopyButton/CopyButton';
import NoDataPlaceholder from '../../common/EmptyPlaceholder/NoDataPlaceholder';
import NoSearchResultsPlaceholder from '../../common/EmptyPlaceholder/NoSearchResultsPlaceholder';
import { PreviewRendererId } from '../../common/FilePreviewer/FilePreviewer.types';
import { resolveRenderer } from '../../common/FilePreviewer/FilePreviewer.utils';
import UserPopOverCard from '../../common/PopOverCard/UserPopOverCard';
import { UserSelectableList } from '../../common/UserSelectableList/UserSelectableList.component';
import CopyLinkButton from '../../CopyLinkButton/CopyLinkButton.component';
import MemoryExtractionMenuItem from '../../discovery/context-center/MemoryExtractionMenuItem/MemoryExtractionMenuItem';
import DocumentStatusBadge from '../DocumentStatusBadge/DocumentStatusBadge.component';
import {
Expand Down Expand Up @@ -795,9 +794,7 @@ const FileRow: FC<FileRowProps> = ({
tooltip={t('label.download')}
onClick={() => onDownload?.(file)}
/>
<CopyLinkButton size="lg" url={rowUrl}>
<Copy01 data-icon aria-hidden="true" />
</CopyLinkButton>
<CopyButton size="lg" value={rowUrl} />
<FileActions
canDelete={canDelete}
canEdit={canEdit}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
Typography,
} from '@openmetadata/ui-core-components';
import {
Copy01,
DotsVertical,
Edit01,
NoFilterFunnel,
Expand All @@ -48,9 +47,9 @@ import { getMemoryCitations } from '../../../utils/ContextCenterPureUtils';
import { getShortRelativeTime } from '../../../utils/date-time/DateTimeUtils';
import { getEntityName } from '../../../utils/EntityNameUtils';
import { stripMarkdown } from '../../../utils/RichTextStringUtils';
import CopyButton from '../../common/CopyButton/CopyButton';
import NoFilteredResultsPlaceholder from '../../common/EmptyPlaceholder/NoFilteredResultsPlaceholder';
import NoSearchResultsPlaceholder from '../../common/EmptyPlaceholder/NoSearchResultsPlaceholder';
import CopyLinkButton from '../../CopyLinkButton/CopyLinkButton.component';
import {
MemoriesViewProps,
MemoryActionsProps,
Expand Down Expand Up @@ -308,9 +307,7 @@ const MemoryRowActions: FC<MemoryRowActionsProps> = ({

return (
<Box align="center" gap={1} onClick={(e) => e.stopPropagation()}>
<CopyLinkButton url={memoryUrl}>
<Copy01 data-icon aria-hidden="true" />
</CopyLinkButton>
<CopyButton value={memoryUrl} />
{canActOnMemory && canEdit && onEditMemory && (
<ButtonUtility
data-testid="edit-memory-btn"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jest.mock('../../../rest/contextMemoryAPI', () => ({
getContextMemoryVersions: jest.fn(),
}));

jest.mock('../../CopyLinkButton/CopyLinkButton.component', () =>
jest.mock('../../common/CopyButton/CopyButton', () =>
jest.fn(() => <button aria-label="Copy link" data-testid="copy-link-btn" />)
);

Expand Down
Loading
Loading