-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1503 from RoadieHQ/shortcut-entity-page
Add a component card for the shortcut plugin
- Loading branch information
Showing
9 changed files
with
190 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@roadiehq/backstage-plugin-shortcut': minor | ||
--- | ||
|
||
Add an entity card for the shortcut plugin. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
...ontend/backstage-plugin-shortcut/src/components/ComponentExtensions/EntityStoriesCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Copyright 2024 Larder Software Limited | ||
* | ||
* 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 { ErrorPanel, Table, TableColumn } from '@backstage/core-components'; | ||
import SyncIcon from '@material-ui/icons/Sync'; | ||
import { shortcutApiRef } from '../../api'; | ||
import { useApi } from '@backstage/core-plugin-api'; | ||
import { useAsyncRetry } from 'react-use'; | ||
import { useEntity } from '@backstage/plugin-catalog-react'; | ||
import { SHORTCUT_QUERY_ANNOTATION } from '../../constants'; | ||
import { Story, User } from '../../api/types'; | ||
|
||
const columnsBuilder: (users?: User[]) => TableColumn<Story>[] = ( | ||
users?: User[], | ||
) => [ | ||
{ | ||
title: 'Name', | ||
field: 'name', | ||
}, | ||
{ | ||
title: 'Status', | ||
render: story => (story.started ? <>In progress</> : <>'Not started'</>), | ||
}, | ||
{ | ||
title: 'Owners', | ||
render: story => { | ||
return users | ||
?.filter(user => story.owner_ids.includes(user.id)) | ||
.map(user => user.profile.name) | ||
.join(', '); | ||
}, | ||
}, | ||
]; | ||
|
||
export const EntityStoriesCard = (props: { | ||
title?: string; | ||
additionalQuery?: string; | ||
}) => { | ||
const shortcutApi = useApi(shortcutApiRef); | ||
const { entity } = useEntity(); | ||
|
||
const { | ||
value: data, | ||
retry, | ||
error, | ||
loading, | ||
} = useAsyncRetry(async () => { | ||
let query = entity.metadata.annotations?.[SHORTCUT_QUERY_ANNOTATION]; | ||
if (props.additionalQuery) { | ||
query = `${query} ${props.additionalQuery}`; | ||
} | ||
if (query) { | ||
return (await shortcutApi.fetchStories({ query })).data; | ||
} | ||
return []; | ||
}); | ||
|
||
const { value: users } = useAsyncRetry(async () => { | ||
return shortcutApi.getUsers(); | ||
}); | ||
|
||
if (error) { | ||
return <ErrorPanel error={error} />; | ||
} | ||
return ( | ||
<Table | ||
title={props.title ? props.title : 'Shortcut Stories'} | ||
options={{ | ||
paging: true, | ||
search: false, | ||
sorting: true, | ||
draggable: false, | ||
padding: 'dense', | ||
}} | ||
isLoading={loading} | ||
data={data || []} | ||
columns={columnsBuilder(users)} | ||
actions={[ | ||
{ | ||
icon: () => <SyncIcon />, | ||
tooltip: 'Refresh', | ||
isFreeAction: true, | ||
onClick: () => retry(), | ||
}, | ||
]} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
plugins/frontend/backstage-plugin-shortcut/src/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright 2024 Larder Software Limited | ||
* | ||
* 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 const SHORTCUT_QUERY_ANNOTATION = 'shortcut.com/story-query'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
plugins/frontend/backstage-plugin-shortcut/src/isShortcutAvailable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* | ||
* Copyright 2024 Larder Software Limited | ||
* | ||
* 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 { SHORTCUT_QUERY_ANNOTATION } from './constants'; | ||
|
||
export const isShortcutAvailable = (entity: Entity) => | ||
Boolean(entity?.metadata.annotations?.[SHORTCUT_QUERY_ANNOTATION]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters