Skip to content

Commit

Permalink
Jira Table Links (AxisCommunications#189)
Browse files Browse the repository at this point in the history
* Jira Table Links

* chore(backend): removed all files for the old backend system (AxisCommunications#188)

Co-authored-by: Niklas Aronsson <[email protected]>

* Using jqlQueryBuilder for building table links

---------

Co-authored-by: anicke <[email protected]>
Co-authored-by: Niklas Aronsson <[email protected]>
  • Loading branch information
3 people authored Sep 25, 2024
1 parent 8b3bd03 commit d3129c0
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .changeset/late-socks-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@axis-backstage/plugin-jira-dashboard-backend': minor
'@axis-backstage/plugin-jira-dashboard-common': minor
'@axis-backstage/plugin-jira-dashboard': minor
---

Adding jql query to support links within JiraTable title
10 changes: 10 additions & 0 deletions plugins/jira-dashboard-backend/src/service/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
searchJira,
SearchOptions,
} from '../api';
import { jqlQueryBuilder } from '../queries';

export const getProjectResponse = async (
projectKey: string,
Expand Down Expand Up @@ -113,6 +114,11 @@ export const getIssuesFromFilters = async (
return await Promise.all(
filters.map(async filter => ({
name: filter.name,
query: jqlQueryBuilder({
project: projectKey,
components,
query: filter.query,
}),
type: 'filter',
issues: await getIssuesByFilter(
projectKey,
Expand All @@ -132,6 +138,10 @@ export const getIssuesFromComponents = async (
return await Promise.all(
componentAnnotations.map(async componentKey => ({
name: componentKey,
query: jqlQueryBuilder({
project: projectKey,
components: [componentKey],
}),
type: 'component',
issues: await getIssuesByComponent(projectKey, componentKey, config),
})),
Expand Down
1 change: 1 addition & 0 deletions plugins/jira-dashboard-common/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export type Issue = {
// @public
export type JiraDataResponse = {
name: string;
query?: string;
type: 'component' | 'filter';
issues: Issue[];
};
Expand Down
1 change: 1 addition & 0 deletions plugins/jira-dashboard-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export type Filter = {
*/
export type JiraDataResponse = {
name: string;
query?: string;
type: 'component' | 'filter';
issues: Issue[];
};
Expand Down
2 changes: 2 additions & 0 deletions plugins/jira-dashboard/dev/__fixtures__/jiraResponse.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
{
"name": "Open Issues",
"type": "filter",
"query": "resolution = Unresolved ORDER BY updated DESC",
"issues": [
{
"key": "BS-1",
Expand Down Expand Up @@ -89,6 +90,7 @@
{
"name": "New Issues",
"type": "filter",
"query": "resolution = Unresolved ORDER BY updated DESC",
"issues": [
{
"key": "BS-1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export const JiraDashboardContent = (props?: {
<JiraTable
tableContent={value}
showFilters={props?.showFilters}
project={jiraResponse.project}
/>
</Grid>
))}
Expand Down
14 changes: 11 additions & 3 deletions plugins/jira-dashboard/src/components/JiraTable/JiraTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import React from 'react';
import { renderInTestApp } from '@backstage/test-utils';
import { JiraTable } from './JiraTable';
import mockedJiraDataResponse from './mockedJiraDataResponse.json';
import mockedProject from '../JiraProjectCard/mockedProject.json';
import type { JiraDataResponse } from '@axis-backstage/plugin-jira-dashboard-common';

describe('JiraTable', () => {
it('renders header', async () => {
const { getByTestId } = await renderInTestApp(
<JiraTable tableContent={mockedJiraDataResponse as JiraDataResponse} />,
<JiraTable
tableContent={mockedJiraDataResponse as JiraDataResponse}
project={mockedProject}
/>,
);
expect(getByTestId('table-header')).toBeInTheDocument();
});
Expand All @@ -16,17 +20,21 @@ describe('JiraTable', () => {
const emptyJiraDataResponse = {
name: 'Open Issues',
type: 'filter',
query: 'resolution = Unresolved ORDER BY updated DESC',
issues: [],
} as JiraDataResponse;
const { getByText } = await renderInTestApp(
<JiraTable tableContent={emptyJiraDataResponse} />,
<JiraTable
tableContent={emptyJiraDataResponse}
project={mockedProject}
/>,
);
expect(getByText('No issues found')).toBeInTheDocument();
});

it('renders error when data is missing', async () => {
const { getByText } = await renderInTestApp(
<JiraTable tableContent={undefined!} />,
<JiraTable tableContent={undefined!} project={undefined!} />,
);
expect(getByText('Table could not be rendered')).toBeInTheDocument();
});
Expand Down
20 changes: 18 additions & 2 deletions plugins/jira-dashboard/src/components/JiraTable/JiraTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ import Typography from '@mui/material/Typography';
import {
Issue,
JiraDataResponse,
Project,
} from '@axis-backstage/plugin-jira-dashboard-common';
import {
ErrorPanel,
InfoCard,
Link,
Table,
TableColumn,
TableFilter,
} from '@backstage/core-components';
import { capitalize } from 'lodash';
import { columns } from './columns';
import { transformAssignees } from '../../lib';
import { getJiraBaseUrl, transformAssignees } from '../../lib';

// Infer the prop types from the Table component
type TableComponentProps = React.ComponentProps<typeof Table>;
Expand All @@ -23,6 +25,7 @@ type Props = {
tableColumns?: TableColumn<Issue>[];
tableStyle?: TableComponentProps['style'];
showFilters?: TableFilter[] | boolean;
project?: Project;
};

export const JiraTable = ({
Expand All @@ -36,6 +39,7 @@ export const JiraTable = ({
width: '100%',
},
showFilters,
project,
}: Props) => {
if (!tableContent) {
return (
Expand Down Expand Up @@ -66,12 +70,24 @@ export const JiraTable = ({
}
}

const title = (
let title = (
<Typography component="div" variant="h5" data-testid="table-header">
{`${capitalize(tableContent.name)} (${nbrOfIssues})`}
</Typography>
);

if (project && tableContent.query) {
title = (
<Link
to={`${getJiraBaseUrl(project.self)}/issues/?jql=${tableContent.query}`}
variant="h5"
data-testid="table-header"
>
{`${capitalize(tableContent.name)} (${nbrOfIssues})`}
</Link>
);
}

if (showFilters) {
return (
<InfoCard title={title}>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "Open Issues",
"type": "filter",
"query": "resolution = Unresolved ORDER BY updated DESC",
"issues": [
{
"key": "BS-1",
Expand Down

0 comments on commit d3129c0

Please sign in to comment.