Skip to content

Commit

Permalink
Add table, integrate search and i18n-lize
Browse files Browse the repository at this point in the history
  • Loading branch information
bobbyqiz448 committed Feb 28, 2024
1 parent 6ec15bf commit af9955f
Showing 1 changed file with 197 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,199 @@
import React from "react"
import React, { useEffect, useState } from "react";

Check failure on line 1 in packages/fhir-location-management/src/components/AllLocationListFlat/index.tsx

View workflow job for this annotation

GitHub Actions / test (16.17.0, ubuntu-latest)

Replace `"react"` with `'react'`
import { useSimpleTabularView } from '@opensrp/react-utils';
import { RouteComponentProps } from 'react-router';
import { ILocation } from '@smile-cdr/fhirts/dist/FHIR-R4/interfaces/ILocation';
import { locationResourceType, URL_LOCATION_UNIT_EDIT, URL_LOCATION_UNIT_ADD } from '../../constants';

Check failure on line 5 in packages/fhir-location-management/src/components/AllLocationListFlat/index.tsx

View workflow job for this annotation

GitHub Actions / test (16.17.0, ubuntu-latest)

Replace `·locationResourceType,·URL_LOCATION_UNIT_EDIT,·URL_LOCATION_UNIT_ADD·` with `⏎··locationResourceType,⏎··URL_LOCATION_UNIT_EDIT,⏎··URL_LOCATION_UNIT_ADD,⏎`
import {
BrokenPage,

Check failure on line 7 in packages/fhir-location-management/src/components/AllLocationListFlat/index.tsx

View workflow job for this annotation

GitHub Actions / test (16.17.0, ubuntu-latest)

Delete `··`
useSearchParams,

Check failure on line 8 in packages/fhir-location-management/src/components/AllLocationListFlat/index.tsx

View workflow job for this annotation

GitHub Actions / test (16.17.0, ubuntu-latest)

Delete `··`
TableLayout,

Check failure on line 9 in packages/fhir-location-management/src/components/AllLocationListFlat/index.tsx

View workflow job for this annotation

GitHub Actions / test (16.17.0, ubuntu-latest)

Delete `··`
viewDetailsQuery,

Check failure on line 10 in packages/fhir-location-management/src/components/AllLocationListFlat/index.tsx

View workflow job for this annotation

GitHub Actions / test (16.17.0, ubuntu-latest)

Delete `··`
PageHeader,

Check failure on line 11 in packages/fhir-location-management/src/components/AllLocationListFlat/index.tsx

View workflow job for this annotation

GitHub Actions / test (16.17.0, ubuntu-latest)

Delete `··`
SearchForm,

Check failure on line 12 in packages/fhir-location-management/src/components/AllLocationListFlat/index.tsx

View workflow job for this annotation

GitHub Actions / test (16.17.0, ubuntu-latest)

Delete `··`
} from '@opensrp/react-utils';
import { Dictionary } from '@onaio/utils';
import { Helmet } from 'react-helmet';
import { useTranslation } from '../../mls';
import { Row, Col, Button, Divider, Dropdown, Popconfirm } from 'antd';

Check failure on line 17 in packages/fhir-location-management/src/components/AllLocationListFlat/index.tsx

View workflow job for this annotation

GitHub Actions / test (16.17.0, ubuntu-latest)

'Popconfirm' is defined but never used. Allowed unused vars must match /^_/u
import { useHistory, Link } from 'react-router-dom';
import { RbacCheck, useUserRole } from '@opensrp/rbac';
import type { MenuProps } from 'antd';
import { MoreOutlined, PlusOutlined } from '@ant-design/icons';
import { LocationUnitDetail } from '../LocationUnitDetail';

