Skip to content

Commit

Permalink
fix: skip knowledge display if no notes
Browse files Browse the repository at this point in the history
  • Loading branch information
mondaychen committed Apr 22, 2024
1 parent bf25d2b commit af01223
Showing 1 changed file with 39 additions and 15 deletions.
54 changes: 39 additions & 15 deletions src/common/CustomKnowledgeBase/HostKnowledge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ const HostKnowledge = ({
? fetchAllDefaultKnowledge()
: customKnowledgeBase;

if (knowledgeBase[host] === undefined) {
return null;
}
if (knowledgeBase[host].rules === undefined) {
return null;
}
const hasNotes = knowledgeBase[host].rules.some(
(rule) => (rule.knowledge?.notes?.length ?? 0) > 0,
);
// skip if no notes
if (!hasNotes) {
return null;
}

const handleRemove = () => {
const newKnowledge = { ...knowledgeBase };
delete newKnowledge[host];
Expand Down Expand Up @@ -109,21 +123,31 @@ const HostKnowledge = ({
</Heading>
</Flex>
<Accordion allowToggle>
{knowledgeBase[host].rules?.map((rule, ruleIndex) => (
<AccordionItem key={ruleIndex} backgroundColor="white">
<h2>
<AccordionButton>
<Box flex="1" textAlign="left">
Instructions Set {ruleIndex + 1}
</Box>
<AccordionIcon />
</AccordionButton>
</h2>
<AccordionPanel pb={4}>
<Notes notes={rule.knowledge.notes} />
</AccordionPanel>
</AccordionItem>
))}
{knowledgeBase[host].rules.map((rule, ruleIndex) => {
// Skip rules without notes
if (
rule.knowledge === undefined ||
rule.knowledge.notes === undefined ||
rule.knowledge.notes.length === 0
) {
return null;
}
return (
<AccordionItem key={ruleIndex} backgroundColor="white">
<h2>
<AccordionButton>
<Box flex="1" textAlign="left">
Instructions Set {ruleIndex + 1}
</Box>
<AccordionIcon />
</AccordionButton>
</h2>
<AccordionPanel pb={4}>
<Notes notes={rule.knowledge.notes} />
</AccordionPanel>
</AccordionItem>
);
})}
</Accordion>
</>
);
Expand Down

0 comments on commit af01223

Please sign in to comment.