-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(builder): add fuzzy match functions (#421)
* feat(models): add fuzzy match functions (#414) * feat(builder): add fuzzy match functions edit (#415) * feat(builder): add fuzzy match functions edit * feat(builder): handle fuzzy match any of * feat(data-type): handle list of data types * feat(fuzzy-match): edit threshold (#419) * feat(fuzzy-match): add doc for fuzzy match functions * feat(ui-design-system): add switch focus styles * feat(fuzzy-match): edit threshold * feat(fuzzy-match): localised editable algorithm
- Loading branch information
Showing
27 changed files
with
1,327 additions
and
73 deletions.
There are no files selected for viewing
This file contains 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 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 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,22 @@ | ||
import clsx from 'clsx'; | ||
import { forwardRef } from 'react'; | ||
|
||
export const ExternalLink = forwardRef< | ||
HTMLAnchorElement, | ||
React.ComponentPropsWithoutRef<'a'> | ||
>(function ExternalLink({ className, children, ...otherProps }, ref) { | ||
return ( | ||
<a | ||
ref={ref} | ||
className={clsx( | ||
'hover:text-purple-120 focus:text-purple-120 font-semibold lowercase text-purple-100 hover:underline focus:underline', | ||
className, | ||
)} | ||
target="_blank" | ||
rel="noreferrer" | ||
{...otherProps} | ||
> | ||
{children} | ||
</a> | ||
); | ||
}); |
This file contains 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 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 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 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 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
122 changes: 122 additions & 0 deletions
122
.../components/Scenario/AstBuilder/AstBuilderNode/FuzzyMatchComparatorEdit/EditAlgorithm.tsx
This file contains 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,122 @@ | ||
import { EvaluationErrors } from '@app-builder/components/Scenario/ScenarioValidationError'; | ||
import { | ||
editableFuzzyMatchAlgorithms, | ||
type FuzzyMatchAlgorithm, | ||
getFuzzyMatchAlgorithmName, | ||
isEditableFuzzyMatchAlgorithm, | ||
} from '@app-builder/models/fuzzy-match'; | ||
import { type EvaluationError } from '@app-builder/models/node-evaluation'; | ||
import { | ||
adaptEvaluationErrorViewModels, | ||
useGetNodeEvaluationErrorMessage, | ||
} from '@app-builder/services/validation'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { Select, Tooltip } from 'ui-design-system'; | ||
import { Icon } from 'ui-icons'; | ||
|
||
import { operatorContainerClassnames } from '../Operator'; | ||
|
||
interface EditAlgorithmProps { | ||
algorithm: FuzzyMatchAlgorithm; | ||
setAlgorithm: (algorithm: FuzzyMatchAlgorithm) => void; | ||
errors: EvaluationError[]; | ||
} | ||
|
||
export function EditAlgorithm({ | ||
algorithm, | ||
setAlgorithm, | ||
errors, | ||
}: EditAlgorithmProps) { | ||
const { t } = useTranslation(['common', 'scenarios']); | ||
const getNodeEvaluationErrorMessage = useGetNodeEvaluationErrorMessage(); | ||
|
||
if (isEditableFuzzyMatchAlgorithm(algorithm)) { | ||
return ( | ||
<div className="flex flex-1 flex-col gap-2"> | ||
<label htmlFor="algorithm" className="text-m text-grey-100 font-normal"> | ||
{t('scenarios:edit_fuzzy_match.algorithm.label')} | ||
</label> | ||
<Select.Root value={algorithm} onValueChange={setAlgorithm}> | ||
<Select.Trigger | ||
id="algorithm" | ||
className={operatorContainerClassnames({ | ||
validationStatus: errors.length > 0 ? 'error' : 'valid', | ||
})} | ||
> | ||
<span className="text-s text-grey-100 w-full text-center font-medium"> | ||
<Select.Value placeholder="..." /> | ||
</span> | ||
<Tooltip.Default | ||
content={t( | ||
`scenarios:edit_fuzzy_match.algorithm.description.${algorithm}`, | ||
)} | ||
> | ||
<Icon | ||
icon="tip" | ||
className="size-5 shrink-0 text-purple-50 transition-colors hover:text-purple-100" | ||
/> | ||
</Tooltip.Default> | ||
</Select.Trigger> | ||
<Select.Content className="max-h-60"> | ||
<Select.Viewport> | ||
{editableFuzzyMatchAlgorithms.map((fuzzyMatchAlgorithm) => { | ||
return ( | ||
<Select.Item | ||
className="flex min-w-[110px] flex-col gap-1" | ||
key={fuzzyMatchAlgorithm} | ||
value={fuzzyMatchAlgorithm} | ||
> | ||
<Select.ItemText> | ||
<FuzzyMatchAlgorithmLabel | ||
fuzzyMatchAlgorithm={fuzzyMatchAlgorithm} | ||
/> | ||
</Select.ItemText> | ||
<p className="text-s text-grey-50"> | ||
{t( | ||
`scenarios:edit_fuzzy_match.algorithm.description.${fuzzyMatchAlgorithm}`, | ||
)} | ||
</p> | ||
</Select.Item> | ||
); | ||
})} | ||
</Select.Viewport> | ||
</Select.Content> | ||
</Select.Root> | ||
<EvaluationErrors | ||
errors={adaptEvaluationErrorViewModels(errors).map( | ||
getNodeEvaluationErrorMessage, | ||
)} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="flex flex-1 flex-col gap-2"> | ||
<span className="text-m text-grey-100 font-normal"> | ||
{t('scenarios:edit_fuzzy_match.threshold.label')} | ||
</span> | ||
<div className="bg-grey-02 border-grey-10 flex h-10 items-center justify-center rounded border p-2 text-center"> | ||
<FuzzyMatchAlgorithmLabel fuzzyMatchAlgorithm={algorithm} /> | ||
</div> | ||
<EvaluationErrors | ||
errors={adaptEvaluationErrorViewModels(errors).map( | ||
getNodeEvaluationErrorMessage, | ||
)} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
function FuzzyMatchAlgorithmLabel({ | ||
fuzzyMatchAlgorithm, | ||
}: { | ||
fuzzyMatchAlgorithm: FuzzyMatchAlgorithm; | ||
}) { | ||
const { t } = useTranslation(['common', 'scenarios']); | ||
return ( | ||
<span className="text-s text-grey-100 font-semibold"> | ||
{getFuzzyMatchAlgorithmName(t, fuzzyMatchAlgorithm)} | ||
</span> | ||
); | ||
} |
Oops, something went wrong.