Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
peterMuriuki committed Jul 15, 2024
1 parent a99cc1c commit 312dd28
Show file tree
Hide file tree
Showing 18 changed files with 579 additions and 504 deletions.
44 changes: 19 additions & 25 deletions packages/fhir-import/src/components/statusTag.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
import React from 'react';
import { Tag } from 'antd';
import { JobStatus } from '../helpers/utils';

export const ImportStatusTag = ({ statusString }: { statusString: JobStatus }) => {
const tagStatusColor = getStatusColor(statusString)
return (<Tag color={tagStatusColor}>
{statusString}
</Tag>)
}

type JobStatus =
| 'completed'
| 'waiting'
| 'active'
| 'delayed'
| 'failed'
| 'paused';
const tagStatusColor = getStatusColor(statusString);
return <Tag color={tagStatusColor}>{statusString}</Tag>;
};

/**
* @param statusString - get tag status color for a job status
*/
export function getStatusColor(statusString: JobStatus) {
switch (statusString) {
case "completed":
return "success"
case "active":
return "processing"
case "failed":
return "error"
case "paused":
return "warning"
default:
return "default"
}
switch (statusString) {
case 'completed':
return 'success';
case 'active':
return 'processing';
case 'failed':
return 'error';
case 'paused':
return 'warning';
default:
return 'default';
}
}
33 changes: 16 additions & 17 deletions packages/fhir-import/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
export const DATA_IMPORT_LIST_URL = "/import"
export const DATA_IMPORT_DETAIL_URL = "/importDetail"
export const DATA_IMPORT_CREATE_URL = "/importCreate"
export const DATA_IMPORT_LIST_URL = '/import';
export const DATA_IMPORT_DETAIL_URL = '/importDetail';
export const DATA_IMPORT_CREATE_URL = '/importCreate';

export const IMPORT_ENDPOINT = "/$import"
export const IMPORT_DOMAIN_URI=""
export const IMPORT_TEMPLATE_ENDPOINT = `${IMPORT_ENDPOINT}/templates`
export const IMPORT_ENDPOINT = '/$import';
export const IMPORT_DOMAIN_URI = '';
export const IMPORT_TEMPLATE_ENDPOINT = `${IMPORT_ENDPOINT}/templates`;


export const dataImportRQueryKey = "dataImport"
export const locations = "locations" as const
export const users = "users" as const
export const organizations = "organizations" as const
export const careteams = "careteams" as const
export const inventories = "inventories" as const
export const orgToLocationAssignment = "orgToLocationAssignment" as const
export const userToOrganizationAssignment = "userToOrganizationAssignment" as const
export const products = "products" as const
export const productImages = "productImages" as const
export const dataImportRQueryKey = 'dataImport';
export const locations = 'locations' as const;
export const users = 'users' as const;
export const organizations = 'organizations' as const;
export const careteams = 'careteams' as const;
export const inventories = 'inventories' as const;
export const orgToLocationAssignment = 'orgToLocationAssignment' as const;
export const userToOrganizationAssignment = 'userToOrganizationAssignment' as const;
export const products = 'products' as const;
export const productImages = 'productImages' as const;
73 changes: 40 additions & 33 deletions packages/fhir-import/src/containers/ImportDetailView/index.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import React from 'react';
import { Spin, Tabs } from 'antd';
import { useQuery } from 'react-query';
import {
BrokenPage,
} from '@opensrp/react-utils';
import { BrokenPage } from '@opensrp/react-utils';
import { dataImportRQueryKey, IMPORT_DOMAIN_URI } from '../../constants';
import { useTranslation } from '../../mls';
import { OpenSRPService, BodyLayout, ResourceDetails, Resource404, KeyValuesDescriptions } from '@opensrp/react-utils';
import {
OpenSRPService,
BodyLayout,
ResourceDetails,
Resource404,
KeyValuesDescriptions,
} from '@opensrp/react-utils';
import { Helmet } from 'react-helmet';
import { useParams } from 'react-router';
import { formatTimestamp } from '../../helpers/utils'
import { getStatusColor } from '../../components/statusTag'
import "./index.css";
import { formatTimestamp, WorkflowDescription } from '../../helpers/utils';
import { getStatusColor } from '../../components/statusTag';
import './index.css';

