Skip to content

Commit

Permalink
fix: early filter for default knowledge without notes (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
mondaychen authored Apr 23, 2024
1 parent 7903a73 commit abfc501
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
9 changes: 7 additions & 2 deletions src/common/CustomKnowledgeBase/DefaultKnowledge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ import HostKnowledge from "./HostKnowledge";
const DefaultKnowledge = () => {
const { isOpen, onOpen, onClose } = useDisclosure();
const defaultKnowledgeBase = fetchAllDefaultKnowledge();

// some default knowledge may not have notes, filter them out
const hosts = Object.keys(defaultKnowledgeBase).filter((host) =>
defaultKnowledgeBase[host]?.rules?.some(
(rule) => (rule.knowledge?.notes?.length ?? 0) > 0,
),
);
return (
<>
<Button size="sm" variant="link" colorScheme="blue" onClick={onOpen}>
Expand All @@ -33,7 +38,7 @@ const DefaultKnowledge = () => {
<ModalHeader>Default Instructions</ModalHeader>
<ModalCloseButton />
<ModalBody>
{Object.keys(defaultKnowledgeBase).map((host) => (
{hosts.map((host) => (
<Box
key={host}
w="full"
Expand Down
7 changes: 0 additions & 7 deletions src/common/CustomKnowledgeBase/HostKnowledge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ const HostKnowledge = ({
if (rules === undefined) {
return null;
}
const hasNotes = rules.some(
(rule) => (rule.knowledge?.notes?.length ?? 0) > 0,
);
// skip if no notes
if (!hasNotes) {
return null;
}

const handleRemove = () => {
const newKnowledge = { ...knowledgeBase };
Expand Down

0 comments on commit abfc501

Please sign in to comment.