-
Notifications
You must be signed in to change notification settings - Fork 413
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
made a reusable component for table in routine and nursing care procedures #8608
Open
Sahil-Sinha-11
wants to merge
14
commits into
ohcnetwork:develop
Choose a base branch
from
Sahil-Sinha-11:issues/8562/Nursing_tab_ui
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+265
−222
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9cc2eb2
made a reusable component for table in routine and nursing care proce…
1b52b3c
Merge branch 'develop' into issues/8562/Nursing_tab_ui
nihal467 cd16e35
Merge branch 'develop' into issues/8562/Nursing_tab_ui
nihal467 38712fd
Merged NursingTab Section into ConsultationNursingTab
13bf013
resolved is_dysuria_block
c96bfcb
bug resolved for iinvalid date
414fcd6
Merge branch 'issues/8562/Nursing_tab_ui' of https://github.com/Sahil…
Sahil-Sinha-11 21fc805
Merge branch 'develop' into issues/8562/Nursing_tab_ui
Sahil-Sinha-11 1fe6f38
Merge branch 'ohcnetwork:develop' into issues/8562/Nursing_tab_ui
Sahil-Sinha-11 e82d0d0
Update src/Components/Facility/ConsultationDetails/ConsultationNursin…
Sahil-Sinha-11 aca95b7
fixed function names and tried to remove any from some parts
Sahil-Sinha-11 9b40784
Merge branch 'develop' into issues/8562/Nursing_tab_ui
Sahil-Sinha-11 6168b73
changes file name from sharedtable to LogAnalayseTable
Sahil-Sinha-11 665ad21
Merge branch 'develop' into issues/8562/Nursing_tab_ui
Sahil-Sinha-11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
src/Components/Facility/Consultations/LogUpdateAnalayseTable.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
import React from "react"; | ||
import { formatDate, formatTime } from "../../../Utils/utils"; | ||
import { classNames } from "../../../Utils/utils"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
interface SharedSectionTableProps { | ||
data: Record<string, any>; | ||
rows: Array<{ title?: string; field?: string; subField?: boolean }>; | ||
choices?: Record<string, Record<number | string, string>>; | ||
} | ||
|
||
const LogUpdateAnalayseTable: React.FC<SharedSectionTableProps> = ({ | ||
data, | ||
rows, | ||
choices = {}, | ||
}) => { | ||
const { t } = useTranslation(); | ||
|
||
// Helper function to get the display value | ||
const getDisplayValue = ( | ||
value: string | boolean | null | undefined, | ||
field?: string, | ||
): string => { | ||
if (value == null) { | ||
return " "; | ||
} | ||
|
||
if (typeof value === "boolean") { | ||
return t(value ? "yes" : "no"); | ||
} | ||
if (field && choices[field]) { | ||
const choice = | ||
choices[field][value as keyof (typeof choices)[typeof field]]; | ||
return choice ? t(`${field.toUpperCase()}__${choice}`) : "-"; | ||
} | ||
if (value && typeof value == "string") return value; | ||
|
||
return "-"; | ||
}; | ||
|
||
const isValidDate = (str: string) => { | ||
let ct = 0; | ||
for (let i = 0; i < str.length; i++) { | ||
if (str[i] == "/") ct++; | ||
} | ||
|
||
if (ct == 2) return true; | ||
return false; | ||
}; | ||
|
||
const dateConversion = (str: string) => { | ||
const time = str.split(";")[0].trim(); | ||
|
||
const date = str.split(";")[1].trim(); | ||
|
||
const dd = date.split("/")[0]; | ||
const mm = date.split("/")[1]; | ||
|
||
const yyyy = date.split("/")[2]; | ||
|
||
return time + ";" + mm + "/" + dd + "/" + yyyy; | ||
}; | ||
|
||
return ( | ||
<div className="m-2 w-full overflow-hidden overflow-x-auto rounded-lg border border-black shadow md:w-fit"> | ||
<table className="border-collapse rounded-lg border bg-secondary-100"> | ||
<thead className="sticky top-0 bg-white shadow"> | ||
<tr> | ||
<th className="sticky left-0 border-b-2 border-r-2 border-black bg-white"></th> | ||
{Object.keys(data).map((date) => ( | ||
<> | ||
<th | ||
key={date} | ||
className="w-40 border border-b-2 border-secondary-500 border-b-black p-1 text-sm font-semibold" | ||
> | ||
{/* DD/MM/YYYY -> MM/DD/YYYY */} | ||
<p> | ||
{isValidDate(date) | ||
? formatDate(dateConversion(date)) | ||
: formatDate(date)} | ||
</p> | ||
<p> | ||
{isValidDate(date) | ||
? formatTime(dateConversion(date)) | ||
: formatTime(date)} | ||
</p> | ||
</th> | ||
</> | ||
))} | ||
</tr> | ||
</thead> | ||
<tbody className="bg-secondary-200"> | ||
{rows.map((row) => ( | ||
<tr | ||
key={row.field ?? row.title} | ||
className={classNames( | ||
row.title && "border-t-2 border-t-secondary-600", | ||
)} | ||
> | ||
<th | ||
className={classNames( | ||
"sticky left-0 border border-r-2 border-secondary-500 border-r-black bg-white p-2", | ||
row.subField ? "pl-4 font-medium" : "font-bold", | ||
)} | ||
> | ||
{row.title ?? t(`LOG_UPDATE_FIELD_LABEL__${row.field!}`)} | ||
</th> | ||
{Object.values(data).map((obj, idx) => { | ||
const value = obj[row.field!]; | ||
return ( | ||
<td | ||
key={`${row.field}-${idx}`} | ||
className="w-80 border border-l-2 border-secondary-500 bg-secondary-100 p-2 text-center font-medium" | ||
> | ||
{getDisplayValue(value, row.field)} | ||
</td> | ||
); | ||
})} | ||
</tr> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
); | ||
}; | ||
|
||
export default LogUpdateAnalayseTable; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try to avoid any as much as possible, please add a valid type here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Sahil-Sinha-11 the changes look good, just this, can you please replace this
any
with respective type