Skip to content

Commit

Permalink
feat: Implement catalog_incident api (#2147)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleixhub authored Sep 18, 2024
1 parent c62a376 commit 1e7f118
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
5 changes: 2 additions & 3 deletions catalog/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,8 @@ async def catalog_item_incidents(request):
asset_uuid = request.match_info.get('asset_uuid')
stage = request.match_info.get('stage')
data = await request.json()
headers = {
"Authorization": f"Bearer {reporting_api_authorization_token}"
}
headers = request.headers
headers["Authorization"] = f"Bearer {reporting_api_authorization_token}"
return await api_proxy(
headers=headers,
method="POST",
Expand Down
2 changes: 1 addition & 1 deletion catalog/ui/src/app/Admin/CatalogItemAdmin.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('CatalogItemAdmin Component', () => {
status: 'Operational',
incident_url: '',
jira_url: '',
comments: [],
comments: JSON.stringify([]),
}
await userEvent.click(getByText('Save'));
expect(fetcher).toHaveBeenCalledWith(path, { method: 'POST', body: JSON.stringify(patch), headers: {'Content-Type': 'application/json'}});
Expand Down
29 changes: 20 additions & 9 deletions catalog/ui/src/app/Admin/CatalogItemAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,22 @@ const CatalogItemAdmin: React.FC = () => {
const navigate = useNavigate();
const { data: catalogItem } = useSWR<CatalogItem>(apiPaths.CATALOG_ITEM({ namespace, name }), fetcher);
const asset_uuid = catalogItem.metadata.labels['gpte.redhat.com/asset-uuid'];
const { data: catalogItemIncident } = useSWR<CatalogItemIncident>(
const { data: catalogItemIncident, isLoading: isLoadingIncidents } = useSWR<CatalogItemIncident>(
apiPaths.CATALOG_ITEM_LAST_INCIDENT({ namespace, asset_uuid }),
fetcher
fetcher,
{
suspense: false,
shouldRetryOnError: false,
}
);
const { email: userEmail } = useSession().getSession();
const [isReadOnlyValue, setIsReadOnlyValue] = useState(false);
const [isOpen, setIsOpen] = useState(false);
const [isLoading, setIsLoading] = useState(false);
const [status, setStatus] = useState(catalogItemIncident?.status || 'Operational');
const [isDisabled, setIsDisabled] = useState(catalogItemIncident?.disabled ?? false);
const [incidentUrl, setIncidentUrl] = useState(catalogItemIncident?.incident_url || '');
const [jiraIssueId, setJiraIssueId] = useState(catalogItemIncident?.jira_url || '');
const [status, setStatus] = useState('Operational');
const [isDisabled, setIsDisabled] = useState(false);
const [incidentUrl, setIncidentUrl] = useState('');
const [jiraIssueId, setJiraIssueId] = useState('');
const [comment, setComment] = useState('');
const provider = getProvider(catalogItem);

Expand All @@ -79,6 +83,13 @@ const CatalogItemAdmin: React.FC = () => {
}
}, [setIsReadOnlyValue, status]);

useEffect(() => {
setStatus(catalogItemIncident?.status || 'Operational');
setIsDisabled(catalogItemIncident?.disabled ?? false);
setIncidentUrl(catalogItemIncident?.incident_url || '');
setJiraIssueId(catalogItemIncident?.jira_url || '');
}, [isLoadingIncidents])

async function removeComment(comment: comment) {
if (!catalogItemIncident?.comments) {
throw "Can't find comment to delete";
Expand All @@ -93,7 +104,7 @@ const CatalogItemAdmin: React.FC = () => {
async function saveForm(comments?: comment[]) {
setIsLoading(true);
if (comments === null || comments === undefined) {
comments = JSON.parse(catalogItemIncident?.comments) || [];
comments = catalogItemIncident ? JSON.parse(catalogItemIncident.comments) : [];
}
if (comment) {
comments.push({
Expand All @@ -111,7 +122,7 @@ const CatalogItemAdmin: React.FC = () => {
status,
incident_url: incidentUrl,
jira_url: jiraIssueId,
comments,
comments: JSON.stringify(comments),
}),
headers: {
'Content-Type': 'application/json',
Expand All @@ -123,7 +134,7 @@ const CatalogItemAdmin: React.FC = () => {

return (
<PageSection key="body" variant={PageSectionVariants.light}>
{isLoading ? (
{isLoading || isLoadingIncidents ? (
<EmptyState variant="full" className="catalog-item-admin__loading">
<EmptyStateHeader icon={<EmptyStateIcon icon={LoadingIcon} />} />
</EmptyState>
Expand Down
6 changes: 3 additions & 3 deletions catalog/ui/src/app/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1612,11 +1612,11 @@ export const apiPaths: { [key in ResourceType]: (args: any) => string } = {
continueId ? `&continue=${continueId}` : ''
}${labelSelector ? `&labelSelector=${labelSelector}` : ''}`,
CATALOG_ITEM_INCIDENTS: ({ namespace, asset_uuid }: { namespace: string; asset_uuid: string }) =>
`/api/catalog_incident/incidents/${asset_uuid}/${namespace}`,
`/api/catalog_incident/incidents/${asset_uuid}/${namespace.split('-').slice(-1)[0]}`,
CATALOG_ITEM_LAST_INCIDENT: ({ namespace, asset_uuid }: { namespace: string; asset_uuid: string }) =>
`/api/catalog_incident/last-incident/${asset_uuid}/${namespace}`,
`/api/catalog_incident/last-incident/${asset_uuid}/${namespace.split('-').slice(-1)[0]}`,
CATALOG_ITEMS_ACTIVE_INCIDENTS: ({ namespace }: { namespace?: string }) =>
`/api/catalog_incident/active-incidents${namespace ? `?stage=${namespace}` : ''}`,
`/api/catalog_incident/active-incidents${namespace ? `?stage=${namespace.split('-').slice(-1)[0]}` : ''}`,
RESOURCE_CLAIMS: ({
namespace,
limit,
Expand Down

0 comments on commit 1e7f118

Please sign in to comment.