Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions .example.env
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,9 @@ REACT_DECIMAL_ROUNDING_METHOD=ROUND_HALF_UP
# Maximum number of forms that can be favorited in the forms dialog (default: 5)
REACT_MAX_FORM_DIALOG_FAVORITES=5

# Maximum number of datapoints allowed in a single upsert request (default: 100)
# Must not exceed the backend limit
REACT_MAX_DATAPOINTS_PER_UPSERT=100

# Default tab for medication selector. Valid values: product, valueset
REACT_MEDICATION_VALUE_SET_SELECT_DEFAULT_TAB=product
11 changes: 9 additions & 2 deletions care.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ const careConfig = {
: undefined),

defaultDischargeDisposition: env.REACT_DEFAULT_DISCHARGE_DISPOSITION as
| EncounterDischargeDisposition
| undefined,
EncounterDischargeDisposition | undefined,

mapFallbackUrlTemplate:
env.REACT_MAPS_FALLBACK_URL_TEMPLATE ||
Expand Down Expand Up @@ -407,6 +406,14 @@ const careConfig = {
maxFormDialogFavorites: env.REACT_MAX_FORM_DIALOG_FAVORITES
? parseInt(env.REACT_MAX_FORM_DIALOG_FAVORITES, 10)
: 5,

/**
* Maximum number of datapoints allowed in a single upsert request.
* Must not exceed the backend limit (defaults to 100).
Comment thread
NikhilA8606 marked this conversation as resolved.
Outdated
*/
maxDatapointsPerUpsert: env.REACT_MAX_DATAPOINTS_PER_UPSERT
Comment thread
rithviknishad marked this conversation as resolved.
? parseInt(env.REACT_MAX_DATAPOINTS_PER_UPSERT, 10)
Comment thread
NikhilA8606 marked this conversation as resolved.
: 100,
Comment thread
rithviknishad marked this conversation as resolved.
Comment thread
rithviknishad marked this conversation as resolved.
Comment thread
NikhilA8606 marked this conversation as resolved.
} as const;

export default careConfig;
1 change: 1 addition & 0 deletions scripts/validate-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ const envSchema = z
})
.optional(),
REACT_MAX_FORM_DIALOG_FAVORITES: numberAsString.optional(),
REACT_MAX_DATAPOINTS_PER_UPSERT: numberAsString.optional(),
Comment thread
rithviknishad marked this conversation as resolved.
Comment thread
rithviknishad marked this conversation as resolved.
})
.superRefine(async (data, ctx) => {
// Ensure at least one API URL configuration is provided
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { useMemo, useState } from "react";
import { Trans, useTranslation } from "react-i18next";
import { toast } from "sonner";

import careConfig from "@careConfig";

import CareIcon from "@/CAREUI/icons/CareIcon";
import ConfirmActionDialog from "@/components/Common/ConfirmActionDialog";
import Page from "@/components/Common/Page";
Expand Down Expand Up @@ -252,6 +254,9 @@ export function DeliveryOrderShow({
});
const { open: isSidebarOpen } = useSidebar();

const exceedsUpsertLimit =
selectedDeliveries.length > careConfig.maxDatapointsPerUpsert;

Comment thread
NikhilA8606 marked this conversation as resolved.
Outdated
const { data: deliveryOrder, isLoading } = useQuery({
queryKey: ["deliveryOrders", deliveryOrderId],
queryFn: query(deliveryOrderApi.retrieveDeliveryOrder, {
Expand Down Expand Up @@ -288,6 +293,7 @@ export function DeliveryOrderShow({
queryClient.invalidateQueries({
queryKey: ["supplyDeliveries", deliveryOrderId],
});
setSelectedDeliveries([]);
toast.success(t("supply_deliveries_updated_successfully"));
},
onError: (_error) => {
Expand Down Expand Up @@ -362,7 +368,6 @@ export function DeliveryOrderShow({
upsertSupplyDeliveries({

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

handleMarkAsAbandoned/handleMarkAsDamaged/handleSubmitDialog fire the upsert with zero regard for maxDatapointsPerUpsert. You built a limit check but only wired it into one disabled prop — the actual guard belongs in these handlers too (early-return with a toast), otherwise it's just decoration on a single button.

datapoints: selectedSupplyDeliveries,
});
Comment thread
NikhilA8606 marked this conversation as resolved.
setSelectedDeliveries([]);
}

function handleMarkAsDamaged() {
Expand All @@ -388,7 +393,6 @@ export function DeliveryOrderShow({
upsertSupplyDeliveries({
datapoints: selectedSupplyDeliveries,
});
setSelectedDeliveries([]);
}

function handleSubmitDialog() {
Expand All @@ -411,7 +415,6 @@ export function DeliveryOrderShow({
upsertSupplyDeliveries({
datapoints: selectedSupplyDeliveries,
});
setSelectedDeliveries([]);
setConfirmDialog((prev) => ({ ...prev, open: false }));
}

Expand Down Expand Up @@ -578,7 +581,8 @@ export function DeliveryOrderShow({
disabled={
isUpsertingDeliveries ||
isUpdating ||
selectedDeliveries.length !== 0
selectedDeliveries.length !== 0 ||
exceedsUpsertLimit
Comment thread
NikhilA8606 marked this conversation as resolved.
Outdated
Comment thread
NikhilA8606 marked this conversation as resolved.
Outdated
Comment thread
NikhilA8606 marked this conversation as resolved.
Outdated
Comment thread
NikhilA8606 marked this conversation as resolved.
Outdated
}
>
{isUpdating ? t("updating") : t("mark_as_completed")}
Expand Down
1 change: 1 addition & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ interface ImportMetaEnv {
readonly REACT_ACCOUNTING_PRECISION?: string;
readonly REACT_DECIMAL_ROUNDING_METHOD?: string;
readonly REACT_MAX_FORM_DIALOG_FAVORITES?: string;
readonly REACT_MAX_DATAPOINTS_PER_UPSERT?: string;
readonly REACT_MEDICATION_VALUE_SET_SELECT_DEFAULT_TAB?: string;

// Plugins related envs...
Expand Down
Loading