equinor / fusion-react-components

mono repo for collection of react components used for Fusion apps
MIT License
7 stars 1 forks source link

AgGrid Person Cell - Custom generic filter feature #2163

Open AndrejNikolicEq opened 2 months ago

AndrejNikolicEq commented 2 months ago

Is your feature request related to a problem? Please describe. Currently, when you use AgGridPesonCell with data extraction, default filter is not working correctly, so you have to add custom filter in order to access correct data to filter. Here is working example:

// filter
export const PersonFilter = {
  filter: 'agSetColumnFilter',
  filterParams: {
    applyMiniFilterWhileTyping: true,
    keyCreator: (params: KeyCreatorParams<ContractPersonnelRequest, ContractPerson>) => {
      return params.value?.azureId || '';
    },
    valueFormatter: (params: ValueFormatterParams<ContractPersonnelRequest, ContractPerson>) => {
      return params.value ? params.value.name : '(Blanks)';
    },
  } as ISetFilterParams,
};

// usage of person filter in person cell
agGridPersonCell({
  field: 'person',
  headerName: 'Person',
  flex: 1,
  azureId: (data: Person) => data.azureId,
  heading: (person) => person.name,
  subHeading: (person) => {
    return person.mail
      ? `<a href="mailto:${person.mail}">${person.mail}</a>`
      : 'email not available';
    },
  dataToSort: (data: Person) => data.name,
  ...PersonFilter,
}),

Describe the solution you'd like We should maybe write generic property like for sorting, where you can choose data to use to filter and data to format

Describe alternatives you've considered Do nothing, leave it as is