chore: refactoring some of the simplification
Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
@@ -28,6 +28,7 @@ import {
|
||||
import { useEntityList } from '@backstage/plugin-catalog-react';
|
||||
import { Typography } from '@material-ui/core';
|
||||
import { TemplateCard } from '../TemplateCard';
|
||||
import { isTemplateEntity } from '../../lib/isTemplateEntity';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
@@ -53,23 +54,10 @@ export const TemplateList = ({
|
||||
}: TemplateListProps) => {
|
||||
const { loading, error, entities } = useEntityList();
|
||||
const Card = TemplateCardComponent || TemplateCard;
|
||||
const templateEntities = entities.filter(isTemplateEntity);
|
||||
const maybeFilteredEntities = (
|
||||
group
|
||||
? entities
|
||||
.filter(
|
||||
(e): e is TemplateEntityV1beta3 =>
|
||||
e.kind === 'Template' &&
|
||||
e.apiVersion === 'scaffolder.backstage.io/v1beta3',
|
||||
)
|
||||
.filter(group.filter)
|
||||
: entities
|
||||
)
|
||||
.filter(
|
||||
(e): e is TemplateEntityV1beta3 =>
|
||||
e.kind === 'Template' &&
|
||||
e.apiVersion === 'scaffolder.backstage.io/v1beta3',
|
||||
)
|
||||
.filter(e => (templateFilter ? !templateFilter(e) : true));
|
||||
group ? templateEntities.filter(group.filter) : templateEntities
|
||||
).filter(e => (templateFilter ? !templateFilter(e) : true));
|
||||
|
||||
const titleComponent: React.ReactNode = (() => {
|
||||
if (group && group.title) {
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2023 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 { Entity } from '@backstage/catalog-model';
|
||||
import { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common';
|
||||
|
||||
export const isTemplateEntity = (
|
||||
entity: Entity,
|
||||
): entity is TemplateEntityV1beta3 =>
|
||||
entity.apiVersion === 'scaffolder.backstage.io/v1beta3' &&
|
||||
entity.kind === 'Template';
|
||||
@@ -29,6 +29,7 @@ import {
|
||||
import { TemplateGroup } from '@backstage/plugin-scaffolder-react/alpha';
|
||||
import { viewTechDocRouteRef, selectedTemplateRouteRef } from '../../routes';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { isTemplateEntity } from '../../lib/isTemplateEntity';
|
||||
|
||||
/**
|
||||
* @alpha
|
||||
@@ -87,11 +88,7 @@ export const TemplateGroups = (props: TemplateGroupsProps) => {
|
||||
<>
|
||||
{groups.map(({ title, filter }, index) => {
|
||||
const templates = entities
|
||||
.filter(
|
||||
(e): e is TemplateEntityV1beta3 =>
|
||||
e.kind === 'Template' &&
|
||||
e.apiVersion === 'scaffolder.backstage.io/v1beta3',
|
||||
)
|
||||
.filter(isTemplateEntity)
|
||||
.filter(e => (templateFilter ? !templateFilter(e) : true))
|
||||
.filter(filter)
|
||||
.map(template => {
|
||||
|
||||
Reference in New Issue
Block a user