Skip to content

Commit

Permalink
Do not show templates and slot modal if app metadata is not part of s…
Browse files Browse the repository at this point in the history
…erver data
  • Loading branch information
pkalita-lbl committed Dec 10, 2024
1 parent f7879b1 commit c411e9b
Showing 1 changed file with 38 additions and 28 deletions.
66 changes: 38 additions & 28 deletions src/components/StudyView/StudyView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ const StudyView: React.FC<StudyViewProps> = ({ submissionId }) => {
const templateVisibleSlots = useMemo(() => {
const fieldVisibilityInfo: TemplateVisibleSlots[] = [];
if (submission.data) {
if (!("field_notes_metadata" in submission.data)) {
return undefined;
}
const templates = getSubmissionTemplates(submission.data);
templates.forEach((templateName) => {
const template = TEMPLATES[templateName];
Expand All @@ -71,7 +74,10 @@ const StudyView: React.FC<StudyViewProps> = ({ submissionId }) => {
// them has no visible slot information (this could be because it is a brand-new study or
// because it was created via the submission portal and this is the first time opening it in the
// app), open the slot selector for that template.
if (modalTemplateVisibleSlots !== undefined) {
if (
modalTemplateVisibleSlots !== undefined ||
templateVisibleSlots === undefined
) {
return;
}
for (const item of templateVisibleSlots) {
Expand Down Expand Up @@ -227,33 +233,37 @@ const StudyView: React.FC<StudyViewProps> = ({ submissionId }) => {
</IonItem>
</IonList>

<SectionHeader>Templates</SectionHeader>
<IonList className="ion-padding-bottom">
{templateVisibleSlots.map((item) => (
<IonItem
key={item.template}
onClick={() => setModalTemplateVisibleSlots(item)}
>
<IonLabel>
<h3>{item.templateDisplay}</h3>
<p>
{item.visibleSlots === undefined ? (
"Not customized"
) : (
<>
<Pluralize
count={item.visibleSlots.length}
singular={"field"}
showCount
/>{" "}
selected
</>
)}
</p>
</IonLabel>
</IonItem>
))}
</IonList>
{templateVisibleSlots !== undefined && (
<>
<SectionHeader>Templates</SectionHeader>
<IonList className="ion-padding-bottom">
{templateVisibleSlots.map((item) => (
<IonItem
key={item.template}
onClick={() => setModalTemplateVisibleSlots(item)}
>
<IonLabel>
<h3>{item.templateDisplay}</h3>
<p>
{item.visibleSlots === undefined ? (
"Not customized"
) : (
<>
<Pluralize
count={item.visibleSlots.length}
singular={"field"}
showCount
/>{" "}
selected
</>
)}
</p>
</IonLabel>
</IonItem>
))}
</IonList>
</>
)}

<SampleList
submission={submission.data}
Expand Down

0 comments on commit c411e9b

Please sign in to comment.