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

+55
-16
lines changed

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)
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
))}

packages/component/src/LinkDefinition/LinkDefinitionItem.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,22 @@ import ItemBody from './private/ItemBody';
55
import extractHostnameWithSubdomain from './private/extractHostnameWithSubdomain';
66

77
type Props = Readonly<{
8-
badgeName?: string;
9-
badgeTitle?: string;
8+
// The text (usually a number) displayed to the left of the item (e.g. "1")
109
identifier?: string;
11-
onClick?: (event: Pick<CustomEvent, 'defaultPrevented' | 'preventDefault' | 'type'>) => void;
10+
11+
// The main text of the citation. This will be formatted as if it were a link. If this is nullish and a URL exists, its host will be displayed instead.
1212
text?: string;
13+
14+
// Displayed beneath the main link of the citation if it exists
15+
badgeName?: string;
16+
17+
// Used as a tooltip and ARIA label for the item's displayed badgeName
18+
badgeTitle?: string;
19+
20+
// If the citation is an external link, this is its destination.
1321
url?: string;
22+
23+
onClick?: (event: Pick<CustomEvent, 'defaultPrevented' | 'preventDefault' | 'type'>) => void;
1424
}>;
1525

1626
const LinkDefinitionItem = memo(({ badgeName, badgeTitle, identifier, onClick, text, url }: Props) => {

packages/component/src/LinkDefinition/private/ItemBody.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,20 @@ import Badge from './Badge';
44
import OpenInNewWindowIcon from './OpenInNewWindowIcon';
55

66
type Props = Readonly<{
7-
badgeName?: string;
8-
badgeTitle?: string;
7+
// The text (usually a number) displayed at the head of the citation
98
identifier?: string;
10-
isExternal?: boolean;
9+
10+
// The text displayed as the main link of the citation
1111
text: string;
12+
13+
// If this is true, we show the "external link" icon after the link
14+
isExternal?: boolean;
15+
16+
// The text displayed beneath the link as a description
17+
badgeName?: string;
18+
19+
// The title of the badge, displayed as a tooltip on the item's description as well as the description's screen-reader content
20+
badgeTitle?: string;
1221
}>;
1322

1423
const ItemBody = memo(({ badgeName, badgeTitle, identifier, isExternal, text }: Props) => (

0 commit comments

Comments
 (0)