relocate context menu provider

Signed-off-by: Mark Dunphy <markd@spotify.com>
This commit is contained in:
Mark Dunphy
2025-04-08 11:36:56 -04:00
parent c9e4d8e573
commit 631c79cd34
10 changed files with 64 additions and 100 deletions
+1 -1
View File
@@ -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;
-21
View File
@@ -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<TEntity extends Entity = Entity>(): {
entity: TEntity;
};
// @public (undocumented)
export function useEntityContextMenu(): EntityContextMenuContextValue;
// @public
export function useEntityList<
EntityFilters extends DefaultEntityFilters = DefaultEntityFilters,
-9
View File
@@ -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';
@@ -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 }) => (
<EntityContextMenuProvider onMenuClose={mockOnMenuClose}>
{children}
</EntityContextMenuProvider>
),
});
expect(result.current.onMenuClose).toBe(mockOnMenuClose);
});
});
@@ -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;
}
+1
View File
@@ -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",
@@ -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';
@@ -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 = (
</EntityContextMenuContext.Provider>
);
};
/** @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;
}
+16
View File
@@ -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';
+1
View File
@@ -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"