Morph many to one picker (#14155)

This PR follows the multiSelect PR merged previously. It will enable
morph relation Many to One to be handled from the table, using a
singleSelect picker

Main point : I decided to change the singleSelect API to take an array
of **objectMetadataName** instead of only one to deal with both our
usecases.

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Guillim
2025-10-07 17:25:11 +02:00
committed by GitHub
co-authored by Charles Bochet
parent 9f9c2d85ca
commit f60817a1e1
138 changed files with 2116 additions and 1763 deletions
@@ -1,5 +1,8 @@
export const filterOutByProperty = <T, K extends keyof T>(property: K, valueToExclude: T[K] | null | undefined) => {
export const filterOutByProperty = <T, K extends keyof T>(
property: K,
valueToExclude: T[K] | null | undefined,
) => {
return (itemToFilter: T) => {
return itemToFilter[property] !== valueToExclude
}
}
return itemToFilter[property] !== valueToExclude;
};
};
@@ -1,5 +1,5 @@
export const findById = <T extends { id: string }>(idToMatch: string) => {
return (itemToFind: T) => {
return itemToFind.id === idToMatch
}
}
return itemToFind.id === idToMatch;
};
};
@@ -1,5 +1,8 @@
export const findByProperty = <T, K extends keyof T>(property: K, valueToMatch: T[K] | null | undefined) => {
export const findByProperty = <T, K extends keyof T>(
property: K,
valueToMatch: T[K] | null | undefined,
) => {
return (itemToFind: T) => {
return itemToFind[property] === valueToMatch
}
}
return itemToFind[property] === valueToMatch;
};
};
@@ -3,11 +3,11 @@ import { assertIsDefinedOrThrow } from '@/utils';
export const findOrThrow = <T>(
array: T[],
predicate: (value: T) => boolean,
error: Error = new Error('Element not found'),
error: Error = new Error('Element not found'),
): T => {
const result = array.find(predicate);
assertIsDefinedOrThrow(result, error)
assertIsDefinedOrThrow(result, error);
return result;
};
@@ -1,17 +1,17 @@
import { isNumberOrNaN } from "@sniptt/guards";
import { isNumberOrNaN } from '@sniptt/guards';
export const sumByProperty = <T, K extends keyof T>(property: K) => {
return (accumulator: number, nextItem: T) => {
if(typeof accumulator !== "number") {
if (typeof accumulator !== 'number') {
accumulator = 0;
}
if(!isNumberOrNaN(nextItem[property])) {
if (!isNumberOrNaN(nextItem[property])) {
return accumulator;
}
accumulator += nextItem[property];
return accumulator
}
}
return accumulator;
};
};