From babf0fb0f6fd76f9c55de91aeec662a2beecdf70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Rialland?= Date: Thu, 7 Apr 2022 12:17:05 +0200 Subject: [PATCH] Catch error in RuleLink --- site/source/components/RuleLink.tsx | 9 +++++++++ .../components/search/RulesInfiniteHits/index.tsx | 13 ++++++++++--- site/source/pages/gerer/_components/Fields.tsx | 2 +- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/site/source/components/RuleLink.tsx b/site/source/components/RuleLink.tsx index decf74616..cdc329c94 100644 --- a/site/source/components/RuleLink.tsx +++ b/site/source/components/RuleLink.tsx @@ -16,6 +16,15 @@ export default function RuleLink( const sitePaths = useContext(SitePathsContext) const engine = useContext(EngineContext) + try { + engine.getRule(props.dottedName) + } catch (error) { + // eslint-disable-next-line no-console + console.error(error) + + return null + } + return ( +type THit = AlgoliaHit<{ objectID: DottedName; namespace?: string }> const StyledRuleLink = styled(RuleLink)` ${SmallBody}, ${Body} { @@ -42,7 +42,7 @@ const HitContainer = styled.li` } ` -const Hit = (hit: Hit) => { +const Hit = (hit: THit) => { return ( @@ -89,7 +89,14 @@ const InfiniteHits = styled.div` } ` -const Hits = connectInfiniteHits(({ hits, hasMore, refineNext }) => { +interface IHits { + hits: THit[] + hasMore: boolean + hasPrevious: boolean + refineNext: () => void +} + +const Hits = connectInfiniteHits(({ hits, hasMore, refineNext }: IHits) => { const { t } = useTranslation() return ( diff --git a/site/source/pages/gerer/_components/Fields.tsx b/site/source/pages/gerer/_components/Fields.tsx index 33588fa6c..31c546497 100644 --- a/site/source/pages/gerer/_components/Fields.tsx +++ b/site/source/pages/gerer/_components/Fields.tsx @@ -95,7 +95,7 @@ export function SimpleField({ const labelId = useSSRSafeId() const targetUnit = useSelector(targetUnitSelector) - console.log(dottedName, evaluation) + if (evaluation.nodeValue === null) { return null }