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

Enhance stock user roles to display all tagged locations. #201

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
10 changes: 8 additions & 2 deletions src/stock-lookups/stock-lookups.resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { Concept } from "../core/api/types/concept/Concept";
import { Party } from "../core/api/types/Party";
import { Drug } from "../core/api/types/concept/Drug";
import { Patient } from "../core/api/types/identity/Patient";
import { useMemo } from "react";
import { useMemo, useState } from "react";
import { uniqBy } from "lodash-es";
import { UserRoleScope } from "../core/api/types/identity/UserRoleScope";

Expand Down Expand Up @@ -59,7 +59,8 @@ export function useStockLocations(filter: LocationFilterCriteria) {
Unless a location is tag as main store, main pharmacy or dispensing, it will not be fetched.
*/
export function useStockTagLocations() {
const apiUrl = `${fhirBaseUrl}/Location?_summary=data&_tag=main store,main pharmacy,dispensary `;
const [count, setCount] = useState(100);
const apiUrl = `${fhirBaseUrl}/Location?_summary=data&_tag=main store,main pharmacy,dispensary&_count=${count}`;
const { data, error, isLoading } = useSWR<{ data: FHIRResponse }>(
apiUrl,
openmrsFetch
Expand All @@ -68,10 +69,15 @@ export function useStockTagLocations() {
() => data?.data?.entry?.map((response) => response.resource) ?? [],
[data?.data?.entry]
);
const increaseCount = () => {
setCount((prevCount) => prevCount + 100);
};
return {
stockLocations: uniqBy(stockLocations, "id") ?? [],
isLoading,
error,
count,
increaseCount,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ const AddStockUserRoleScope: React.FC<AddStockUserRoleScopeProps> = ({
.filter((item: any) => item.uuid !== loggedInUserUuid)
.filter((item: any) => {
const displayName = item?.person?.display ?? item?.display ?? "";
return displayName?.toLowerCase().includes(query?.toLowerCase());
return displayName.toLowerCase().includes(query.toLowerCase());
});
setFilteredItems(filtered);
}
Expand Down Expand Up @@ -443,8 +443,8 @@ const AddStockUserRoleScope: React.FC<AddStockUserRoleScopeProps> = ({
</span>
</div>
</section>
<section className={styles.section}>
<CheckboxGroup className={styles.checkboxGrid}>
<section className={styles.sectionScroll}>
<CheckboxGroup className={styles.checkboxGridScroll}>
{stockLocations?.length > 0 &&
stockLocations.map((type) => {
const checkedLocation = findCheckedLocation(type);
Expand All @@ -459,16 +459,11 @@ const AddStockUserRoleScope: React.FC<AddStockUserRoleScopeProps> = ({

return (
<div
style={{
display: "flex",
flexDirection: "row",
margin: "4px",
padding: "5px",
}}
key={`chk-loc-child-key-${type.id}`}
className={styles.checkboxItem}
>
<Checkbox
name="location"
key={`chk-loc-child-key-${type.id}`}
id={`chk-loc-child-${type.id}`}
value={type.id}
onChange={(event) => onLocationCheckBoxChanged(event)}
Expand All @@ -481,7 +476,7 @@ const AddStockUserRoleScope: React.FC<AddStockUserRoleScopeProps> = ({
value={type.id}
hideLabel
className={styles.toggle}
size={"sm"}
size="sm"
onToggleClick={getToggledValue(type.id)}
key={`tg-loc-child-key-${type.id}`}
id={`tg-loc-child-${type.id}`}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@
.section {
margin: spacing.$spacing-03;
}
.sectionScroll {
margin: spacing.$spacing-03;
height: 200px;
width: 60%;
overflow-y: auto;
max-height: 200px;
border: 1px solid #ddd;
}

.checkboxGridScroll {
display: flex;
flex-direction: column;
width: 20%;
}
.checkboxItem {
display: flex;
flex-direction: row;
margin: 4px 0;
padding:5px;
gap: 8px;
}

.sectionTitle {
@include type.type-style('heading-compact-02');
Expand All @@ -23,8 +44,8 @@

.checkboxGrid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); /* Adjust the values as needed */
gap: 16px; /* Adjust the gap between checkboxes */
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
gap: 16px;
}

.hr {
Expand Down
Loading