Skip to content

Commit

Permalink
hide sources for empty data
Browse files Browse the repository at this point in the history
  • Loading branch information
anish-work committed Dec 5, 2024
1 parent 60251e1 commit 58a57f9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/widgets/copilot/components/Messages/IncomingMsg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ const IncomingMsg = memo(
const audioTrack = output_audio[0];
const videoTrack = output_video[0];
const isStreaming = type !== STREAM_MESSAGE_TYPES.FINAL_RESPONSE;

// Parse the response text and format it - customised links, sources, etc.
const parsedElements = formatTextResponse(
props.data,
props?.linkColor,
Expand Down
13 changes: 7 additions & 6 deletions src/widgets/copilot/components/Messages/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export const getReactParserOptions = (data: any): HTMLReactParserOptions => ({
},
transform(reactNode, domNode) {
if (domNode.type === "text" && data.showSources) {
return customizedReferences(reactNode, domNode, data);
return customizedSources(reactNode, domNode, data);
}
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
Expand Down Expand Up @@ -228,7 +228,7 @@ const customizedLinks = (reactNode: any, domNode: any, data: any) => {
);
};

const customizedReferences = (reactNode: any, domNode: any, data: any) => {
const customizedSources = (reactNode: any, domNode: any, data: any) => {
if (!domNode) return domNode;
let text = domNode.data || "";

Expand Down Expand Up @@ -259,10 +259,11 @@ const customizedReferences = (reactNode: any, domNode: any, data: any) => {
return (
<React.Fragment>
{text}{" "}
<CollapsibleButton disabled={!references.length}>
<Sources data={sources} />
</CollapsibleButton>
<br />
{!!references.length && (
<CollapsibleButton>
<Sources data={sources} />
</CollapsibleButton>
)}
</React.Fragment>
);
};
Expand Down

0 comments on commit 58a57f9

Please sign in to comment.