32 lines
696 B
TypeScript
32 lines
696 B
TypeScript
/* eslint-disable import/prefer-default-export */
|
|
|
|
import type { BaseOption } from 'Elements/types';
|
|
|
|
const propsMap = {
|
|
lead: {
|
|
name: 'fullname',
|
|
value: 'leadid',
|
|
},
|
|
opportunity: {
|
|
name: 'name',
|
|
value: 'opportunityid',
|
|
},
|
|
};
|
|
|
|
type PropsMap = typeof propsMap;
|
|
|
|
function getEntityName(entities: any[]): keyof PropsMap {
|
|
// eslint-disable-next-line no-underscore-dangle
|
|
return entities.at(0)?.__typename;
|
|
}
|
|
|
|
export function convertEntitiesToOptions(entities: any[]): BaseOption[] {
|
|
const entityName = getEntityName(entities);
|
|
const map = propsMap[entityName];
|
|
|
|
return entities.map((entity) => ({
|
|
label: entity[map.name],
|
|
value: entity[map.value],
|
|
}));
|
|
}
|