Skip to content

Commit

Permalink
Hide N/A and null values in event log ohcnetwork#8376 (ohcnetwork#8381)
Browse files Browse the repository at this point in the history
* Hide N/A and null values in event log ohcnetwork#8376

* Hide N/A and null values in GenericEvent component

* Refactor GenericEvent component to improve readability and efficiency

* Revert NeurologicalTables.tsx to previous state

* Resolved conflict in GenericEvent component

---------

Co-authored-by: Mohammed Nihal <[email protected]>
Co-authored-by: Rithvik Nishad <[email protected]>
  • Loading branch information
3 people authored and UdaySagar-Git committed Aug 23, 2024
1 parent 2ab8f4d commit 7f51640
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/Components/Facility/ConsultationDetails/Events/GenericEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ interface IProps {
* object - array, date
*/
const formatValue = (value: unknown, key?: string): ReactNode => {
if (value == null) {
return "N/A";
if (value == null || value === "N/A") {
return null;
}

if (typeof value === "boolean") {
Expand All @@ -25,7 +25,7 @@ const formatValue = (value: unknown, key?: string): ReactNode => {
const trimmed = value.trim().replaceAll(/_/g, " ");

if (trimmed === "") {
return "Empty";
return null;
}

if (!isNaN(Number(trimmed))) {
Expand All @@ -50,8 +50,8 @@ const formatValue = (value: unknown, key?: string): ReactNode => {

return (
<ul className="list-disc space-y-2 pl-4">
{value.map((v) => (
<li>{formatValue(v, key)}</li>
{value.map((v, idx) => (
<li key={idx}>{formatValue(v, key)}</li>
))}
</ul>
);
Expand All @@ -69,8 +69,8 @@ const formatValue = (value: unknown, key?: string): ReactNode => {
return `No ${key?.replaceAll(/_/g, " ")}`;
}

return entries.map(([key, value]) => (
<div className="flex flex-col items-center gap-2 md:flex-row">
return entries.map(([key, value], idx) => (
<div key={idx} className="flex flex-col items-center gap-2 md:flex-row">
<span className="text-xs uppercase text-secondary-700">
{key.replaceAll(/_/g, " ")}
</span>
Expand All @@ -88,16 +88,19 @@ export default function GenericEvent(props: IProps) {
const { t } = useTranslation();
return (
<div className="flex w-full flex-col gap-4 rounded-lg border border-secondary-400 p-4 @container">
{Object.entries(props.values).map(([key, value]) => (
<div className="flex w-full flex-col items-start gap-2">
<span className="text-xs capitalize text-secondary-700">
{t(key).replaceAll(/_/g, " ")}
</span>
<span className="break-words text-sm font-semibold text-secondary-700">
{formatValue(value, key)}
</span>
</div>
))}
{Object.entries(props.values)
.map(([key, value]) => ({ key, value: formatValue(value, key) }))
.filter(({ value }) => value != null)
.map(({ key, value }) => (
<div key={key} className="flex w-full flex-col items-start gap-2">
<span className="text-xs capitalize text-secondary-700">
{t(key).replaceAll(/_/g, " ")}
</span>
<span className="break-words text-sm font-semibold text-secondary-700">
{value}
</span>
</div>
))}
</div>
);
}

0 comments on commit 7f51640

Please sign in to comment.