/** typings for the view details component */
export interface RouteComponentProps {
Expand All @@ -21,25 +25,26 @@ export interface RouteComponentProps {
/**
* Details view for a single workflow during bulk uploads.
*
* @param props - detail view component props
* @param _ - detail view component props
*/
export const ImportDetailViewDetails = (_: RouteComponentProps) => {
const params = useParams<RouteComponentProps>();
const workflowId = params.workflowId;
const { t } = useTranslation();

const { data, isLoading, error } = useQuery(
[dataImportRQueryKey, workflowId], () => {
const service = new OpenSRPService(`/$import`, IMPORT_DOMAIN_URI)
return service.read(workflowId).then(res => {
return res
})
}, {
enabled: !!workflowId,
}
const { data, isLoading, error } = useQuery<WorkflowDescription>(
[dataImportRQueryKey, workflowId],
() => {
const service = new OpenSRPService(`/$import`, IMPORT_DOMAIN_URI);
return service.read(workflowId).then((res) => {
return res;
});
},
{
enabled: !!workflowId,
}
);


if (isLoading) {
return <Spin size="large" className="custom-spinner" />;
}
Expand All @@ -60,7 +65,6 @@ export const ImportDetailViewDetails = (_: RouteComponentProps) => {
},
};


const dateCreatedKeyPairing = {
[t('Date Created')]: formatTimestamp(data.dateCreated),
};
Expand All @@ -73,42 +77,45 @@ export const ImportDetailViewDetails = (_: RouteComponentProps) => {
[t('Workflow type')]: data.workflowType,
[t('Date Started')]: formatTimestamp(data.dateStarted),
[t('Date Ended')]: formatTimestamp(data.dateEnded),
[t('Author')]: data.author
[t('Author')]: data.author,
};

return (
<BodyLayout headerProps={headerProps}>
<Helmet>
<title>{pageTitle} </title>
</Helmet>
<div className='view-details-container'>
<div className="view-details-container">
<ResourceDetails
title={data.workflowType}
headerLeftData={headerLeftData}
headerRightData={dateCreatedKeyPairing}
status={{
title: data.status,
color: getStatusColor(data.status)
color: getStatusColor(data.status),
}}
bodyData={() => <KeyValuesDescriptions data={otherDetailsMap} column={2} />}
/>
<Tabs
data-testid="details-tab"
style={{ width: '100%' }}
size={'small'}
items={[{
label: t('Log Output'),
key: "logOutput",
children: <div className="terminal-output">
<pre>
{data.statusReason?.stdout}
{data.statusReason?.stderr}
</pre>
</div>,
}]}
items={[
{
label: t('Log Output'),
key: 'logOutput',
children: (
<div className="terminal-output">
<pre>
{data.statusReason?.stdout}
{data.statusReason?.stderr}
</pre>
</div>
),
},
]}
/>
</div>
</BodyLayout>
);
};

Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ describe('Care Teams list view', () => {
</title>
`);

expect(document.querySelector(".view-details-container")!.textContent).toMatchSnapshot("innerDetailsText");
expect(
(document.querySelector('.view-details-container') as HTMLElement).textContent
).toMatchSnapshot('innerDetailsText');

expect(nock.pendingMocks()).toEqual([]);
});
Expand Down
44 changes: 21 additions & 23 deletions packages/fhir-import/src/containers/ImportListView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,18 @@ import { BodyLayout, OpenSRPService } from '@opensrp/react-utils';
import { CloudUploadOutlined } from '@ant-design/icons';
import { RouteComponentProps } from 'react-router';
import { useHistory, Link } from 'react-router-dom';
import {
BrokenPage,
TableLayout,
} from '@opensrp/react-utils';
import { BrokenPage, TableLayout } from '@opensrp/react-utils';
import {
DATA_IMPORT_DETAIL_URL,
DATA_IMPORT_CREATE_URL,
dataImportRQueryKey,
IMPORT_DOMAIN_URI
IMPORT_DOMAIN_URI,
} from '../../constants';
import { useTranslation } from '../../mls';
import { RbacCheck } from '@opensrp/rbac';
import { useQuery } from 'react-query';
import { WorkflowDescription, formatTimestamp } from '../../helpers/utils';
import { ImportStatusTag } from '../../components/statusTag'

import { JobStatus, WorkflowDescription, formatTimestamp } from '../../helpers/utils';
import { ImportStatusTag } from '../../components/statusTag';

// route params for care team pages
interface RouteParams {
Expand All @@ -37,17 +33,16 @@ export const DataImportList = () => {
const history = useHistory();

const { data, isFetching, isLoading, error } = useQuery(dataImportRQueryKey, () => {
const service = new OpenSRPService("/$import", IMPORT_DOMAIN_URI)
return service.list().then(res => {
return res
})
})
const service = new OpenSRPService('/$import', IMPORT_DOMAIN_URI);
return service.list().then((res) => {
return res;
});
});

if (error && !data) {
return <BrokenPage errorMessage={(error as Error).message} />;
}


const columns = [
{
title: t('Workflow Id'),
Expand All @@ -64,20 +59,20 @@ export const DataImportList = () => {
{
title: t('status'),
dataIndex: 'status' as const,
render: (_: any) => {
return <ImportStatusTag statusString={_} />
}
render: (_: JobStatus) => {
return <ImportStatusTag statusString={_} />;
},
},
{
title: t('Date created'),
dataIndex: 'dateCreated' as const,
defaultSortOrder: 'descend' as const,
sortDirections: ['ascend' as const, 'descend' as const],
sorter: (a: any, b: any) => {
const diff = a.dateCreated - b.dateCreated
return diff === 0 ? 0 : diff > 0 ? 1 : -1
sorter: (a: WorkflowDescription, b: WorkflowDescription) => {
const diff = a.dateCreated - b.dateCreated;
return diff === 0 ? 0 : diff > 0 ? 1 : -1;
},
render: (_: any) => formatTimestamp(_),
render: (_: number) => formatTimestamp(_),
},
{
title: t('Actions'),
Expand All @@ -88,7 +83,10 @@ export const DataImportList = () => {
<span className="d-flex align-items-center">
<RbacCheck permissions={['WebDataImport.read']}>
<>
<Link to={`${DATA_IMPORT_DETAIL_URL}/${record.workflowId.toString()}`} className="m-0 p-1">
<Link
to={`${DATA_IMPORT_DETAIL_URL}/${record.workflowId.toString()}`}
className="m-0 p-1"
>
{t('View')}
</Link>
</>
Expand All @@ -99,7 +97,7 @@ export const DataImportList = () => {
];

const tableProps = {
datasource: (data ?? []),
datasource: data ?? [],
columns,
loading: isFetching || isLoading,
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
export const workflows = [ {
"workflowId": "26aae779-0e6f-482d-82c3-a0fad1fd3689_orgToLocationAssignment",
"status": "completed",
"workflowType": "orgToLocationAssignment",
"dateCreated": 1720096011433,
"dateStarted": 1720096011435,
"dateEnded": 1720096013898,
"statusReason": {
"stdout": "Progress::Reading csv \n",
"stderr": "Start time: 15:26:53\nStarting csv import...\nReading csv file\nReturning records from csv file\nUnsupported request!\n{ \"final-response\": }\nEnd time: 15:26:53\nTotal time: 0.002815 seconds\n"
export const workflows = [
{
workflowId: '26aae779-0e6f-482d-82c3-a0fad1fd3689_orgToLocationAssignment',
status: 'completed',
workflowType: 'orgToLocationAssignment',
dateCreated: 1720096011433,
dateStarted: 1720096011435,
dateEnded: 1720096013898,
statusReason: {
stdout: 'Progress::Reading csv \n',
stderr:
'Start time: 15:26:53\nStarting csv import...\nReading csv file\nReturning records from csv file\nUnsupported request!\n{ "final-response": }\nEnd time: 15:26:53\nTotal time: 0.002815 seconds\n',
},
filename: 'organizations_locations.csv',
},
"filename": "organizations_locations.csv"
}]
];
Loading

0 comments on commit 312dd28

Please sign in to comment.