export const AllLocationListFlat = ()=>{
return (
<div>All Locations Rendered</div>
)

Check failure on line 24 in packages/fhir-location-management/src/components/AllLocationListFlat/index.tsx

View workflow job for this annotation

GitHub Actions / test (16.17.0, ubuntu-latest)

Delete `⏎⏎`

interface RouteParams {
locationId: string | undefined;
}

interface Props {
fhirBaseURL: string;
LocationPageSize: number;
}

const getSearchParams = () => {
return { "_include": "Location:partof" };
};

export type LocationListPropTypes = Props & RouteComponentProps<RouteParams>;



export const AllLocationListFlat: React.FC<LocationListPropTypes> = (props) => {
const { fhirBaseURL } = props;
const { t } = useTranslation();
const history = useHistory();
const [detailId, setDetailId] = useState<string>('');
const { addParam, sParams } = useSearchParams();
const userRole = useUserRole();
const resourceId = sParams.get(viewDetailsQuery) ?? undefined;

const {
queryValues: { data, isFetching, isLoading, error, refetch },
tablePaginationProps,
searchFormProps,
} = useSimpleTabularView<ILocation>(fhirBaseURL, locationResourceType, getSearchParams());

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

// this is for debugging
useEffect(() => {
console.log("Component mounted");

Check warning on line 64 in packages/fhir-location-management/src/components/AllLocationListFlat/index.tsx

View workflow job for this annotation

GitHub Actions / test (16.17.0, ubuntu-latest)

Unexpected console statement
console.log("Data:", data);

Check warning on line 65 in packages/fhir-location-management/src/components/AllLocationListFlat/index.tsx

View workflow job for this annotation

GitHub Actions / test (16.17.0, ubuntu-latest)

Unexpected console statement
console.log("Is Fetching:", isFetching);

Check warning on line 66 in packages/fhir-location-management/src/components/AllLocationListFlat/index.tsx

View workflow job for this annotation

GitHub Actions / test (16.17.0, ubuntu-latest)

Unexpected console statement
console.log("Is Loading:", isLoading);

Check warning on line 67 in packages/fhir-location-management/src/components/AllLocationListFlat/index.tsx

View workflow job for this annotation

GitHub Actions / test (16.17.0, ubuntu-latest)

Unexpected console statement
console.log("Error:", error);

Check warning on line 68 in packages/fhir-location-management/src/components/AllLocationListFlat/index.tsx

View workflow job for this annotation

GitHub Actions / test (16.17.0, ubuntu-latest)

Unexpected console statement

return () => {
console.log("Component unmounted");

Check warning on line 71 in packages/fhir-location-management/src/components/AllLocationListFlat/index.tsx

View workflow job for this annotation

GitHub Actions / test (16.17.0, ubuntu-latest)

Unexpected console statement
};
}, [data, isFetching, isLoading, error]);
// TODO delete this (useEffect)


const tableData: any[] = (data?.records ?? []).map((datum: Dictionary) => ({

Check warning on line 77 in packages/fhir-location-management/src/components/AllLocationListFlat/index.tsx

View workflow job for this annotation

GitHub Actions / test (16.17.0, ubuntu-latest)

Unexpected any. Specify a different type
key: datum.id,
id: datum.id,
name: datum.name,
}));

type TableData = typeof tableData[0];


const getItems = (record: TableData): MenuProps['items'] => {
return [

{
key: '1',
permissions: [],
label: (
<Button type="link" onClick={() => addParam(viewDetailsQuery, record.id)}>
View Details
</Button>
),
},
]
.filter((item) => userRole.hasPermissions(item.permissions))
.map((item) => {
const { permissions, ...rest } = item;
return rest;
});
};

const columns = [
// {
// title: t('Name'),
// dataIndex: 'name' as const,
// editable: true,
// },
{
title: t('Type'),
dataIndex: 'resourceType' as const,
editable: true,
},
{
title: t('Status'),
dataIndex: 'status' as const,
editable: true,
},
{
title: t('Parent'),
dataIndex: 'parent' as const,
editable: true,
},
{
title: t('Actions'),
width: '10%',

// eslint-disable-next-line react/display-name
render: (_: unknown, record: TableData) => (
<span className="d-flex align-items-center">
<RbacCheck permissions={['Location.update']}>
<>
<Link to={`${URL_LOCATION_UNIT_EDIT}/${record.id.toString()}`} className="m-0 p-1">
{t('Edit')}
</Link>
<Divider type="vertical" />
</>
</RbacCheck>
<Dropdown
menu={{ items: getItems(record) }}
placement="bottomRight"
arrow
trigger={['click']}
>
<MoreOutlined className="more-options" data-testid="action-dropdown" />
</Dropdown>
</span>
),
},
];



const tableProps = {
datasource: tableData,
columns,
loading: isFetching || isLoading,
pagination: tablePaginationProps,
};

return (
<div className="content-section">
<Helmet>
<title>{t('All Locations List')}</title>
</Helmet>
<PageHeader title={t('All Locations Flat')} />
<Row className="list-view">
<Col className="main-content">
<div className="main-content__header">
<SearchForm {...searchFormProps} />
<RbacCheck permissions={['Location.create']}>
<Link to={URL_LOCATION_UNIT_ADD}>
<Button type="primary" onClick={() => history.push(URL_LOCATION_UNIT_ADD)}>
<PlusOutlined />
{t('Add Location')}
</Button>
</Link>
</RbacCheck>
</div>
<TableLayout {...tableProps} />
</Col>
{detailId ? (
<LocationUnitDetail
fhirBaseUrl={fhirBaseURL}
onClose={() => setDetailId('')}
detailId={detailId}
/>
) : null}
</Row>
</div>
);
};




0 comments on commit af9955f

Please sign in to comment.