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(ui): filter out fields with disableListFilter in whereBuilder prior to adding conditions #10112

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 1 addition & 5 deletions packages/ui/src/elements/WhereBuilder/Condition/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ export const Condition: React.FC<Props> = (props) => {
updateCondition,
} = props

const options = useMemo(() => {
return fields.filter(({ field }) => !field.admin.disableListFilter)
}, [fields])

const [internalField, setInternalField] = useState<FieldCondition>(() =>
fields.find((field) => fieldName === field.value),
)
Expand Down Expand Up @@ -135,7 +131,7 @@ export const Condition: React.FC<Props> = (props) => {
setInternalOperatorOption(undefined)
setInternalQueryValue(undefined)
}}
options={options}
options={fields}
value={
fields.find((field) => internalField?.value === field.value) || {
value: internalField?.value,
Expand Down
24 changes: 15 additions & 9 deletions packages/ui/src/elements/WhereBuilder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export const WhereBuilder: React.FC<WhereBuilderProps> = (props) => {
setReducedColumns(reduceClientFields({ fields, i18n }))
}, [fields, i18n])

const filterableFields = React.useMemo(() => {
return reducedFields.filter((condition) => !condition.field?.admin?.disableListFilter)
}, [reducedFields])

const { handleWhereChange, query } = useListQuery()
const [shouldUpdateQuery, setShouldUpdateQuery] = React.useState(false)

Expand Down Expand Up @@ -185,7 +189,7 @@ export const WhereBuilder: React.FC<WhereBuilderProps> = (props) => {
addCondition={addCondition}
andIndex={andIndex}
fieldName={initialFieldName}
fields={reducedFields}
fields={filterableFields}
initialValue={initialValue}
operator={initialOperator}
orIndex={orIndex}
Expand All @@ -208,12 +212,14 @@ export const WhereBuilder: React.FC<WhereBuilderProps> = (props) => {
iconPosition="left"
iconStyle="with-border"
onClick={() => {
addCondition({
andIndex: 0,
fieldName: reducedFields[0].value,
orIndex: conditions.length,
relation: 'or',
})
if (filterableFields.length > 0) {
addCondition({
andIndex: 0,
fieldName: filterableFields[0].value,
orIndex: conditions.length,
relation: 'or',
})
}
}}
>
{t('general:or')}
Expand All @@ -230,10 +236,10 @@ export const WhereBuilder: React.FC<WhereBuilderProps> = (props) => {
iconPosition="left"
iconStyle="with-border"
onClick={() => {
if (reducedFields.length > 0) {
if (filterableFields.length > 0) {
addCondition({
andIndex: 0,
fieldName: reducedFields[0].value,
fieldName: filterableFields[0].value,
orIndex: conditions.length,
relation: 'or',
})
Expand Down
Loading