diff --git a/plugins/catalog-graph/report-alpha.api.md b/plugins/catalog-graph/report-alpha.api.md index cf5835e35c..1d906ebb68 100644 --- a/plugins/catalog-graph/report-alpha.api.md +++ b/plugins/catalog-graph/report-alpha.api.md @@ -126,9 +126,9 @@ const _default: FrontendPlugin< direction?: Direction | undefined; zoom?: 'disabled' | 'enabled' | 'enable-on-click' | undefined; relations?: string[] | undefined; - rootEntityRefs?: string[] | undefined; maxDepth?: number | undefined; kinds?: string[] | undefined; + rootEntityRefs?: string[] | undefined; unidirectional?: boolean | undefined; mergeRelations?: boolean | undefined; relationPairs?: [string, string][] | undefined; diff --git a/plugins/catalog-react/report.api.md b/plugins/catalog-react/report.api.md index ed7e1e4971..1e5735bd86 100644 --- a/plugins/catalog-react/report.api.md +++ b/plugins/catalog-react/report.api.md @@ -243,24 +243,6 @@ export type EntityAutocompletePickerProps< hidden?: boolean; }; -// @public (undocumented) -export type EntityContextMenuContextValue = { - onMenuClose: () => void; -}; - -// @public (undocumented) -export const EntityContextMenuProvider: ( - props: EntityContextMenuProviderProps, -) => React_2.JSX.Element; - -// @public (undocumented) -export interface EntityContextMenuProviderProps { - // (undocumented) - children: React_2.ReactNode; - // (undocumented) - onMenuClose: () => void; -} - // @public export const EntityDisplayName: (props: EntityDisplayNameProps) => JSX.Element; @@ -796,9 +778,6 @@ export function useEntity(): { entity: TEntity; }; -// @public (undocumented) -export function useEntityContextMenu(): EntityContextMenuContextValue; - // @public export function useEntityList< EntityFilters extends DefaultEntityFilters = DefaultEntityFilters, diff --git a/plugins/catalog-react/src/hooks/index.ts b/plugins/catalog-react/src/hooks/index.ts index 96a7315ca5..befcce520d 100644 --- a/plugins/catalog-react/src/hooks/index.ts +++ b/plugins/catalog-react/src/hooks/index.ts @@ -35,15 +35,6 @@ export type { EntityListProviderProps, PaginationMode, } from './useEntityListProvider'; -export type { - EntityContextMenuContextValue, - EntityContextMenuProviderProps, -} from './useEntityContextMenu'; -export { - EntityContextMenuProvider, - useEntityContextMenu, -} from './useEntityContextMenu'; - export { useEntityTypeFilter } from './useEntityTypeFilter'; export { useRelatedEntities } from './useRelatedEntities'; export { useStarredEntities } from './useStarredEntities'; diff --git a/plugins/catalog-react/src/hooks/useEntityContextMenu.test.tsx b/plugins/catalog-react/src/hooks/useEntityContextMenu.test.tsx deleted file mode 100644 index a28c41caa9..0000000000 --- a/plugins/catalog-react/src/hooks/useEntityContextMenu.test.tsx +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2025 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -import React from 'react'; -import { - EntityContextMenuProvider, - useEntityContextMenu, -} from './useEntityContextMenu'; -import { renderHook } from '@testing-library/react'; - -describe('useEntityContextMenu', () => { - it('should throw error when used outside of provider', () => { - expect(() => { - renderHook(() => useEntityContextMenu()); - }).toThrow( - 'useEntityContextMenu must be used within an EntityContextMenuProvider', - ); - }); - - it('should return the context value', () => { - const mockOnMenuClose = jest.fn(); - const { result } = renderHook(() => useEntityContextMenu(), { - wrapper: ({ children }) => ( - - {children} - - ), - }); - - expect(result.current.onMenuClose).toBe(mockOnMenuClose); - }); -}); diff --git a/plugins/catalog-react/src/hooks/useEntityContextMenu.ts b/plugins/catalog-react/src/hooks/useEntityContextMenu.ts new file mode 100644 index 0000000000..6eb7aba2ea --- /dev/null +++ b/plugins/catalog-react/src/hooks/useEntityContextMenu.ts @@ -0,0 +1,41 @@ +/* + * Copyright 2025 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { useVersionedContext } from '@backstage/version-bridge'; + +/** @internal */ +export type EntityContextMenuContextValue = { + onMenuClose: () => void; +}; + +/** @internal */ +export function useEntityContextMenu() { + const versionedHolder = useVersionedContext<{ + 1: EntityContextMenuContextValue; + }>('entity-context-menu-context'); + + if (!versionedHolder) { + throw new Error( + 'useEntityContextMenu must be used within an EntityContextMenuProvider', + ); + } + + const value = versionedHolder.atVersion(1); + if (!value) { + throw new Error('EntityContextMenu v1 is not available'); + } + + return value; +} diff --git a/plugins/catalog/package.json b/plugins/catalog/package.json index 51675d225e..9d69805e7d 100644 --- a/plugins/catalog/package.json +++ b/plugins/catalog/package.json @@ -73,6 +73,7 @@ "@backstage/plugin-search-common": "workspace:^", "@backstage/plugin-search-react": "workspace:^", "@backstage/types": "workspace:^", + "@backstage/version-bridge": "workspace:^", "@material-ui/core": "^4.12.2", "@material-ui/icons": "^4.9.1", "@material-ui/lab": "4.0.0-alpha.61", diff --git a/plugins/catalog/src/components/EntityContextMenu/EntityContextMenu.tsx b/plugins/catalog/src/components/EntityContextMenu/EntityContextMenu.tsx index fd8d76c052..640bb75e49 100644 --- a/plugins/catalog/src/components/EntityContextMenu/EntityContextMenu.tsx +++ b/plugins/catalog/src/components/EntityContextMenu/EntityContextMenu.tsx @@ -35,7 +35,7 @@ import { useApi, alertApiRef } from '@backstage/core-plugin-api'; import useCopyToClipboard from 'react-use/esm/useCopyToClipboard'; import { catalogTranslationRef } from '../../alpha/translation'; import { useTranslationRef } from '@backstage/core-plugin-api/alpha'; -import { EntityContextMenuProvider } from '@backstage/plugin-catalog-react'; +import { EntityContextMenuProvider } from '../../context'; /** @public */ export type EntityContextMenuClassKey = 'button'; diff --git a/plugins/catalog-react/src/hooks/useEntityContextMenu.tsx b/plugins/catalog/src/context/EntityContextMenuContext.tsx similarity index 72% rename from plugins/catalog-react/src/hooks/useEntityContextMenu.tsx rename to plugins/catalog/src/context/EntityContextMenuContext.tsx index 46db699abd..b3769757b2 100644 --- a/plugins/catalog-react/src/hooks/useEntityContextMenu.tsx +++ b/plugins/catalog/src/context/EntityContextMenuContext.tsx @@ -17,10 +17,9 @@ import React from 'react'; import { createVersionedContext, createVersionedValueMap, - useVersionedContext, } from '@backstage/version-bridge'; -/** @public */ +/** @internal */ export type EntityContextMenuContextValue = { onMenuClose: () => void; }; @@ -29,13 +28,13 @@ const EntityContextMenuContext = createVersionedContext<{ 1: EntityContextMenuContextValue; }>('entity-context-menu-context'); -/** @public */ +/** @internal */ export interface EntityContextMenuProviderProps { children: React.ReactNode; onMenuClose: () => void; } -/** @public */ +/** @internal */ export const EntityContextMenuProvider = ( props: EntityContextMenuProviderProps, ) => { @@ -50,23 +49,3 @@ export const EntityContextMenuProvider = ( ); }; - -/** @public */ -export function useEntityContextMenu() { - const versionedHolder = useVersionedContext<{ - 1: EntityContextMenuContextValue; - }>('entity-context-menu-context'); - - if (!versionedHolder) { - throw new Error( - 'useEntityContextMenu must be used within an EntityContextMenuProvider', - ); - } - - const value = versionedHolder.atVersion(1); - if (!value) { - throw new Error('EntityContextMenu v1 is not available'); - } - - return value; -} diff --git a/plugins/catalog/src/context/index.ts b/plugins/catalog/src/context/index.ts new file mode 100644 index 0000000000..919829d314 --- /dev/null +++ b/plugins/catalog/src/context/index.ts @@ -0,0 +1,16 @@ +/* + * Copyright 2025 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export { EntityContextMenuProvider } from './EntityContextMenuContext'; diff --git a/yarn.lock b/yarn.lock index 215e6ce4bf..fe9f4075ef 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6390,6 +6390,7 @@ __metadata: "@backstage/plugin-search-react": "workspace:^" "@backstage/test-utils": "workspace:^" "@backstage/types": "workspace:^" + "@backstage/version-bridge": "workspace:^" "@material-ui/core": "npm:^4.12.2" "@material-ui/icons": "npm:^4.9.1" "@material-ui/lab": "npm:4.0.0-alpha.61"