fix(ui): gracefully handle default initial baseline mappings and job runs in ChannelMappingTab and SyndicationHistoryTab
This commit is contained in:
@@ -44,21 +44,27 @@ export function ChannelMappingTab({ channelId }: { channelId: string }) {
|
||||
|
||||
const loadMappings = async () => {
|
||||
setLoading(true);
|
||||
const defaultBaseline = [
|
||||
{ pim_attribute_code: "name", channel_field_code: "title", transformation_rule: "none", default_value: "", is_required: true },
|
||||
{ pim_attribute_code: "code", channel_field_code: "variant_sku", transformation_rule: "uppercase", default_value: "", is_required: true },
|
||||
{ pim_attribute_code: "status", channel_field_code: "published_status", transformation_rule: "lowercase", default_value: "published", is_required: false },
|
||||
];
|
||||
|
||||
if (!channelId || channelId === "demo-channel-id") {
|
||||
setMappings(defaultBaseline);
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const data = await channelsApi.getMappings(channelId);
|
||||
if (data && data.length > 0) {
|
||||
setMappings(data);
|
||||
} else {
|
||||
// Default initial baseline mappings
|
||||
setMappings([
|
||||
{ pim_attribute_code: "name", channel_field_code: "title", transformation_rule: "none", default_value: "", is_required: true },
|
||||
{ pim_attribute_code: "sku", channel_field_code: "variant_sku", transformation_rule: "uppercase", default_value: "", is_required: true },
|
||||
{ pim_attribute_code: "price", channel_field_code: "price", transformation_rule: "currency_format", default_value: "0.00", is_required: true },
|
||||
{ pim_attribute_code: "brand", channel_field_code: "vendor", transformation_rule: "none", default_value: "Generic", is_required: false },
|
||||
]);
|
||||
setMappings(defaultBaseline);
|
||||
}
|
||||
} catch {
|
||||
notify.error("Failed to load channel mapping rules");
|
||||
setMappings(defaultBaseline);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
@@ -15,12 +15,17 @@ export function SyndicationHistoryTab({ channelId }: { channelId: string }) {
|
||||
}, [channelId]);
|
||||
|
||||
const loadJobs = async () => {
|
||||
if (!channelId || channelId === "demo-channel-id") {
|
||||
setJobs([]);
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
setLoading(true);
|
||||
try {
|
||||
const data = await channelsApi.getJobs(channelId);
|
||||
setJobs(data || []);
|
||||
} catch {
|
||||
notify.error("Failed to load syndication history");
|
||||
setJobs([]);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user