ForestAdmin / forestadmin-experimental

3 stars 0 forks source link

packages/plugin-define-enum - Enable sort and filtering #97

Open Aralun opened 2 months ago

Aralun commented 2 months ago

I've added some sorting and filtering to fields defined with the plugin. The code looked very boiler-platey, so maybe it could be included in the plugin?

    .replaceFieldSorting(newFieldName, [
      { field: fieldName, ascending: true },
    ])
    .replaceFieldOperator(newFieldName, 'Equal', (v) => ({
      field: fieldName,
      operator: 'Equal',
      value: v ? enumObject[v] : null,
    }))
    .replaceFieldOperator(newFieldName, 'NotEqual', (v) => ({
      field: fieldName,
      operator: 'NotEqual',
      value: v ? enumObject[v] : null,
    }))
    .replaceFieldOperator(newFieldName, 'Present', () => ({
      field: fieldName,
      operator: 'Present',
    }))
    .replaceFieldOperator(newFieldName, 'Blank', () => ({
      field: fieldName,
      operator: 'Blank',
    }))

I don't know if there are subtle implications to this, for example on matters of performance. If so, it might be worth hiding these behind enableSorting / enableFiltering options.

Thenkei commented 1 month ago

Hey @Aralun,

It's indeed a good idea! Most of our team is on Holiday vacation so we will add this when we will have a little time.