From 8edc66257a6ab5f8694e08eb2dbd1076dc2cd6a7 Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Thu, 7 Apr 2022 12:47:34 +0200 Subject: [PATCH 1/4] add dedicated grpc api widget Signed-off-by: Kiss Miklos --- .../ApiDefinitionCard/ApiDefinitionWidget.tsx | 8 ++++ .../GrpcApiDefinitionWidget.test.tsx | 32 ++++++++++++++++ .../GrpcApiDefinitionWidget.tsx | 38 +++++++++++++++++++ .../GrpcApiDefinitionWidget/index.ts | 18 +++++++++ 4 files changed, 96 insertions(+) create mode 100644 plugins/api-docs/src/components/GrpcApiDefinitionWidget/GrpcApiDefinitionWidget.test.tsx create mode 100644 plugins/api-docs/src/components/GrpcApiDefinitionWidget/GrpcApiDefinitionWidget.tsx create mode 100644 plugins/api-docs/src/components/GrpcApiDefinitionWidget/index.ts diff --git a/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionWidget.tsx b/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionWidget.tsx index baccf09de9..3b7aa406d4 100644 --- a/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionWidget.tsx +++ b/plugins/api-docs/src/components/ApiDefinitionCard/ApiDefinitionWidget.tsx @@ -17,6 +17,7 @@ import React from 'react'; import { AsyncApiDefinitionWidget } from '../AsyncApiDefinitionWidget'; import { GraphQlDefinitionWidget } from '../GraphQlDefinitionWidget'; import { OpenApiDefinitionWidget } from '../OpenApiDefinitionWidget'; +import { GrpcApiDefinitionWidget } from '../GrpcApiDefinitionWidget'; export type ApiDefinitionWidget = { type: string; @@ -51,5 +52,12 @@ export function defaultDefinitionWidgets(): ApiDefinitionWidget[] { ), }, + { + type: 'grpc', + title: 'gRPC', + component: definition => ( + + ), + }, ]; } diff --git a/plugins/api-docs/src/components/GrpcApiDefinitionWidget/GrpcApiDefinitionWidget.test.tsx b/plugins/api-docs/src/components/GrpcApiDefinitionWidget/GrpcApiDefinitionWidget.test.tsx new file mode 100644 index 0000000000..046614fc91 --- /dev/null +++ b/plugins/api-docs/src/components/GrpcApiDefinitionWidget/GrpcApiDefinitionWidget.test.tsx @@ -0,0 +1,32 @@ +/* + * Copyright 2020 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 { renderInTestApp } from '@backstage/test-utils'; +import React from 'react'; +import { GrpcApiDefinitionWidget } from './GrpcApiDefinitionWidget'; + +describe('', () => { + it('renders plain text', async () => { + const { getAllByText } = await renderInTestApp( + , + ); + + expect( + getAllByText((_text, element) => element?.textContent === 'Hello World') + .length, + ).toBeGreaterThan(0); + }); +}); diff --git a/plugins/api-docs/src/components/GrpcApiDefinitionWidget/GrpcApiDefinitionWidget.tsx b/plugins/api-docs/src/components/GrpcApiDefinitionWidget/GrpcApiDefinitionWidget.tsx new file mode 100644 index 0000000000..8178f76073 --- /dev/null +++ b/plugins/api-docs/src/components/GrpcApiDefinitionWidget/GrpcApiDefinitionWidget.tsx @@ -0,0 +1,38 @@ +/* + * Copyright 2020 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 { CodeSnippet } from '@backstage/core-components'; +import { useTheme } from '@material-ui/core/styles'; +import { BackstageTheme } from '@backstage/theme'; + +export type GrpcApiDefinitionWidgetProps = { + definition: any; +}; + +export const GrpcApiDefinitionWidget = ( + props: GrpcApiDefinitionWidgetProps, +) => { + const theme = useTheme(); + return ( + + ); +}; diff --git a/plugins/api-docs/src/components/GrpcApiDefinitionWidget/index.ts b/plugins/api-docs/src/components/GrpcApiDefinitionWidget/index.ts new file mode 100644 index 0000000000..f9ed12d111 --- /dev/null +++ b/plugins/api-docs/src/components/GrpcApiDefinitionWidget/index.ts @@ -0,0 +1,18 @@ +/* + * Copyright 2020 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 { GrpcApiDefinitionWidget } from './GrpcApiDefinitionWidget'; +export type { GrpcApiDefinitionWidgetProps } from './GrpcApiDefinitionWidget'; From 1c8ebf7af2f1a9657c165b3f9160af19989a0549 Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Fri, 8 Apr 2022 13:39:46 +0200 Subject: [PATCH 2/4] add changeset Signed-off-by: Kiss Miklos --- .changeset/slimy-horses-do.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/slimy-horses-do.md diff --git a/.changeset/slimy-horses-do.md b/.changeset/slimy-horses-do.md new file mode 100644 index 0000000000..0a8fc7f309 --- /dev/null +++ b/.changeset/slimy-horses-do.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-api-docs': patch +--- + +Add dedicated grpc api definition widget From a136baa657aa6894f59dbe23f2d04c7cf26c843d Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Fri, 8 Apr 2022 14:12:59 +0200 Subject: [PATCH 3/4] spell grpc as gRPC Signed-off-by: Kiss Miklos --- .changeset/slimy-horses-do.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/slimy-horses-do.md b/.changeset/slimy-horses-do.md index 0a8fc7f309..196c47c988 100644 --- a/.changeset/slimy-horses-do.md +++ b/.changeset/slimy-horses-do.md @@ -2,4 +2,4 @@ '@backstage/plugin-api-docs': patch --- -Add dedicated grpc api definition widget +Add dedicated gRPC api definition widget From eb85cd5fac95da83b4edd65fc6c36f6077447d66 Mon Sep 17 00:00:00 2001 From: Kiss Miklos Date: Fri, 8 Apr 2022 16:09:59 +0200 Subject: [PATCH 4/4] use explicit type for props Signed-off-by: Kiss Miklos --- .../GrpcApiDefinitionWidget/GrpcApiDefinitionWidget.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/api-docs/src/components/GrpcApiDefinitionWidget/GrpcApiDefinitionWidget.tsx b/plugins/api-docs/src/components/GrpcApiDefinitionWidget/GrpcApiDefinitionWidget.tsx index 8178f76073..c5f9b071ef 100644 --- a/plugins/api-docs/src/components/GrpcApiDefinitionWidget/GrpcApiDefinitionWidget.tsx +++ b/plugins/api-docs/src/components/GrpcApiDefinitionWidget/GrpcApiDefinitionWidget.tsx @@ -20,7 +20,7 @@ import { useTheme } from '@material-ui/core/styles'; import { BackstageTheme } from '@backstage/theme'; export type GrpcApiDefinitionWidgetProps = { - definition: any; + definition: string; }; export const GrpcApiDefinitionWidget = (