-
Notifications
You must be signed in to change notification settings - Fork 0
feat: display ai match ui (#746) #749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0bc25c1
feat: display ai match ui (#746)
frano-m 0fbf95e
feat: added ai match ui tests (#746)
frano-m 38e2d38
Update src/components/Filter/components/ai/components/FacetAssistant/…
frano-m 9251e7c
fix: measured width hook clarity (#746)
frano-m 21d0dc1
feat: unmatched matched wording (#746)
frano-m c89c683
feat: added alert colour to svg icon (#746)
frano-m File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
33 changes: 33 additions & 0 deletions
33
...nts/FacetAssistant/components/ResultSummary/components/Tooltip/components/Title/title.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { Stack, Typography } from "@mui/material"; | ||
| import React from "react"; | ||
| import { STACK_PROPS } from "../../../../../../../../../../../../styles/common/mui/stack"; | ||
| import { TYPOGRAPHY_PROPS } from "../../../../../../../../../../../../styles/common/mui/typography"; | ||
| import { ResultSummarySectionProps } from "./types"; | ||
|
|
||
| export const ResultSummarySection = ({ | ||
| icon, | ||
| mentionTermPair, | ||
| title, | ||
| }: ResultSummarySectionProps): JSX.Element | null => { | ||
| if (mentionTermPair.length === 0) return null; | ||
| return ( | ||
| <Stack gap={2} useFlexGap> | ||
| <Typography variant={TYPOGRAPHY_PROPS.VARIANT.BODY_500}> | ||
| {title} | ||
| </Typography> | ||
| {mentionTermPair.map(([mention, term]) => ( | ||
| <Stack | ||
| key={`${mention}-${term}`} | ||
| direction={STACK_PROPS.DIRECTION.ROW} | ||
| spacing={1} | ||
| useFlexGap | ||
| > | ||
| {icon} | ||
| <span>{mention}</span> | ||
| <Typography color={TYPOGRAPHY_PROPS.COLOR.INK_LIGHT}>=</Typography> | ||
| <span>{term}</span> | ||
| </Stack> | ||
| ))} | ||
| </Stack> | ||
| ); | ||
| }; | ||
8 changes: 8 additions & 0 deletions
8
...ents/FacetAssistant/components/ResultSummary/components/Tooltip/components/Title/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import { ReactNode } from "react"; | ||
| import { MentionTermPair } from "../../../../types"; | ||
|
|
||
| export interface ResultSummarySectionProps { | ||
| icon: ReactNode; | ||
| mentionTermPair: MentionTermPair[]; | ||
| title: string; | ||
| } |
29 changes: 29 additions & 0 deletions
29
...nts/ai/components/FacetAssistant/components/ResultSummary/components/Tooltip/constants.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { TooltipProps } from "@mui/material"; | ||
| import { FONT } from "../../../../../../../../../../styles/common/constants/font"; | ||
| import { PALETTE } from "../../../../../../../../../../styles/common/constants/palette"; | ||
|
|
||
| export const TOOLTIP_PROPS: Omit<TooltipProps, "children" | "title"> = { | ||
| disableInteractive: true, | ||
| enterNextDelay: 250, | ||
| placement: "top-start", | ||
| slotProps: { | ||
| popper: { | ||
| modifiers: [ | ||
| { name: "flip", options: { padding: 8 } }, | ||
| { name: "offset", options: { offset: [0, 2] } }, | ||
| { name: "preventOverflow", options: { padding: 8 } }, | ||
| ], | ||
| }, | ||
| tooltip: { | ||
| sx: { | ||
| backgroundColor: PALETTE.COMMON_WHITE, | ||
| border: `1px solid ${PALETTE.SMOKE_DARK}`, | ||
| color: PALETTE.INK_MAIN, | ||
| font: FONT.BODY_400, | ||
| margin: 0, | ||
| maxWidth: "unset", | ||
| padding: 4, | ||
| }, | ||
frano-m marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| }; | ||
frano-m marked this conversation as resolved.
Show resolved
Hide resolved
|
||
23 changes: 23 additions & 0 deletions
23
...mponents/ai/components/FacetAssistant/components/ResultSummary/components/Tooltip/hook.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { useCallback, useState } from "react"; | ||
|
|
||
| /** | ||
| * Hook to measure the width of an element and provide a ref to attach to it. | ||
| * Returns the measured width and a ref function to attach to the element. | ||
| * @returns A tuple containing the measured width and a ref function to attach to the element. | ||
| */ | ||
| export function useMeasuredWidth<T extends HTMLElement>(): [ | ||
| number | undefined, | ||
| (node: T | null) => void | ||
| ] { | ||
| const [width, setWidth] = useState<number>(); | ||
|
|
||
| const ref = useCallback((node: T | null) => { | ||
| if (!node) return; | ||
|
|
||
| const { width } = node.getBoundingClientRect(); | ||
|
|
||
| setWidth(width); | ||
frano-m marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, []); | ||
|
|
||
| return [width, ref]; | ||
| } | ||
21 changes: 21 additions & 0 deletions
21
...ents/ai/components/FacetAssistant/components/ResultSummary/components/Tooltip/tooltip.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import { Tooltip as MTooltip } from "@mui/material"; | ||
| import React from "react"; | ||
| import { TOOLTIP_PROPS } from "./constants"; | ||
| import { useMeasuredWidth } from "./hook"; | ||
| import { TooltipProps } from "./types"; | ||
|
|
||
| export const Tooltip = ({ children, ...props }: TooltipProps): JSX.Element => { | ||
| const [minWidth = "unset", ref] = useMeasuredWidth<HTMLSpanElement>(); | ||
| return ( | ||
| <MTooltip | ||
| {...TOOLTIP_PROPS} | ||
| slotProps={{ | ||
| ...TOOLTIP_PROPS.slotProps, | ||
| popper: { sx: { minWidth } }, | ||
| }} | ||
| {...props} | ||
| > | ||
| {children(ref)} | ||
| </MTooltip> | ||
| ); | ||
| }; |
6 changes: 6 additions & 0 deletions
6
...ponents/ai/components/FacetAssistant/components/ResultSummary/components/Tooltip/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { TooltipProps as MTooltipProps } from "@mui/material"; | ||
| import { ReactElement } from "react"; | ||
|
|
||
| export interface TooltipProps extends Omit<MTooltipProps, "children"> { | ||
| children: (ref: (node: HTMLSpanElement | null) => void) => ReactElement; | ||
| } |
11 changes: 11 additions & 0 deletions
11
.../components/ai/components/FacetAssistant/components/ResultSummary/resultSummary.styles.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import styled from "@emotion/styled"; | ||
| import { Typography } from "@mui/material"; | ||
| import { PALETTE } from "../../../../../../../../styles/common/constants/palette"; | ||
|
|
||
| export const StyledResultSummary = styled(Typography)` | ||
| cursor: pointer; | ||
| text-decoration: underline dashed ${PALETTE.SMOKE_DARK}; | ||
| text-decoration-skip-ink: none; | ||
| text-decoration-thickness: 1px; | ||
| text-underline-position: under; | ||
| `; |
44 changes: 44 additions & 0 deletions
44
...Filter/components/ai/components/FacetAssistant/components/ResultSummary/resultSummary.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { Stack } from "@mui/material"; | ||
| import React from "react"; | ||
| import { SVG_ICON_PROPS } from "../../../../../../../../styles/common/mui/svgIcon"; | ||
| import { TYPOGRAPHY_PROPS } from "../../../../../../../../styles/common/mui/typography"; | ||
| import { ErrorIcon } from "../../../../../../../common/CustomIcon/components/ErrorIcon/errorIcon"; | ||
| import { SuccessIcon } from "../../../../../../../common/CustomIcon/components/SuccessIcon/successIcon"; | ||
| import { ResultSummarySection } from "./components/Tooltip/components/Title/title"; | ||
| import { Tooltip } from "./components/Tooltip/tooltip"; | ||
| import { StyledResultSummary } from "./resultSummary.styles"; | ||
| import { ResultSummaryProps } from "./types"; | ||
| import { renderSummary } from "./utils"; | ||
|
|
||
| export const ResultSummary = ({ | ||
| summary, | ||
| }: ResultSummaryProps): JSX.Element | null => { | ||
| if (!summary) return null; | ||
| return ( | ||
| <Tooltip | ||
| title={ | ||
| <Stack gap={4} useFlexGap> | ||
| <ResultSummarySection | ||
| icon={<SuccessIcon color={SVG_ICON_PROPS.COLOR.SUCCESS} />} | ||
| mentionTermPair={summary.matched} | ||
| title="Matches" | ||
| /> | ||
| <ResultSummarySection | ||
| icon={<ErrorIcon color={SVG_ICON_PROPS.COLOR.ERROR} />} | ||
| mentionTermPair={summary.unmatched} | ||
| title="No matches" | ||
| /> | ||
| </Stack> | ||
| } | ||
| > | ||
| {(ref) => ( | ||
| <StyledResultSummary | ||
| ref={ref} | ||
| variant={TYPOGRAPHY_PROPS.VARIANT.BODY_400} | ||
| > | ||
| {renderSummary(summary)} | ||
| </StyledResultSummary> | ||
| )} | ||
| </Tooltip> | ||
| ); | ||
| }; |
10 changes: 10 additions & 0 deletions
10
...mponents/Filter/components/ai/components/FacetAssistant/components/ResultSummary/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| export type MentionTermPair = [mention: string, term: string]; | ||
|
|
||
| export type ResultSummaryData = { | ||
| matched: MentionTermPair[]; | ||
| unmatched: MentionTermPair[]; | ||
| }; | ||
|
|
||
| export interface ResultSummaryProps { | ||
| summary?: ResultSummaryData; | ||
| } |
35 changes: 35 additions & 0 deletions
35
...mponents/Filter/components/ai/components/FacetAssistant/components/ResultSummary/utils.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import type { ResultSummaryData } from "./types"; | ||
|
|
||
| /** | ||
| * Returns the appropriate noun ("match" or "matches") based on the count. | ||
| * @param count - The number of matches. | ||
| * @returns The singular or plural form of "match". | ||
| */ | ||
| function getMatchNoun(count: number): string { | ||
| return count === 1 ? "match" : "matches"; | ||
| } | ||
|
|
||
| /** | ||
| * Renders a human-readable summary from the result summary data. | ||
| * @param summary - The result summary data. | ||
| * @returns A formatted string summarizing the matched and unmatched items. | ||
| */ | ||
| export function renderSummary(summary: ResultSummaryData): string { | ||
| const matched = summary.matched.length; | ||
| const unmatched = summary.unmatched.length; | ||
|
|
||
| if (!unmatched) { | ||
| // If there are no unmatched items, just report the matched count. | ||
| return `AI found ${matched} ${getMatchNoun(matched)}`; | ||
| } | ||
|
|
||
| if (!matched) { | ||
| // If there are no matched items, report only unmatched count. | ||
| return `AI found ${unmatched} with no match`; | ||
| } | ||
|
|
||
| // Otherwise, report both matched and unmatched counts. | ||
| return `AI found ${matched} ${getMatchNoun( | ||
| matched | ||
| )} and ${unmatched} with no match`; | ||
| } |
5 changes: 3 additions & 2 deletions
5
src/components/Filter/components/ai/components/FacetAssistant/facetAssistant.styles.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.