Skip to content

Commit

Permalink
Merge pull request #217 from Elastic-Suite/fix-1312959-BoostsRuleEngi…
Browse files Browse the repository at this point in the history
…neFilterOnlyProductAttributes

Fix 1312959 boosts rule engine filter only product attributes
  • Loading branch information
matthias-goupil authored Dec 3, 2024
2 parents 2becfb2 + 6a11e50 commit 95bf2df
Showing 1 changed file with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const sourceFieldFixedFilters = {
isUsedForRules: true,
}

interface IProps
interface IRulesManagerWrapperProps
extends Omit<
ICombinationRulesProps,
'catalogId' | 'localizedCatalogId' | 'rule' | 'onChange'
Expand All @@ -48,10 +48,26 @@ interface IProps
showError?: boolean
}

function RulesManager(props: IProps): JSX.Element {
function RulesManagerWrapper({
ruleOperators: defaultRuleOperators,
...props
}: IRulesManagerWrapperProps): JSX.Element {
const ruleOperators = useRuleOperators(defaultRuleOperators)

if (!ruleOperators) {
return null
}

return <RulesManager {...props} ruleOperators={ruleOperators} />
}

interface IRulesManagerProps extends IRulesManagerWrapperProps {
ruleOperators: IRuleEngineOperators
}
function RulesManager(props: IRulesManagerProps): JSX.Element {
const {
active,
ruleOperators: ruleOperatorsDefault,
ruleOperators,
label,
infoTooltip,
required,
Expand All @@ -64,7 +80,6 @@ function RulesManager(props: IProps): JSX.Element {
} = props
const { t } = useTranslation('common')
const { catalogId, localizedCatalogId } = useContext(catalogContext)
const ruleOperators = useRuleOperators(ruleOperatorsDefault)
const rowsPerPage = 200
const rule: IRuleCombination =
typeof ruleProps.rule === 'string'
Expand All @@ -89,7 +104,7 @@ function RulesManager(props: IProps): JSX.Element {
'type[]': Object.keys(ruleOperators.operatorsValueType),
}
}
}, [ruleOperators?.operatorsValueType])
}, [ruleOperators.operatorsValueType])
const [sourceFields] = useApiList<ISourceField>(
sourceFieldResource,
false,
Expand Down Expand Up @@ -122,7 +137,7 @@ function RulesManager(props: IProps): JSX.Element {
true
)

if (!sourceFields.data || !sourceFieldLabels.data || !ruleOperators) {
if (!sourceFields.data || !sourceFieldLabels.data) {
return null
}

Expand Down Expand Up @@ -190,4 +205,4 @@ RulesManager.defaultProps = {
small: false,
}

export default RulesManager
export default RulesManagerWrapper

0 comments on commit 95bf2df

Please sign in to comment.