From 84ace9a29c03e556c4f0d2be7dad7d6e5b3e22fd Mon Sep 17 00:00:00 2001 From: Marley Powell Date: Wed, 3 Nov 2021 09:41:20 +0000 Subject: [PATCH] docs: Created stories for BuildTable component to document different component states. Signed-off-by: Marley Powell --- .changeset/tough-buckets-explain.md | 5 + plugins/azure-devops/package.json | 1 + .../BuildTable/BuildTable.stories.tsx | 94 +++++++++++++++++++ .../src/components/BuildTable/BuildTable.tsx | 4 +- 4 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 .changeset/tough-buckets-explain.md create mode 100644 plugins/azure-devops/src/components/BuildTable/BuildTable.stories.tsx diff --git a/.changeset/tough-buckets-explain.md b/.changeset/tough-buckets-explain.md new file mode 100644 index 0000000000..a2ca37d516 --- /dev/null +++ b/.changeset/tough-buckets-explain.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-azure-devops': patch +--- + +Simplified queue time calculation in `BuildTable`. diff --git a/plugins/azure-devops/package.json b/plugins/azure-devops/package.json index a071205711..1c5e0bba84 100644 --- a/plugins/azure-devops/package.json +++ b/plugins/azure-devops/package.json @@ -31,6 +31,7 @@ "@backstage/core-components": "^0.7.2", "@backstage/core-plugin-api": "^0.1.12", "@backstage/errors": "^0.1.4", + "@backstage/plugin-azure-devops-backend": "^0.1.4", "@backstage/plugin-catalog-react": "^0.6.2", "@backstage/theme": "^0.2.12", "@material-ui/core": "^4.12.2", diff --git a/plugins/azure-devops/src/components/BuildTable/BuildTable.stories.tsx b/plugins/azure-devops/src/components/BuildTable/BuildTable.stories.tsx new file mode 100644 index 0000000000..609466769b --- /dev/null +++ b/plugins/azure-devops/src/components/BuildTable/BuildTable.stories.tsx @@ -0,0 +1,94 @@ +/* + * Copyright 2021 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 { + BuildResult, + BuildStatus, + RepoBuild, +} from '@backstage/plugin-azure-devops-backend'; + +import { BuildTable } from './BuildTable'; +import { MemoryRouter } from 'react-router'; +import React from 'react'; + +export default { + title: 'Plugins/Azure Devops/Build Table', + component: BuildTable, +}; + +const buildStatuses: Array<[BuildStatus, BuildResult]> = [ + [BuildStatus.InProgress, BuildResult.None], // In Progress + [BuildStatus.Completed, BuildResult.Succeeded], // Succeeded + [BuildStatus.Completed, BuildResult.Failed], // Failed + [BuildStatus.Completed, BuildResult.PartiallySucceeded], // Partially Succeeded + [BuildStatus.Completed, BuildResult.Canceled], // Cancelled + [BuildStatus.Completed, BuildResult.None], // Unknown + [BuildStatus.Cancelling, BuildResult.None], // Cancelling + [BuildStatus.Postponed, BuildResult.None], // Postponed + [BuildStatus.NotStarted, BuildResult.None], // Not Started + [BuildStatus.None, BuildResult.None], // Unknown +]; + +const generateTestData = (rows = 10): RepoBuild[] => { + const repoBuilds: RepoBuild[] = []; + + for (let i = 0; i < rows; i++) { + const [status, result] = buildStatuses[i] ?? [ + BuildStatus.Completed, + BuildResult.Succeeded, + ]; + + repoBuilds.push({ + id: rows - i + 12534, + title: `backstage ci - 1.0.0-preview-${rows - i}`, + status, + result, + queueTime: new Date(Date.now() - i * 60000), + source: 'refs/heads/main', + link: '', + }); + } + + return repoBuilds; +}; + +export const Default = () => ( + + + +); + +export const Empty = () => ( + + + +); + +export const Loading = () => ( + + + +); + +export const ErrorMessage = () => ( + + + +); diff --git a/plugins/azure-devops/src/components/BuildTable/BuildTable.tsx b/plugins/azure-devops/src/components/BuildTable/BuildTable.tsx index a308afb81b..f8bb031f0a 100644 --- a/plugins/azure-devops/src/components/BuildTable/BuildTable.tsx +++ b/plugins/azure-devops/src/components/BuildTable/BuildTable.tsx @@ -149,9 +149,7 @@ const columns: TableColumn[] = [ field: 'queueTime', width: 'auto', render: (row: Partial) => - DateTime.fromISO( - row.queueTime ? row.queueTime.toString() : new Date().toString(), - ).toRelative(), + DateTime.fromJSDate(row.queueTime ?? new Date()).toRelative(), }, ];