remove support for string filtering
Signed-off-by: Mark Dunphy <markd@spotify.com>
This commit is contained in:
+101
-117
@@ -89,124 +89,117 @@ describe('EntityContextMenuItemBlueprint', () => {
|
||||
"properties": {
|
||||
"filter": {
|
||||
"anyOf": [
|
||||
{
|
||||
"type": "string",
|
||||
},
|
||||
{
|
||||
"anyOf": [
|
||||
{
|
||||
"anyOf": [
|
||||
{
|
||||
"type": [
|
||||
"string",
|
||||
"number",
|
||||
"boolean",
|
||||
],
|
||||
},
|
||||
{
|
||||
"items": {
|
||||
"$ref": "#/properties/filter/anyOf/1/anyOf/0/anyOf/0",
|
||||
},
|
||||
"type": "array",
|
||||
},
|
||||
"type": [
|
||||
"string",
|
||||
"number",
|
||||
"boolean",
|
||||
],
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"$all": {
|
||||
"items": {
|
||||
"$ref": "#/properties/filter/anyOf/1",
|
||||
},
|
||||
"type": "array",
|
||||
},
|
||||
"items": {
|
||||
"$ref": "#/properties/filter/anyOf/0/anyOf/0",
|
||||
},
|
||||
"required": [
|
||||
"$all",
|
||||
],
|
||||
"type": "object",
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"$any": {
|
||||
"items": {
|
||||
"$ref": "#/properties/filter/anyOf/1",
|
||||
},
|
||||
"type": "array",
|
||||
},
|
||||
},
|
||||
"required": [
|
||||
"$any",
|
||||
],
|
||||
"type": "object",
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"$not": {
|
||||
"$ref": "#/properties/filter/anyOf/1",
|
||||
},
|
||||
},
|
||||
"required": [
|
||||
"$not",
|
||||
],
|
||||
"type": "object",
|
||||
},
|
||||
{
|
||||
"additionalProperties": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/properties/filter/anyOf/1/anyOf/0",
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"$exists": {
|
||||
"type": "boolean",
|
||||
},
|
||||
},
|
||||
"required": [
|
||||
"$exists",
|
||||
],
|
||||
"type": "object",
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"$in": {
|
||||
"items": {
|
||||
"$ref": "#/properties/filter/anyOf/1/anyOf/0/anyOf/0",
|
||||
},
|
||||
"type": "array",
|
||||
},
|
||||
},
|
||||
"required": [
|
||||
"$in",
|
||||
],
|
||||
"type": "object",
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"$contains": {
|
||||
"$ref": "#/properties/filter/anyOf/1",
|
||||
},
|
||||
},
|
||||
"required": [
|
||||
"$contains",
|
||||
],
|
||||
"type": "object",
|
||||
},
|
||||
],
|
||||
},
|
||||
"propertyNames": {
|
||||
"pattern": "^(?!\\$).*$",
|
||||
},
|
||||
"type": "object",
|
||||
"type": "array",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"$all": {
|
||||
"items": {
|
||||
"$ref": "#/properties/filter",
|
||||
},
|
||||
"type": "array",
|
||||
},
|
||||
},
|
||||
"required": [
|
||||
"$all",
|
||||
],
|
||||
"type": "object",
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"$any": {
|
||||
"items": {
|
||||
"$ref": "#/properties/filter",
|
||||
},
|
||||
"type": "array",
|
||||
},
|
||||
},
|
||||
"required": [
|
||||
"$any",
|
||||
],
|
||||
"type": "object",
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"$not": {
|
||||
"$ref": "#/properties/filter",
|
||||
},
|
||||
},
|
||||
"required": [
|
||||
"$not",
|
||||
],
|
||||
"type": "object",
|
||||
},
|
||||
{
|
||||
"additionalProperties": {
|
||||
"anyOf": [
|
||||
{
|
||||
"$ref": "#/properties/filter/anyOf/0",
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"$exists": {
|
||||
"type": "boolean",
|
||||
},
|
||||
},
|
||||
"required": [
|
||||
"$exists",
|
||||
],
|
||||
"type": "object",
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"$in": {
|
||||
"items": {
|
||||
"$ref": "#/properties/filter/anyOf/0/anyOf/0",
|
||||
},
|
||||
"type": "array",
|
||||
},
|
||||
},
|
||||
"required": [
|
||||
"$in",
|
||||
],
|
||||
"type": "object",
|
||||
},
|
||||
{
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"$contains": {
|
||||
"$ref": "#/properties/filter",
|
||||
},
|
||||
},
|
||||
"required": [
|
||||
"$contains",
|
||||
],
|
||||
"type": "object",
|
||||
},
|
||||
],
|
||||
},
|
||||
"propertyNames": {
|
||||
"pattern": "^(?!\\$).*$",
|
||||
},
|
||||
"type": "object",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
@@ -229,15 +222,6 @@ describe('EntityContextMenuItemBlueprint', () => {
|
||||
"optional": [Function],
|
||||
"toString": [Function],
|
||||
},
|
||||
{
|
||||
"$$type": "@backstage/ExtensionDataRef",
|
||||
"config": {
|
||||
"optional": true,
|
||||
},
|
||||
"id": "catalog.entity-filter-expression",
|
||||
"optional": [Function],
|
||||
"toString": [Function],
|
||||
},
|
||||
],
|
||||
"override": [Function],
|
||||
"toString": [Function],
|
||||
|
||||
@@ -24,14 +24,13 @@ import MenuItem from '@material-ui/core/MenuItem';
|
||||
import ListItemIcon from '@material-ui/core/ListItemIcon';
|
||||
import ListItemText from '@material-ui/core/ListItemText';
|
||||
import { useEntityContextMenu } from '../../hooks/useEntityContextMenu';
|
||||
import { EntityPredicate } from '../predicates';
|
||||
import type { Entity } from '@backstage/catalog-model';
|
||||
import {
|
||||
entityFilterExpressionDataRef,
|
||||
entityFilterFunctionDataRef,
|
||||
} from './extensionData';
|
||||
EntityPredicate,
|
||||
entityPredicateToFilterFunction,
|
||||
} from '../predicates';
|
||||
import type { Entity } from '@backstage/catalog-model';
|
||||
import { entityFilterFunctionDataRef } from './extensionData';
|
||||
import { createEntityPredicateSchema } from '../predicates/createEntityPredicateSchema';
|
||||
import { resolveEntityFilterData } from './resolveEntityFilterData';
|
||||
/** @alpha */
|
||||
export type UseProps = () =>
|
||||
| {
|
||||
@@ -49,7 +48,7 @@ export type UseProps = () =>
|
||||
export type EntityContextMenuItemParams = {
|
||||
useProps: UseProps;
|
||||
icon: JSX.Element;
|
||||
filter?: string | EntityPredicate | ((entity: Entity) => boolean);
|
||||
filter?: EntityPredicate | ((entity: Entity) => boolean);
|
||||
};
|
||||
|
||||
/** @alpha */
|
||||
@@ -59,16 +58,13 @@ export const EntityContextMenuItemBlueprint = createExtensionBlueprint({
|
||||
output: [
|
||||
coreExtensionData.reactElement,
|
||||
entityFilterFunctionDataRef.optional(),
|
||||
entityFilterExpressionDataRef.optional(),
|
||||
],
|
||||
dataRefs: {
|
||||
filterFunction: entityFilterFunctionDataRef,
|
||||
filterExpression: entityFilterExpressionDataRef,
|
||||
},
|
||||
config: {
|
||||
schema: {
|
||||
filter: z =>
|
||||
z.union([z.string(), createEntityPredicateSchema(z)]).optional(),
|
||||
filter: z => createEntityPredicateSchema(z).optional(),
|
||||
},
|
||||
},
|
||||
*factory(params: EntityContextMenuItemParams, { node, config }) {
|
||||
@@ -102,6 +98,16 @@ export const EntityContextMenuItemBlueprint = createExtensionBlueprint({
|
||||
|
||||
yield coreExtensionData.reactElement(ExtensionBoundary.lazy(node, loader));
|
||||
|
||||
yield* resolveEntityFilterData(params.filter, config, node);
|
||||
if (config.filter) {
|
||||
yield entityFilterFunctionDataRef(
|
||||
entityPredicateToFilterFunction(config.filter),
|
||||
);
|
||||
} else if (typeof params.filter === 'function') {
|
||||
yield entityFilterFunctionDataRef(params.filter);
|
||||
} else if (params.filter) {
|
||||
yield entityFilterFunctionDataRef(
|
||||
entityPredicateToFilterFunction(params.filter),
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
@@ -738,11 +738,11 @@ describe('Entity page', () => {
|
||||
it.each([
|
||||
{
|
||||
positive: { params: {} },
|
||||
negative: { params: { filter: 'kind:api' } },
|
||||
negative: { params: { filter: { kind: 'api' } } },
|
||||
},
|
||||
{
|
||||
positive: { params: { filter: 'kind:component' } },
|
||||
negative: { params: { filter: 'kind:api' } },
|
||||
positive: { params: { filter: { kind: 'component' } } },
|
||||
negative: { params: { filter: { kind: 'api' } } },
|
||||
},
|
||||
{
|
||||
positive: {
|
||||
|
||||
@@ -75,7 +75,6 @@ export const catalogEntityPage = PageBlueprint.makeWithOverrides({
|
||||
contextMenuItems: createExtensionInput([
|
||||
coreExtensionData.reactElement,
|
||||
EntityContextMenuItemBlueprint.dataRefs.filterFunction.optional(),
|
||||
EntityContextMenuItemBlueprint.dataRefs.filterExpression.optional(),
|
||||
]),
|
||||
},
|
||||
config: {
|
||||
@@ -95,10 +94,9 @@ export const catalogEntityPage = PageBlueprint.makeWithOverrides({
|
||||
|
||||
const menuItems = inputs.contextMenuItems.map(item => ({
|
||||
element: item.get(coreExtensionData.reactElement),
|
||||
filter: buildFilterFn(
|
||||
item.get(EntityContextMenuItemBlueprint.dataRefs.filterFunction),
|
||||
item.get(EntityContextMenuItemBlueprint.dataRefs.filterExpression),
|
||||
),
|
||||
filter:
|
||||
item.get(EntityContextMenuItemBlueprint.dataRefs.filterFunction) ??
|
||||
(() => true),
|
||||
}));
|
||||
|
||||
type Groups = Record<
|
||||
|
||||
Reference in New Issue
Block a user