Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stock) : save user role scole #39

Merged
merged 4 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/stock-lookups/stock-lookups.resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export function useRoles(filter: ResourceFilterCriteria) {
Error
>(apiUrl, openmrsFetch);
return {
items: data.data ? data.data : [],
items: data?.data || <PageableResult<Role>>{},
isLoading,
isError: error,
};
Expand Down
4 changes: 2 additions & 2 deletions src/stock-operations/stock-operations-table.resource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function useStockOperationPages(filter: StockOperationFilter) {

const {
goTo,
results: paginatedQueueEntries,
results: paginatedItems,
currentPage,
} = usePagination(items.results, currentPageSize);

Expand Down Expand Up @@ -66,7 +66,7 @@ export function useStockOperationPages(filter: StockOperationFilter) {
totalItems: items?.totalCount,
currentPage,
currentPageSize,
paginatedQueueEntries,
paginatedItems,
goTo,
pageSizes,
isLoading,
Expand Down
1 change: 1 addition & 0 deletions src/stock-sources/add-stock-sources/add-stock-sources.scss
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ section {
.modalBody {
padding-bottom: spacing.$spacing-05;
}

202 changes: 171 additions & 31 deletions src/stock-sources/stock-sources-items-table.component.tsx
Original file line number Diff line number Diff line change
@@ -1,52 +1,192 @@
import React from "react";
import React, { useMemo } from "react";

import {
DataTableSkeleton,
DataTable,
Pagination,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableHeader,
TableRow,
TableToolbar,
TableToolbarContent,
Tile,
TableToolbarAction,
TableToolbarMenu,
DataTableSkeleton,
TableToolbarSearch,
} from "@carbon/react";
import { isDesktop } from "@openmrs/esm-framework";
import useStockSourcesPage from "./stock-sources-items-table.resource";
import { ResourceRepresentation } from "../core/api/api";
import DataList from "../core/components/table/table.component";
import AddStockSourceActionButton from "./add-stock-source-button.component";
import StockSourcesFilter from "./stock-sources-filter/stock-sources-filter.component";
import styles from "./stock-sources.scss";
import { useTranslation } from "react-i18next";

function StockSourcesItems() {
// get sources
const { isLoading, tableHeaders, tableRows } = useStockSourcesPage({
v: ResourceRepresentation.Full,
const { t } = useTranslation();

// get sourcess
const {
items,
tableHeaders,
currentPage,
pageSizes,
paginatedItems,
goTo,
currentPageSize,
setPageSize,
isLoading,
} = useStockSourcesPage({
v: ResourceRepresentation.Default,
totalCount: true,
});

const handleRefresh = () => {
// search.refetch()
};
const tableRows = useMemo(() => {
return items?.map((entry) => {
return {
...entry,
id: entry?.uuid,
key: `key-${entry?.uuid}`,
uuid: entry?.uuid,
name: entry?.name,
acronym: entry?.acronym,
sourceType: entry?.sourceType?.display,
};
});
}, [items]);

if (isLoading) {
if (isLoading || items.length === 0) {
return <DataTableSkeleton role="progressbar" />;
}

return (
<DataList columns={tableHeaders} data={tableRows}>
{({ onInputChange }) => (
<>
<TableToolbarSearch persistent onChange={onInputChange} />
<div
style={{
display: "flex",
alignItems: "center",
}}
>
<StockSourcesFilter />
</div>
<TableToolbarMenu>
<TableToolbarAction onClick={handleRefresh}>
Refresh
</TableToolbarAction>
</TableToolbarMenu>
<AddStockSourceActionButton />
</>
)}
</DataList>
<div className={styles.tableOverride}>
<div id="table-tool-bar">
<div></div>
<div className="right-filters"></div>
</div>
<DataTable
rows={tableRows}
headers={tableHeaders}
isSortable={true}
useZebraStyles={true}
render={({
rows,
headers,
getHeaderProps,
getTableProps,
getRowProps,
onInputChange,
}) => (
<TableContainer>
<TableToolbar
style={{
position: "static",
overflow: "visible",
backgroundColor: "color",
}}
>
<TableToolbarContent className={styles.toolbarContent}>
<TableToolbarSearch persistent onChange={onInputChange} />
<div
style={{
display: "flex",
alignItems: "center",
}}
>
<StockSourcesFilter />
</div>
<TableToolbarMenu>
<TableToolbarAction onClick={""}>Refresh</TableToolbarAction>
</TableToolbarMenu>
<AddStockSourceActionButton />
</TableToolbarContent>
</TableToolbar>
<Table {...getTableProps()}>
<TableHead>
<TableRow>
{headers.map(
(header: any) =>
header.key !== "details" && (
<TableHeader
{...getHeaderProps({
header,
isSortable: header.isSortable,
})}
className={
isDesktop
? styles.desktopHeader
: styles.tabletHeader
}
key={`${header.key}`}
>
{header.header?.content ?? header.header}
</TableHeader>
)
)}
<TableHeader></TableHeader>
</TableRow>
</TableHead>
<TableBody>
{rows.map((row: any) => {
return (
<React.Fragment key={row.id}>
<TableRow
className={
isDesktop ? styles.desktopRow : styles.tabletRow
}
{...getRowProps({ row })}
>
{row.cells.map(
(cell: any) =>
cell?.info?.header !== "details" && (
<TableCell key={cell.id}>{cell.value}</TableCell>
)
)}
</TableRow>
</React.Fragment>
);
})}
</TableBody>
</Table>
{rows.length === 0 ? (
<div className={styles.tileContainer}>
<Tile className={styles.tile}>
<div className={styles.tileContent}>
<p className={styles.content}>
{t("noSourcesToDisplay", "No Stock sources to display")}
</p>
<p className={styles.helper}>
{t("checkFilters", "Check the filters above")}
</p>
</div>
<p className={styles.separator}>{t("or", "or")}</p>
</Tile>
</div>
) : null}
</TableContainer>
)}
></DataTable>
<Pagination
page={currentPage}
pageSize={currentPageSize}
pageSizes={pageSizes}
totalItems={paginatedItems.length}
onChange={({ pageSize, page }) => {
if (pageSize !== currentPageSize) {
setPageSize(pageSize);
}
if (page !== currentPage) {
goTo(page);
}
}}
className={styles.paginationOverride}
/>
</div>
);
}

Expand Down
15 changes: 0 additions & 15 deletions src/stock-sources/stock-sources-items-table.resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,6 @@ export default function useStockSourcesPage(filter: StockOperationFilter) {
[]
);

const tableRows = useMemo(() => {
return items.results?.map((entry) => {
return {
...entry,
id: entry?.uuid,
key: `key-${entry?.uuid}`,
uuid: entry?.uuid,
name: entry?.name,
acronym: entry?.acronym,
sourceType: entry?.sourceType?.display,
};
});
}, [items.results]);

return {
items: items.results,
currentPage,
Expand All @@ -64,6 +50,5 @@ export default function useStockSourcesPage(filter: StockOperationFilter) {
isError,
setPageSize,
tableHeaders,
tableRows,
};
}
Loading
Loading