Skip to content
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

Fix 1312959 boosts rule engine filter only product attributes #217

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading