f60817a1e1
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>
14 lines
295 B
TypeScript
14 lines
295 B
TypeScript
import { assertIsDefinedOrThrow } from '@/utils';
|
|
|
|
export const findOrThrow = <T>(
|
|
array: T[],
|
|
predicate: (value: T) => boolean,
|
|
error: Error = new Error('Element not found'),
|
|
): T => {
|
|
const result = array.find(predicate);
|
|
|
|
assertIsDefinedOrThrow(result, error);
|
|
|
|
return result;
|
|
};
|