Skip to content

Commit 336dd7c

Browse files
beyackle2beyackle
andauthored
proritize given citation names as titles (#5215)
* proritize given citation names as titles * update changelog * add unit test for name * make unit tests pass --------- Co-authored-by: Benjamin Yackley <beyackle@microsoft.com>
1 parent 6c3063d commit 336dd7c

12 files changed

Lines changed: 55 additions & 16 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Notes: web developers are advised to use [`~` (tilde range)](https://github.com/
3232

3333
### Fixed
3434

35+
- Read deeper into citation objects in order to provide names, in PR [#5215](https://github.com/microsoft/BotFramework-WebChat/pull/5215), by [@beyackle2](https://github.com/beyackle2)
3536
- Improved performance for `useActivityWithRenderer`, in PR [#5172](https://github.com/microsoft/BotFramework-WebChat/pull/5172), by [@OEvgeny](https://github.com/OEvgeny)
3637
- Fixes [#5162](https://github.com/microsoft/BotFramework-WebChat/issues/5162). Improved performance for `useActivityTreeWithRenderer`, in PR [#5163](https://github.com/microsoft/BotFramework-WebChat/pull/5163), by [@compulim](https://github.com/compulim)
3738
- Fixes [#5175](https://github.com/microsoft/BotFramework-WebChat/issues/5175). `PrecompiledGlobalize.js` is emitted instead of `.cjs`, by [@compulim](https://github.com/compulim) in PR [#5181](https://github.com/microsoft/BotFramework-WebChat/pull/5181)
1.08 KB
Loading
Loading
Loading
Loading
Loading

__tests__/html/citation.basic.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
'@context': 'https://schema.org',
2929
'@id': 'cite:1',
3030
'@type': 'Claim',
31+
name: 'Should Be Visible',
3132
type: 'https://schema.org/Claim',
3233
text: 'Reprehenderit exercitation laborum labore ut. Nostrud do et ut nostrud nisi excepteur labore adipisicing nostrud nostrud ipsum id dolore. Anim aliquip incididunt incididunt sunt sit proident consectetur exercitation qui aliqua aliquip adipisicing nisi et. Id commodo labore sunt quis do aute cillum laborum veniam [proident](https://bing.com/).'
3334
}
@@ -36,7 +37,7 @@
3637
3738
[1]: https://support.microsoft.com/en-us/windows/use-a-proxy-server-in-windows-03096c53-0554-4ffe-b6ab-8b1deee8dae1
3839
[2]: https://learn.microsoft.com/en-us/troubleshoot/windows-server/networking/configure-proxy-server-settings "Configure proxy server settings - Windows Server"
39-
[3]: cite:1 "Citation-1"
40+
[3]: cite:1 "should be hidden"
4041
`,
4142
type: 'message'
4243
});
@@ -71,6 +72,9 @@
7172
);
7273

7374
expect(linkDefinitionItems[2].tagName).toBe('BUTTON');
75+
76+
expect(linkDefinitionItems[2].innerHTML).toContain('Should Be Visible');
77+
expect(linkDefinitionItems[2].innerHTML).not.toContain('should be hidden');
7478
});
7579
</script>
7680
</body>

__tests__/html/citation.showModal.linkDefinitions.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
'@context': 'https://schema.org',
2929
'@id': 'cite:1',
3030
'@type': 'Claim',
31+
name: "Should Be Visible",
3132
type: 'https://schema.org/Claim',
3233
text: 'Reprehenderit exercitation laborum labore ut. Nostrud do et ut nostrud nisi excepteur labore adipisicing nostrud nostrud ipsum id dolore. Anim aliquip incididunt incididunt sunt sit proident consectetur exercitation qui aliqua aliquip adipisicing nisi et. Id commodo labore sunt quis do aute cillum laborum veniam [proident](https://bing.com/).'
3334
}
@@ -36,7 +37,7 @@
3637
3738
[1]: https://support.microsoft.com/en-us/windows/use-a-proxy-server-in-windows-03096c53-0554-4ffe-b6ab-8b1deee8dae1
3839
[2]: https://learn.microsoft.com/en-us/troubleshoot/windows-server/networking/configure-proxy-server-settings "Configure proxy server settings - Windows Server"
39-
[3]: cite:1 "Citation-1"
40+
[3]: cite:1 "should be hidden"
4041
`,
4142
type: 'message'
4243
});

__tests__/html/citation.showModal.markdown.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
'@context': 'https://schema.org',
2929
'@id': 'cite:1',
3030
'@type': 'Claim',
31+
name: "Should Be Visible",
3132
type: 'https://schema.org/Claim',
3233
text: 'Reprehenderit exercitation laborum labore ut. Nostrud do et ut nostrud nisi excepteur labore adipisicing nostrud nostrud ipsum id dolore. Anim aliquip incididunt incididunt sunt sit proident consectetur exercitation qui aliqua aliquip adipisicing nisi et. Id commodo labore sunt quis do aute cillum laborum veniam [proident](https://bing.com/).'
3334
}
@@ -36,7 +37,7 @@
3637
3738
[1]: https://support.microsoft.com/en-us/windows/use-a-proxy-server-in-windows-03096c53-0554-4ffe-b6ab-8b1deee8dae1
3839
[2]: https://learn.microsoft.com/en-us/troubleshoot/windows-server/networking/configure-proxy-server-settings "Configure proxy server settings - Windows Server"
39-
[3]: cite:1 "Citation-1"
40+
[3]: cite:1 "should be hidden"
4041
`,
4142
type: 'message'
4243
});

packages/component/src/Attachment/Text/private/MarkdownTextContent.tsx

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const MarkdownTextContent = memo(({ activity, markdown }: Props) => {
9898
messageCitation?.appearance && !messageCitation.appearance.url
9999
? () =>
100100
showClaimModal(
101-
markdownDefinition.title,
101+
messageCitation.appearance.name ?? markdownDefinition.title,
102102
messageCitation.appearance.text,
103103
messageCitation.alternateName
104104
)
@@ -118,7 +118,12 @@ const MarkdownTextContent = memo(({ activity, markdown }: Props) => {
118118
claim: rootLevelClaim,
119119
key: markdownDefinition.url,
120120
handleClick: isCitationURL(rootLevelClaim['@id'])
121-
? () => showClaimModal(markdownDefinition.title, rootLevelClaim.text, rootLevelClaim.alternateName)
121+
? () =>
122+
showClaimModal(
123+
rootLevelClaim.name ?? markdownDefinition.title,
124+
rootLevelClaim.text,
125+
rootLevelClaim.alternateName
126+
)
122127
: undefined,
123128
markdownDefinition
124129
};
@@ -180,6 +185,16 @@ const MarkdownTextContent = memo(({ activity, markdown }: Props) => {
180185
}
181186
}, [messageThing]);
182187

188+
// The main text of the citation entry (e.g. the title of the document). Used as the content of the main link and, if it exists, the header of the popup window.
189+
const getEntryMainText = (entry: Entry) =>
190+
entry.claim?.name ?? entry.claim?.appearance?.name ?? entry.markdownDefinition.title;
191+
192+
// Optional alternate name for the entry, used as a subtitle beneath the link
193+
const getEntryBadgeName = (entry: Entry) => entry.claim?.appearance?.usageInfo?.name;
194+
195+
// Secondary text describing the citation, used in the a11y description (i.e. the div's title attribute)
196+
const getEntryDescription = (entry: Entry) => entry.claim?.appearance?.usageInfo?.description;
197+
183198
return (
184199
<div
185200
className={classNames('webchat__text-content', 'webchat__text-content--is-markdown', textContentStyleSet + '')}
@@ -197,14 +212,12 @@ const MarkdownTextContent = memo(({ activity, markdown }: Props) => {
197212
>
198213
{entries.map(entry => (
199214
<LinkDefinitionItem
200-
badgeName={entry.claim?.appearance?.usageInfo?.name}
201-
badgeTitle={[entry.claim?.appearance?.usageInfo?.name, entry.claim?.appearance?.usageInfo?.description]
202-
.filter(Boolean)
203-
.join('\n\n')}
215+
badgeName={getEntryBadgeName(entry)}
216+
badgeTitle={`${getEntryBadgeName(entry) ?? ''}\n\n${getEntryDescription(entry) ?? ''}`.trim()}
204217
identifier={entry.markdownDefinition.label}
205218
key={entry.key}
206219
onClick={entry.handleClick}
207-
text={entry.markdownDefinition.title}
220+
text={getEntryMainText(entry)}
208221
url={entry.url}
209222
/>
210223
))}

0 commit comments

Comments
 (0)