@@ -13,9 +13,12 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Entity } from '@backstage/catalog-model';
|
||||
|
||||
/** @public */
|
||||
export const GITHUB_PROJECT_SLUG_ANNOTATION = 'github.com/project-slug';
|
||||
|
||||
/** @public */
|
||||
export const isGithubDeploymentsAvailable = (entity: Entity) =>
|
||||
Boolean(entity?.metadata.annotations?.[GITHUB_PROJECT_SLUG_ANNOTATION]);
|
||||
|
||||
@@ -53,10 +53,12 @@ const getBaseUrl = (
|
||||
return config?.config.apiBaseUrl;
|
||||
};
|
||||
|
||||
type Node = {
|
||||
/** @public */
|
||||
export type Node = {
|
||||
logUrl?: string;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
export type GithubDeployment = {
|
||||
environment: string;
|
||||
state: string;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import useAsyncRetry from 'react-use/lib/useAsyncRetry';
|
||||
import { GithubDeployment, githubDeploymentsApiRef } from '../api';
|
||||
|
||||
+5
-6
@@ -17,7 +17,7 @@ import React from 'react';
|
||||
import { GithubDeployment } from '../../api';
|
||||
import { Typography, makeStyles } from '@material-ui/core';
|
||||
import SyncIcon from '@material-ui/icons/Sync';
|
||||
import * as columnFactories from './columns';
|
||||
import { columnFactories } from './columns';
|
||||
import { defaultDeploymentColumns } from './presets';
|
||||
import { Table, TableColumn } from '@backstage/core-components';
|
||||
|
||||
@@ -29,14 +29,13 @@ const useStyles = makeStyles(theme => ({
|
||||
},
|
||||
}));
|
||||
|
||||
type GithubDeploymentsTableProps = {
|
||||
/** @public */
|
||||
export const GithubDeploymentsTable = (props: {
|
||||
deployments: GithubDeployment[];
|
||||
isLoading: boolean;
|
||||
reload: () => void;
|
||||
columns: TableColumn<GithubDeployment>[];
|
||||
};
|
||||
|
||||
export function GithubDeploymentsTable(props: GithubDeploymentsTableProps) {
|
||||
}) => {
|
||||
const { deployments, isLoading, reload, columns } = props;
|
||||
const classes = useStyles();
|
||||
|
||||
@@ -64,7 +63,7 @@ export function GithubDeploymentsTable(props: GithubDeploymentsTableProps) {
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
GithubDeploymentsTable.columns = columnFactories;
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { GithubDeployment } from '../../api';
|
||||
import { DateTime } from 'luxon';
|
||||
@@ -43,50 +44,54 @@ export const GithubStateIndicator = (props: { state: string }) => {
|
||||
}
|
||||
};
|
||||
|
||||
export function createEnvironmentColumn(): TableColumn<GithubDeployment> {
|
||||
return {
|
||||
title: 'Environment',
|
||||
field: 'environment',
|
||||
highlight: true,
|
||||
};
|
||||
}
|
||||
export const columnFactories = Object.freeze({
|
||||
createEnvironmentColumn(): TableColumn<GithubDeployment> {
|
||||
return {
|
||||
title: 'Environment',
|
||||
field: 'environment',
|
||||
highlight: true,
|
||||
};
|
||||
},
|
||||
|
||||
export function createStatusColumn(): TableColumn<GithubDeployment> {
|
||||
return {
|
||||
title: 'Status',
|
||||
render: (row: GithubDeployment): JSX.Element => (
|
||||
<Box display="flex" alignItems="center">
|
||||
<GithubStateIndicator state={row.state} />
|
||||
<Typography variant="caption">{row.state}</Typography>
|
||||
</Box>
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
export function createCommitColumn(): TableColumn<GithubDeployment> {
|
||||
return {
|
||||
title: 'Commit',
|
||||
render: (row: GithubDeployment) =>
|
||||
row.commit && (
|
||||
<Link to={row.commit.commitUrl} target="_blank" rel="noopener">
|
||||
{row.commit.abbreviatedOid}
|
||||
</Link>
|
||||
createStatusColumn(): TableColumn<GithubDeployment> {
|
||||
return {
|
||||
title: 'Status',
|
||||
render: (row: GithubDeployment): JSX.Element => (
|
||||
<Box display="flex" alignItems="center">
|
||||
<GithubStateIndicator state={row.state} />
|
||||
<Typography variant="caption">{row.state}</Typography>
|
||||
</Box>
|
||||
),
|
||||
};
|
||||
}
|
||||
};
|
||||
},
|
||||
|
||||
export function createCreatorColumn(): TableColumn<GithubDeployment> {
|
||||
return {
|
||||
title: 'Creator',
|
||||
field: 'creator.login',
|
||||
};
|
||||
}
|
||||
createCommitColumn(): TableColumn<GithubDeployment> {
|
||||
return {
|
||||
title: 'Commit',
|
||||
render: (row: GithubDeployment) =>
|
||||
row.commit && (
|
||||
<Link to={row.commit.commitUrl} target="_blank" rel="noopener">
|
||||
{row.commit.abbreviatedOid}
|
||||
</Link>
|
||||
),
|
||||
};
|
||||
},
|
||||
|
||||
export function createLastUpdatedColumn(): TableColumn<GithubDeployment> {
|
||||
return {
|
||||
title: 'Last Updated',
|
||||
render: (row: GithubDeployment): JSX.Element => (
|
||||
<Box>{DateTime.fromISO(row.updatedAt).toRelative({ locale: 'en' })}</Box>
|
||||
),
|
||||
};
|
||||
}
|
||||
createCreatorColumn(): TableColumn<GithubDeployment> {
|
||||
return {
|
||||
title: 'Creator',
|
||||
field: 'creator.login',
|
||||
};
|
||||
},
|
||||
|
||||
createLastUpdatedColumn(): TableColumn<GithubDeployment> {
|
||||
return {
|
||||
title: 'Last Updated',
|
||||
render: (row: GithubDeployment): JSX.Element => (
|
||||
<Box>
|
||||
{DateTime.fromISO(row.updatedAt).toRelative({ locale: 'en' })}
|
||||
</Box>
|
||||
),
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -13,4 +13,5 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export { GithubDeploymentsTable } from './GithubDeploymentsTable';
|
||||
|
||||
@@ -13,20 +13,15 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { GithubDeployment } from '../../api';
|
||||
import {
|
||||
createEnvironmentColumn,
|
||||
createStatusColumn,
|
||||
createCommitColumn,
|
||||
createLastUpdatedColumn,
|
||||
createCreatorColumn,
|
||||
} from './columns';
|
||||
import { columnFactories } from './columns';
|
||||
import { TableColumn } from '@backstage/core-components';
|
||||
|
||||
export const defaultDeploymentColumns: TableColumn<GithubDeployment>[] = [
|
||||
createEnvironmentColumn(),
|
||||
createStatusColumn(),
|
||||
createCommitColumn(),
|
||||
createCreatorColumn(),
|
||||
createLastUpdatedColumn(),
|
||||
columnFactories.createEnvironmentColumn(),
|
||||
columnFactories.createStatusColumn(),
|
||||
columnFactories.createCommitColumn(),
|
||||
columnFactories.createCreatorColumn(),
|
||||
columnFactories.createLastUpdatedColumn(),
|
||||
];
|
||||
|
||||
@@ -20,6 +20,10 @@
|
||||
* @packageDocumentation
|
||||
*/
|
||||
|
||||
export type { Node, GithubDeployment } from './api';
|
||||
export { githubDeploymentsPlugin, EntityGithubDeploymentsCard } from './plugin';
|
||||
export { GithubDeploymentsTable } from './components/GithubDeploymentsTable';
|
||||
export { isGithubDeploymentsAvailable } from './Router';
|
||||
export {
|
||||
isGithubDeploymentsAvailable,
|
||||
GITHUB_PROJECT_SLUG_ANNOTATION,
|
||||
} from './Router';
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
githubAuthApiRef,
|
||||
} from '@backstage/core-plugin-api';
|
||||
|
||||
/** @public */
|
||||
export const githubDeploymentsPlugin = createPlugin({
|
||||
id: 'github-deployments',
|
||||
apis: [
|
||||
@@ -37,6 +38,7 @@ export const githubDeploymentsPlugin = createPlugin({
|
||||
],
|
||||
});
|
||||
|
||||
/** @public */
|
||||
export const EntityGithubDeploymentsCard = githubDeploymentsPlugin.provide(
|
||||
createComponentExtension({
|
||||
name: 'EntityGithubDeploymentsCard',
|
||||
|
||||
Reference in New Issue
Block a user