Skip to content

Commit

Permalink
Merge pull request #593 from jetstreamapp/bug/587
Browse files Browse the repository at this point in the history
Fix load custom metadata
  • Loading branch information
paustint authored Oct 17, 2023
2 parents d8d1396 + f3f7752 commit 7523bca
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ function getComboboxFieldTitle(item: ListItem) {
export interface LoadRecordsFieldMappingStaticRowProps {
fields: FieldWithRelatedEntities[];
fieldMappingItem: FieldMappingItemStatic;
isCustomMetadata?: boolean;
onSelectionChanged: (fieldMappingItem: FieldMappingItemStatic) => void;
onRemoveRow: () => void;
}
Expand Down Expand Up @@ -54,6 +55,7 @@ function getFieldListItems(fields: FieldWithRelatedEntities[]) {
export const LoadRecordsFieldMappingStaticRow: FunctionComponent<LoadRecordsFieldMappingStaticRowProps> = ({
fields,
fieldMappingItem,
isCustomMetadata,
onSelectionChanged,
onRemoveRow,
}) => {
Expand Down Expand Up @@ -83,9 +85,11 @@ export const LoadRecordsFieldMappingStaticRow: FunctionComponent<LoadRecordsFiel
})) || [],
};
}
setEditableField(convertMetadataToEditableFields([fieldMappingItem.fieldMetadata.field], picklistValues, 'create', {})[0]);
setEditableField(
convertMetadataToEditableFields([fieldMappingItem.fieldMetadata.field], picklistValues, 'create', {}, isCustomMetadata)[0]
);
}
}, [fieldMappingItem.fieldMetadata]);
}, [fieldMappingItem.fieldMetadata, isCustomMetadata]);

function handleValueChange(field: EditableFields, staticValue: string | boolean | null) {
onSelectionChanged({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ export const LoadRecordsFieldMapping = memo<LoadRecordsFieldMappingProps>(
key={`${keyPrefix}-static-${i}`}
fields={fields}
fieldMappingItem={fieldMapping[header] as FieldMappingItemStatic}
isCustomMetadata={isCustomMetadataObject}
onSelectionChanged={(value) => handleFieldMappingChange(header, value)}
onRemoveRow={() => handleRemoveRow(header)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,24 @@ export function convertCsvToCustomMetadata(
if (!fieldMappingByTargetField.DeveloperName.csvField || !fieldMappingByTargetField.Label.csvField) {
return;
}
const fullName = `${selectedSObject}.${row[fieldMappingByTargetField.DeveloperName.csvField]}`;
const label = fieldMappingByTargetField.Label ? row[fieldMappingByTargetField.Label.csvField] : null;

let developerName: string | null = null;
if (fieldMappingByTargetField.Label) {
developerName =
fieldMappingByTargetField.DeveloperName.type === 'STATIC'
? fieldMappingByTargetField.DeveloperName.staticValue
: row[fieldMappingByTargetField.DeveloperName.csvField];
}

let label: string | null = null;
if (fieldMappingByTargetField.Label) {
label =
fieldMappingByTargetField.Label.type === 'STATIC'
? fieldMappingByTargetField.Label.staticValue
: row[fieldMappingByTargetField.Label.csvField];
}

const fullName = `${selectedSObject}.${developerName}`;
const record: any = {
DeveloperName: fullName,
Label: label,
Expand All @@ -758,11 +774,16 @@ export function convertCsvToCustomMetadata(
.filter((field) => field.name.endsWith('__c'))
.forEach((field) => {
const fieldMappingItem = fieldMappingByTargetField[field.name];
if (!fieldMappingItem.csvField) {
return;

let fieldValue: string | null | boolean = null;

if (fieldMappingItem && fieldMappingItem.type === 'STATIC') {
fieldValue = fieldMappingItem.staticValue;
} else if (fieldMappingItem) {
fieldValue = row[fieldMappingItem.csvField];
}
let fieldValue = fieldMappingItem ? row[fieldMappingItem.csvField] : null;
// ensure that field is in correct data type (mostly for dates)

// ensure field is in correct data type (mostly for dates)
fieldValue = transformRecordForDataLoad(fieldValue, field.type, dateFormat);
// Custom metadata lookups always use name to relate records
const soapType = field.soapType === 'tns:ID' ? 'xsd:string' : field.soapType;
Expand Down
7 changes: 5 additions & 2 deletions libs/shared/ui-record-form/src/lib/ui-record-form-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ export function convertMetadataToEditableFields(
fields: Field[],
picklistValues: PicklistFieldValues,
action: CloneEditView,
record: Record
record: Record,
isCustomMetadata = false
): EditableFields[] {
return sortQueryFields(fields.filter((field) => !IGNORED_FIELD_TYPES.has(field.type))).map((field): EditableFields => {
let readOnly = action === 'view';
if (!readOnly) {
if (!readOnly && !isCustomMetadata) {
readOnly = action === 'edit' ? !field.updateable : !field.createable;
} else if (!readOnly && isCustomMetadata) {
readOnly = !field.custom && field.name !== 'DeveloperName' && field.name !== 'Label';
}
const output: Partial<EditableFields> = {
label: `${field.label} (${field.name})`,
Expand Down

0 comments on commit 7523bca

Please sign in to comment.