firecmsco / firecms

Awesome Firebase/Firestore-based CMS. The missing admin panel for your Firebase project!
https://firecms.co
Other
1.14k stars 185 forks source link

ForceFilter in reference property is not working #511

Closed davidsondefaria closed 1 year ago

davidsondefaria commented 1 year ago

I was trying to filter a collection to make an array of references for another collection, using forceFilter as documentation says, but although the filter overrides the initialFilter, the result shows my entire collection (without initialFilter, forceFilter and does not allow me to filter manually too).

const groups = {
  name: "Groups¨,
  initialFilter: {
    status: ["==", "completed"]
  },
  properties: {    
    members: buildProperty({
      name: "Members",
      dataType: "array",
      of: {
        dataType: "string",
      }
    }),
  ...
  }
}

and users has an array with all groups that he is

const users = {
  name: "Users",
  properties: {
    id: buildProperty({
      name: "ID",
      dataType: "string"
    }),
    groups: buildProperty(({values}) => {
      name: "Groups",
      dataType: "array",
      of: {
        dataType: "reference",
        path: "groups",
        forceFilter: {
          members:  ["array-contains", values.id]
        }
      },
    }),
  }
}

In firebase, the collections are populated through another app and I need FireCMS to manage the groups per user.

Also tried to use members: ["Contains", values.id], members: ["array-contains-any", values.id] and even tried a hardcoded group ID id: ["==", "my-id"].

fgatti675 commented 1 year ago

Fixed in version v2.0.4 :)

mvarchdev commented 1 year ago

Issue still happenning in 2.0.5:

                    indexOfRefraction2: buildProperty((values) => {
                        console.log({ availableForMaterials: ["array-contains", { id: values.values.materialDetails?.material?.id, path: values.values.materialDetails?.material?.path }] });

                        return {
                            name: glassMaterialsIORCollection.singularName,
                            disabled: !values.values.materialDetails?.material && { disabledMessage: "Please select firstly material!", clearOnDisabled: true },
                            dataType: "reference",
                            path: glassMaterialsIORCollectionTop.path,
                            forceFilter: { availableForMaterials: ["array-contains", { id: values.values.materialDetails?.material?.id, path: values.values.materialDetails?.material?.path }] },
                            previewProperties: ["label"]
                        }
                    })

Tried also force filter with string values, works without problem when doing filtering in collection view. @fgatti675

fraank commented 1 week ago

I guess this issue should be kept open.

@mvarchdev did you find a workaround to filter here by reference / documentID? sth. like this i would use in native react could be working, but i could not get it in firecms?!

const categoryDocRef = doc(firebaseDbInstance, "/COLLECTION_NAME/DOCUMENT_ID");