Fix/opportunities board (#2610)
* WIP * wip * update pipelineStepId * rename pipeline stage to pipeline step * rename pipelineProgress to Opportunity * fix UUID type not queried * fix boardColumnTotal * fix micros * fixing filters, sorts and fields * wip * wip * Fix opportunity board re-render --------- Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com> Co-authored-by: bosiraphael <raphael.bosi@gmail.com>
This commit is contained in:
@ -5,19 +5,20 @@ import { useRelationField } from '../../hooks/useRelationField';
|
||||
export const RelationFieldDisplay = () => {
|
||||
const { fieldValue, fieldDefinition } = useRelationField();
|
||||
|
||||
const { mapToObjectIdentifiers } = useRelationField();
|
||||
|
||||
if (!fieldValue || !fieldDefinition) {
|
||||
return <></>;
|
||||
}
|
||||
|
||||
const mainIdentifierMapped =
|
||||
fieldDefinition.metadata.mainIdentifierMapper(fieldValue);
|
||||
const objectIdentifiers = mapToObjectIdentifiers(fieldValue);
|
||||
|
||||
return (
|
||||
<EntityChip
|
||||
entityId={fieldValue.id}
|
||||
name={mainIdentifierMapped.name}
|
||||
avatarUrl={mainIdentifierMapped.avatarUrl}
|
||||
avatarType={mainIdentifierMapped.avatarType}
|
||||
name={objectIdentifiers.name}
|
||||
avatarUrl={objectIdentifiers.avatarUrl}
|
||||
avatarType={objectIdentifiers.avatarType}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@ -30,11 +30,40 @@ export const useRelationField = () => {
|
||||
|
||||
const initialValue = fieldInitialValue?.isEmpty ? null : fieldValue;
|
||||
|
||||
const mapToObjectIdentifiers = (record: any) => {
|
||||
let name = '';
|
||||
for (const fieldPath of fieldDefinition.metadata
|
||||
.labelIdentifierFieldPaths) {
|
||||
const fieldPathParts = fieldPath.split('.');
|
||||
|
||||
if (fieldPathParts.length === 1) {
|
||||
name += record[fieldPathParts[0]];
|
||||
} else if (fieldPathParts.length === 2) {
|
||||
name += record[fieldPathParts[0]][fieldPathParts[1]];
|
||||
} else {
|
||||
throw new Error(
|
||||
`Invalid field path ${fieldPath}. Relation picker only supports field paths with 1 or 2 parts.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
id: record.id,
|
||||
name: record[name],
|
||||
avatarUrl:
|
||||
fieldDefinition.metadata.imageIdentifierUrlPrefix +
|
||||
record[fieldDefinition.metadata.imageIdentifierUrlField],
|
||||
avatarType: fieldDefinition.metadata.imageIdentifierFormat,
|
||||
record: record,
|
||||
};
|
||||
};
|
||||
|
||||
return {
|
||||
fieldDefinition,
|
||||
fieldValue,
|
||||
initialValue,
|
||||
initialSearchValue,
|
||||
setFieldValue,
|
||||
mapToObjectIdentifiers,
|
||||
};
|
||||
};
|
||||
|
||||
@ -7,6 +7,7 @@ import { IconUserCircle } from '@/ui/display/icon';
|
||||
import { SingleEntitySelect } from '@/ui/input/relation-picker/components/SingleEntitySelect';
|
||||
import { relationPickerSearchFilterScopedState } from '@/ui/input/relation-picker/states/relationPickerSearchFilterScopedState';
|
||||
import { EntityForSelect } from '@/ui/input/relation-picker/types/EntityForSelect';
|
||||
import { useRelationField } from '@/ui/object/field/meta-types/hooks/useRelationField';
|
||||
import { FieldDefinition } from '@/ui/object/field/types/FieldDefinition';
|
||||
import { FieldRelationMetadata } from '@/ui/object/field/types/FieldMetadata';
|
||||
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
|
||||
@ -41,6 +42,8 @@ export const RelationPicker = ({
|
||||
|
||||
const useFindManyQuery = (options: any) => useQuery(findManyQuery, options);
|
||||
|
||||
const { mapToObjectIdentifiers } = useRelationField();
|
||||
|
||||
const workspaceMembers = useFilteredSearchEntityQuery({
|
||||
queryHook: useFindManyQuery,
|
||||
filters: [
|
||||
@ -50,7 +53,7 @@ export const RelationPicker = ({
|
||||
},
|
||||
],
|
||||
orderByField: 'createdAt',
|
||||
mappingFunction: fieldDefinition.metadata.mainIdentifierMapper,
|
||||
mappingFunction: mapToObjectIdentifiers,
|
||||
selectedIds: recordId ? [recordId] : [],
|
||||
objectNamePlural: fieldDefinition.metadata.objectMetadataNamePlural,
|
||||
});
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { EntityForSelect } from '@/ui/input/relation-picker/types/EntityForSelect';
|
||||
import { MainIdentifierMapper } from '@/ui/object/field/types/MainIdentifierMapper';
|
||||
|
||||
export type FieldUuidMetadata = {
|
||||
fieldName: string;
|
||||
@ -65,7 +64,10 @@ export type FieldRelationMetadata = {
|
||||
fieldName: string;
|
||||
useEditButton?: boolean;
|
||||
relationType?: FieldDefinitionRelationType;
|
||||
mainIdentifierMapper: MainIdentifierMapper;
|
||||
labelIdentifierFieldPaths: string[];
|
||||
imageIdentifierUrlField: string;
|
||||
imageIdentifierUrlPrefix: string;
|
||||
imageIdentifierFormat: 'squared' | 'rounded';
|
||||
searchFields: string[];
|
||||
objectMetadataNameSingular: string;
|
||||
objectMetadataNamePlural: string;
|
||||
|
||||
@ -1,9 +0,0 @@
|
||||
import { AvatarType } from '@/users/components/Avatar';
|
||||
|
||||
export type MainIdentifierMapper = (record: any) => {
|
||||
id: string;
|
||||
name: string;
|
||||
avatarUrl?: string;
|
||||
avatarType: AvatarType;
|
||||
record: any;
|
||||
};
|
||||
@ -1,14 +0,0 @@
|
||||
import { MainIdentifierMapper } from '@/ui/object/field/types/MainIdentifierMapper';
|
||||
|
||||
export type FieldDefinitionRelationType =
|
||||
| 'FROM_MANY_OBJECTS'
|
||||
| 'FROM_ONE_OBJECT'
|
||||
| 'TO_MANY_OBJECTS'
|
||||
| 'TO_ONE_OBJECT';
|
||||
|
||||
export type RelationFieldConfig = {
|
||||
relationType?: FieldDefinitionRelationType;
|
||||
mainIdentifierMapper: MainIdentifierMapper;
|
||||
searchFields: string[];
|
||||
objectMetadataNameSingular: string;
|
||||
};
|
||||
@ -63,7 +63,6 @@ export const RecordTableCell = ({ cellIndex }: { cellIndex: number }) => {
|
||||
isMainIdentifier:
|
||||
columnDefinition.fieldMetadataId ===
|
||||
objectMetadataConfig?.mainIdentifierFieldMetadataId,
|
||||
mainIdentifierMapper: objectMetadataConfig?.mainIdentifierMapper,
|
||||
}}
|
||||
>
|
||||
<TableCell customHotkeyScope={{ scope: customHotkeyScope }} />
|
||||
|
||||
@ -2,10 +2,9 @@ import { AvatarType } from '@/users/components/Avatar';
|
||||
|
||||
export type ObjectMetadataConfig = {
|
||||
mainIdentifierFieldMetadataId: string;
|
||||
mainIdentifierMapper: (record: any) => {
|
||||
name: string;
|
||||
avatarUrl?: string;
|
||||
avatarType: AvatarType;
|
||||
};
|
||||
labelIdentifierFieldPaths: string[];
|
||||
imageIdentifierUrlField: string;
|
||||
imageIdentifierUrlPrefix: string;
|
||||
imageIdentifierFormat: AvatarType;
|
||||
basePathToShowPage: string;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user