From a52d98820162176bb3f2d53347d6b501766274c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Thu, 23 Nov 2023 16:39:41 +0100 Subject: [PATCH] moved out the matchers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .../filter/matrchers/createHasMatcher.ts | 24 +++++++++---------- .../alpha/filter/matrchers/createIsMatcher.ts | 10 ++++---- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/plugins/catalog/src/alpha/filter/matrchers/createHasMatcher.ts b/plugins/catalog/src/alpha/filter/matrchers/createHasMatcher.ts index f57316a65e..35a3f7baf7 100644 --- a/plugins/catalog/src/alpha/filter/matrchers/createHasMatcher.ts +++ b/plugins/catalog/src/alpha/filter/matrchers/createHasMatcher.ts @@ -17,6 +17,18 @@ import { InputError } from '@backstage/errors'; import { EntityMatcherFn } from './types'; +const allowedMatchers: Record = { + labels: entity => { + return Object.keys(entity.metadata.labels ?? {}).length > 0; + }, + annotations: entity => { + return Object.keys(entity.metadata.annotations ?? {}).length > 0; + }, + links: entity => { + return (entity.metadata.links ?? []).length > 0; + }, +}; + /** * Matches on the non-empty presence of different parts of the entity */ @@ -24,18 +36,6 @@ export function createHasMatcher( parameters: string[], onParseError: (error: Error) => void, ): EntityMatcherFn { - const allowedMatchers: Record = { - labels: entity => { - return Object.keys(entity.metadata.labels ?? {}).length > 0; - }, - annotations: entity => { - return Object.keys(entity.metadata.annotations ?? {}).length > 0; - }, - links: entity => { - return (entity.metadata.links ?? []).length > 0; - }, - }; - const matchers = parameters.flatMap(parameter => { const matcher = allowedMatchers[parameter.toLocaleLowerCase('en-US')]; if (!matcher) { diff --git a/plugins/catalog/src/alpha/filter/matrchers/createIsMatcher.ts b/plugins/catalog/src/alpha/filter/matrchers/createIsMatcher.ts index 30bfe4eb15..49a54349d1 100644 --- a/plugins/catalog/src/alpha/filter/matrchers/createIsMatcher.ts +++ b/plugins/catalog/src/alpha/filter/matrchers/createIsMatcher.ts @@ -17,6 +17,11 @@ import { InputError } from '@backstage/errors'; import { EntityMatcherFn } from './types'; +const allowedMatchers: Record = { + orphan: entity => + Boolean(entity.metadata.annotations?.['backstage.io/orphan']), +}; + /** * Matches on different semantic properties of the entity */ @@ -24,11 +29,6 @@ export function createIsMatcher( parameters: string[], onParseError: (error: Error) => void, ): EntityMatcherFn { - const allowedMatchers: Record = { - orphan: entity => - Boolean(entity.metadata.annotations?.['backstage.io/orphan']), - }; - const matchers = parameters.flatMap(parameter => { const matcher = allowedMatchers[parameter.toLocaleLowerCase('en-US')]; if (!matcher) {