utils.tsx 578 B

1234567891011121314151617181920212223242526
  1. export function filterItems<I extends object, K extends string>({
  2. filterFns,
  3. filterVals,
  4. items,
  5. }: {
  6. filterFns: Record<K, (item: I, val: any) => boolean>;
  7. filterVals: Record<K, any>;
  8. items: undefined | I[];
  9. }): I[] {
  10. return (
  11. items?.filter(item => {
  12. for (const key in filterFns) {
  13. const filter = filterFns[key];
  14. const val = filterVals[key];
  15. if (!filter(item, val)) {
  16. return false;
  17. }
  18. }
  19. return true;
  20. }) || []
  21. );
  22. }
  23. export function operationName(op: string) {
  24. return op.split('.')?.[1] ?? op;
  25. }