Skip to content

Commit

Permalink
Enhanced Jira Dashboard plugin to accommodate project key in data fet…
Browse files Browse the repository at this point in the history
…ching

Signed-off-by: enaysaa <[email protected]>
  • Loading branch information
SaachiNayyer committed Apr 18, 2024
1 parent 3276a1a commit 2b38273
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
19 changes: 19 additions & 0 deletions .changeset/short-buckets-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@axis-backstage/plugin-jira-dashboard': major
'app': minor
'backend': minor
'@axis-backstage/plugin-analytics-module-umami': minor
'@axis-backstage/plugin-jira-dashboard-backend': minor
'@axis-backstage/plugin-jira-dashboard-common': minor
'@axis-backstage/plugin-readme': minor
'@axis-backstage/plugin-readme-backend': minor
'@axis-backstage/plugin-statuspage': minor
'@axis-backstage/plugin-statuspage-backend': minor
'@axis-backstage/plugin-statuspage-common': minor
---

Implemented project key support for fetching Jira data in the Jira Dashboard plugin.
Updated the getJiraResponseByEntity method signature in JiraDashboardApi.tsx to include a projectKey parameter.
Enhanced the JiraDashboardContent.tsx file to extract the project key from entity metadata annotations and pass it to the useJira hook.
Modified the JiraTable.tsx file to include an optional prop project of type Project to accommodate the project key.
Updated the useJira.ts file to include the projectKey parameter in the useJira hook signature and pass it to the getJiraResponseByEntity method.
5 changes: 4 additions & 1 deletion plugins/jira-dashboard/src/api/JiraDashboardApi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export const jiraDashboardApiRef = createApiRef<JiraDashboardApi>({
});

export type JiraDashboardApi = {
getJiraResponseByEntity(entityRef: string): Promise<JiraResponse>;
getJiraResponseByEntity(
entityRef: string,
projectKey: string,
): Promise<JiraResponse>;
getProjectAvatar(entityRef: string): any;
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,22 @@ import { useEntity } from '@backstage/plugin-catalog-react';
import { stringifyEntityRef } from '@backstage/catalog-model';
import { jiraDashboardApiRef } from '../../api';
import { useJira } from '../../hooks/useJira';
import { JiraDataResponse } from '@axis-backstage/plugin-jira-dashboard-common';
import {
JiraDataResponse,
PROJECT_KEY_NAME,
} from '@axis-backstage/plugin-jira-dashboard-common';

export const JiraDashboardContent = () => {
const { entity } = useEntity();
const projectKey =
entity?.metadata.annotations?.[PROJECT_KEY_NAME]?.split(',')[0]!;
const api = useApi(jiraDashboardApiRef);

const {
data: jiraResponse,
loading,
error,
} = useJira(stringifyEntityRef(entity), api);
} = useJira(stringifyEntityRef(entity), projectKey, api);

if (loading) {
return <Progress />;
Expand All @@ -37,7 +42,7 @@ export const JiraDashboardContent = () => {
return (
<ResponseErrorPanel
error={Error(
'Could not fetch Jira Dashboard content for defined project key',
`Could not fetch Jira Dashboard content for project key: ${projectKey}`,
)}
/>
);
Expand Down Expand Up @@ -70,7 +75,10 @@ export const JiraDashboardContent = () => {
</Grid>
{jiraResponse.data.map((value: JiraDataResponse) => (
<Grid data-testid="issue-table" key={value.name} md={6} xs={12}>
<JiraTable tableContent={value} />
<JiraTable
tableContent={value}
project={jiraResponse.project}
/>
</Grid>
))}
</>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import React from 'react';
import Typography from '@mui/material/Typography';
import { JiraDataResponse } from '@axis-backstage/plugin-jira-dashboard-common';
import {
JiraDataResponse,
Project,
} from '@axis-backstage/plugin-jira-dashboard-common';
import { ErrorPanel, Table } from '@backstage/core-components';
import { capitalize } from 'lodash';
import { columns } from './columns';

type Props = {
tableContent: JiraDataResponse;
project?: Project;
};

export const JiraTable = ({ tableContent }: Props) => {
Expand Down
6 changes: 5 additions & 1 deletion plugins/jira-dashboard/src/hooks/useJira.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { JiraDashboardApi } from '../api';

export function useJira(
entityRef: string,
projectKey: string,
jiraDashboardApi: JiraDashboardApi,
): {
data: JiraResponse | undefined;
Expand All @@ -15,7 +16,10 @@ export function useJira(
loading,
error,
} = useAsync(async (): Promise<any> => {
const response = await jiraDashboardApi.getJiraResponseByEntity(entityRef);
const response = await jiraDashboardApi.getJiraResponseByEntity(
entityRef,
projectKey,
);
response.project.avatarUrls = await jiraDashboardApi.getProjectAvatar(
entityRef,
);
Expand Down

0 comments on commit 2b38273

Please sign in to comment.