From 671cba631cb99fe93f32cee422fdbbe1ed40b2ff Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 25 Feb 2022 15:42:48 +0100 Subject: [PATCH] chore: working on writing some more components for all this stuff Signed-off-by: blam --- plugins/scaffolder/src/next/Router/Router.tsx | 12 ++-- .../next/TemplateListPage/TemplateCard.tsx | 26 +++++++ .../next/TemplateListPage/TemplateGroup.tsx | 70 +++++++++++++++++++ .../next/TemplateListPage/TemplateGroups.tsx | 37 ++++++++++ .../TemplateListPage/TemplateListPage.tsx | 38 ++++------ 5 files changed, 154 insertions(+), 29 deletions(-) create mode 100644 plugins/scaffolder/src/next/TemplateListPage/TemplateCard.tsx create mode 100644 plugins/scaffolder/src/next/TemplateListPage/TemplateGroup.tsx create mode 100644 plugins/scaffolder/src/next/TemplateListPage/TemplateGroups.tsx diff --git a/plugins/scaffolder/src/next/Router/Router.tsx b/plugins/scaffolder/src/next/Router/Router.tsx index 8ab9755ab2..b199abc8bb 100644 --- a/plugins/scaffolder/src/next/Router/Router.tsx +++ b/plugins/scaffolder/src/next/Router/Router.tsx @@ -29,13 +29,17 @@ import { useElementFilter } from '@backstage/core-plugin-api'; import { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common'; export type RouterProps = { - TemplateCardComponent?: React.ComponentType<{ - template: TemplateEntityV1beta3; - }>; + components: { + TemplateCardComponent?: React.ComponentType<{ + template: TemplateEntityV1beta3; + }>; + TaskPageComponent?: React.ComponentType<{}>; + }; }; export const Router = (props: PropsWithChildren) => { - const { TemplateCardComponent } = props; + const { components: { TaskPageComponent, TemplateCardComponent } = {} } = + props; const outlet = useOutlet() || props.children; diff --git a/plugins/scaffolder/src/next/TemplateListPage/TemplateCard.tsx b/plugins/scaffolder/src/next/TemplateListPage/TemplateCard.tsx new file mode 100644 index 0000000000..53ea12d4d6 --- /dev/null +++ b/plugins/scaffolder/src/next/TemplateListPage/TemplateCard.tsx @@ -0,0 +1,26 @@ +/* + * Copyright 2022 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 { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common'; + +export interface TemplateCardProps { + template: TemplateEntityV1beta3; + deprecated?: boolean; +} + +export const TemplateCard = (props: TemplateCardProps) => { + return null; +}; diff --git a/plugins/scaffolder/src/next/TemplateListPage/TemplateGroup.tsx b/plugins/scaffolder/src/next/TemplateListPage/TemplateGroup.tsx new file mode 100644 index 0000000000..8af551d562 --- /dev/null +++ b/plugins/scaffolder/src/next/TemplateListPage/TemplateGroup.tsx @@ -0,0 +1,70 @@ +/* + * Copyright 2022 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 { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common'; +import React from 'react'; +import { + Content, + ContentHeader, + ItemCardGrid, + Link, +} from '@backstage/core-components'; +import { Typography } from '@material-ui/core'; +import { TemplateCard, TemplateCardProps } from './TemplateCard'; +import { stringifyEntityRef } from '@backstage/catalog-model'; + +export interface TemplateGroupProps { + templates: TemplateEntityV1beta3[]; + title?: string; + components?: { + titleComponent?: React.ReactNode; + CardComponent?: React.ComponentType; + }; +} + +export const TemplateGroup = (props: TemplateGroupProps) => { + const { + templates, + title, + components: { titleComponent, CardComponent } = {}, + } = props; + + if (templates.length === 0) { + return ( + + No templates found that match your filter. Learn more about{' '} + + adding templates + + . + + ); + } + + const titleFragment = titleComponent || ; + + const Card = CardComponent || TemplateCard; + + return ( + + {titleFragment} + + {templates.map(template => ( + + ))} + + + ); +}; diff --git a/plugins/scaffolder/src/next/TemplateListPage/TemplateGroups.tsx b/plugins/scaffolder/src/next/TemplateListPage/TemplateGroups.tsx new file mode 100644 index 0000000000..17790729b1 --- /dev/null +++ b/plugins/scaffolder/src/next/TemplateListPage/TemplateGroups.tsx @@ -0,0 +1,37 @@ +/* + * Copyright 2022 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 { TemplateGroup } from './TemplateGroup'; +import { Entity } from '@backstage/catalog-model'; +import { useEntityList } from '@backstage/plugin-catalog-react'; +import { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common'; + +export type TemplateGroupFilter = { + title?: string; + titleComponent?: React.ReactNode; + filter: (entity: Entity) => boolean; +}; + +export interface TemplateGroupsProps { + groups: TemplateGroupFilter[]; + TemplateCardComponent?: React.ComponentType<{ + template: TemplateEntityV1beta3; + }>; +} + +export const TemplateGroups = (props: TemplateGroupsProps) => { + const { loading, error, entities } = useEntityList(); + return null; +}; diff --git a/plugins/scaffolder/src/next/TemplateListPage/TemplateListPage.tsx b/plugins/scaffolder/src/next/TemplateListPage/TemplateListPage.tsx index aab72f3cdf..497f78594c 100644 --- a/plugins/scaffolder/src/next/TemplateListPage/TemplateListPage.tsx +++ b/plugins/scaffolder/src/next/TemplateListPage/TemplateListPage.tsx @@ -16,7 +16,7 @@ import React from 'react'; import { TemplateEntityV1beta3 } from '@backstage/plugin-scaffolder-common'; -import { Entity } from '@backstage/catalog-model'; + import { makeStyles } from '@material-ui/core'; import { Content, @@ -37,18 +37,13 @@ import { CategoryPicker } from './CategoryPicker'; import { RegisterExistingButton } from './RegisterExistingButton'; import { useRouteRef } from '@backstage/core-plugin-api'; import { registerComponentRouteRef } from '../../routes'; - -export type TemplateListGroup = { - title?: string; - titleComponent?: React.ReactNode; - filter: (entity: Entity) => boolean; -}; +import { TemplateGroupFilter, TemplateGroups } from './TemplateGroups'; export type TemplateListPageProps = { TemplateCardComponent?: React.ComponentType<{ template: TemplateEntityV1beta3; }>; - groups?: TemplateListGroup[]; + groups?: TemplateGroupFilter[]; }; const useStyles = makeStyles(theme => ({ @@ -60,20 +55,22 @@ const useStyles = makeStyles(theme => ({ }, })); +const defaultGroup: TemplateGroupFilter = { + title: 'All Templates', + filter: () => true, +}; + export const TemplateListPage = (props: TemplateListPageProps) => { const styles = useStyles(); const registerComponentLink = useRouteRef(registerComponentRouteRef); + const { TemplateCardComponent, groups = [defaultGroup] } = props; return (
- Create a New Component - - } + title="Create a New Component" subtitle="Create new software components using standard templates" /> @@ -101,19 +98,10 @@ export const TemplateListPage = (props: TemplateListPageProps) => {
- {/* {groups && - groups.map((group, index) => ( - - ))} - */} + />