Skip to content

Commit

Permalink
proritize given citation names as titles (#5215)
Browse files Browse the repository at this point in the history
* proritize given citation names as titles

* update changelog

* add unit test for name

* make unit tests pass

---------

Co-authored-by: Benjamin Yackley <[email protected]>
  • Loading branch information
beyackle2 and beyackle authored Jun 25, 2024
1 parent 6c3063d commit 336dd7c
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Notes: web developers are advised to use [`~` (tilde range)](https://github.com/

### Fixed

- 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)
- Improved performance for `useActivityWithRenderer`, in PR [#5172](https://github.com/microsoft/BotFramework-WebChat/pull/5172), by [@OEvgeny](https://github.com/OEvgeny)
- 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)
- 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)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion __tests__/html/citation.basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'@context': 'https://schema.org',
'@id': 'cite:1',
'@type': 'Claim',
name: 'Should Be Visible',
type: 'https://schema.org/Claim',
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/).'
}
Expand All @@ -36,7 +37,7 @@
[1]: https://support.microsoft.com/en-us/windows/use-a-proxy-server-in-windows-03096c53-0554-4ffe-b6ab-8b1deee8dae1
[2]: https://learn.microsoft.com/en-us/troubleshoot/windows-server/networking/configure-proxy-server-settings "Configure proxy server settings - Windows Server"
[3]: cite:1 "Citation-1"
[3]: cite:1 "should be hidden"
`,
type: 'message'
});
Expand Down Expand Up @@ -71,6 +72,9 @@
);

expect(linkDefinitionItems[2].tagName).toBe('BUTTON');

expect(linkDefinitionItems[2].innerHTML).toContain('Should Be Visible');
expect(linkDefinitionItems[2].innerHTML).not.toContain('should be hidden');
});
</script>
</body>
Expand Down
3 changes: 2 additions & 1 deletion __tests__/html/citation.showModal.linkDefinitions.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'@context': 'https://schema.org',
'@id': 'cite:1',
'@type': 'Claim',
name: "Should Be Visible",
type: 'https://schema.org/Claim',
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/).'
}
Expand All @@ -36,7 +37,7 @@
[1]: https://support.microsoft.com/en-us/windows/use-a-proxy-server-in-windows-03096c53-0554-4ffe-b6ab-8b1deee8dae1
[2]: https://learn.microsoft.com/en-us/troubleshoot/windows-server/networking/configure-proxy-server-settings "Configure proxy server settings - Windows Server"
[3]: cite:1 "Citation-1"
[3]: cite:1 "should be hidden"
`,
type: 'message'
});
Expand Down
3 changes: 2 additions & 1 deletion __tests__/html/citation.showModal.markdown.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
'@context': 'https://schema.org',
'@id': 'cite:1',
'@type': 'Claim',
name: "Should Be Visible",
type: 'https://schema.org/Claim',
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/).'
}
Expand All @@ -36,7 +37,7 @@
[1]: https://support.microsoft.com/en-us/windows/use-a-proxy-server-in-windows-03096c53-0554-4ffe-b6ab-8b1deee8dae1
[2]: https://learn.microsoft.com/en-us/troubleshoot/windows-server/networking/configure-proxy-server-settings "Configure proxy server settings - Windows Server"
[3]: cite:1 "Citation-1"
[3]: cite:1 "should be hidden"
`,
type: 'message'
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ const MarkdownTextContent = memo(({ activity, markdown }: Props) => {
messageCitation?.appearance && !messageCitation.appearance.url
? () =>
showClaimModal(
markdownDefinition.title,
messageCitation.appearance.name ?? markdownDefinition.title,
messageCitation.appearance.text,
messageCitation.alternateName
)
Expand All @@ -118,7 +118,12 @@ const MarkdownTextContent = memo(({ activity, markdown }: Props) => {
claim: rootLevelClaim,
key: markdownDefinition.url,
handleClick: isCitationURL(rootLevelClaim['@id'])
? () => showClaimModal(markdownDefinition.title, rootLevelClaim.text, rootLevelClaim.alternateName)
? () =>
showClaimModal(
rootLevelClaim.name ?? markdownDefinition.title,
rootLevelClaim.text,
rootLevelClaim.alternateName
)
: undefined,
markdownDefinition
};
Expand Down Expand Up @@ -180,6 +185,16 @@ const MarkdownTextContent = memo(({ activity, markdown }: Props) => {
}
}, [messageThing]);

// 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.
const getEntryMainText = (entry: Entry) =>
entry.claim?.name ?? entry.claim?.appearance?.name ?? entry.markdownDefinition.title;

// Optional alternate name for the entry, used as a subtitle beneath the link
const getEntryBadgeName = (entry: Entry) => entry.claim?.appearance?.usageInfo?.name;

// Secondary text describing the citation, used in the a11y description (i.e. the div's title attribute)
const getEntryDescription = (entry: Entry) => entry.claim?.appearance?.usageInfo?.description;

return (
<div
className={classNames('webchat__text-content', 'webchat__text-content--is-markdown', textContentStyleSet + '')}
Expand All @@ -197,14 +212,12 @@ const MarkdownTextContent = memo(({ activity, markdown }: Props) => {
>
{entries.map(entry => (
<LinkDefinitionItem
badgeName={entry.claim?.appearance?.usageInfo?.name}
badgeTitle={[entry.claim?.appearance?.usageInfo?.name, entry.claim?.appearance?.usageInfo?.description]
.filter(Boolean)
.join('\n\n')}
badgeName={getEntryBadgeName(entry)}
badgeTitle={`${getEntryBadgeName(entry) ?? ''}\n\n${getEntryDescription(entry) ?? ''}`.trim()}
identifier={entry.markdownDefinition.label}
key={entry.key}
onClick={entry.handleClick}
text={entry.markdownDefinition.title}
text={getEntryMainText(entry)}
url={entry.url}
/>
))}
Expand Down
16 changes: 13 additions & 3 deletions packages/component/src/LinkDefinition/LinkDefinitionItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,22 @@ import ItemBody from './private/ItemBody';
import extractHostnameWithSubdomain from './private/extractHostnameWithSubdomain';

type Props = Readonly<{
badgeName?: string;
badgeTitle?: string;
// The text (usually a number) displayed to the left of the item (e.g. "1")
identifier?: string;
onClick?: (event: Pick<CustomEvent, 'defaultPrevented' | 'preventDefault' | 'type'>) => void;

// 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.
text?: string;

// Displayed beneath the main link of the citation if it exists
badgeName?: string;

// Used as a tooltip and ARIA label for the item's displayed badgeName
badgeTitle?: string;

// If the citation is an external link, this is its destination.
url?: string;

onClick?: (event: Pick<CustomEvent, 'defaultPrevented' | 'preventDefault' | 'type'>) => void;
}>;

const LinkDefinitionItem = memo(({ badgeName, badgeTitle, identifier, onClick, text, url }: Props) => {
Expand Down
15 changes: 12 additions & 3 deletions packages/component/src/LinkDefinition/private/ItemBody.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,20 @@ import Badge from './Badge';
import OpenInNewWindowIcon from './OpenInNewWindowIcon';

type Props = Readonly<{
badgeName?: string;
badgeTitle?: string;
// The text (usually a number) displayed at the head of the citation
identifier?: string;
isExternal?: boolean;

// The text displayed as the main link of the citation
text: string;

// If this is true, we show the "external link" icon after the link
isExternal?: boolean;

// The text displayed beneath the link as a description
badgeName?: string;

// The title of the badge, displayed as a tooltip on the item's description as well as the description's screen-reader content
badgeTitle?: string;
}>;

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

0 comments on commit 336dd7c

Please sign in to comment.