fix: use smart default for displayField based on entityType

When displayField is omitted in award definitions, the backend now
selects the appropriate default field based on the entityType:
- dxcc → entity (country name)
- state → state
- grid → grid (4-character)
- callsign → callsign

Previously, it used a fixed fallback order that prioritized entity
over other fields, causing grid-based awards to show DXCC names.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-01-23 14:14:05 +01:00
parent 2ae47232cb
commit a35731f626
4 changed files with 24 additions and 6 deletions

View File

@@ -896,7 +896,19 @@ export async function getAwardEntityBreakdown(userId, awardId) {
} }
displayName = String(rawValue || entity); displayName = String(rawValue || entity);
} else { } else {
displayName = qso.entity || qso.state || qso.grid || qso.callsign || String(entity); // Smart default based on entityType when displayField is not specified
const defaultDisplayField = {
'dxcc': 'entity',
'state': 'state',
'grid': 'grid',
'callsign': 'callsign'
}[rules.entityType] || 'entity';
let rawValue = qso[defaultDisplayField];
if (defaultDisplayField === 'grid' && rawValue && rawValue.length > 4) {
rawValue = rawValue.substring(0, 4);
}
displayName = String(rawValue || entity);
} }
if (!slotMap.has(slotKey)) { if (!slotMap.has(slotKey)) {

View File

@@ -804,7 +804,7 @@
bind:value={formData.rules.displayField} bind:value={formData.rules.displayField}
placeholder="e.g., entity, state, grid" placeholder="e.g., entity, state, grid"
/> />
<small>Field to display as entity name (defaults to entity value)</small> <small>Field to display as entity name (defaults based on entityType)</small>
</div> </div>
<div class="form-group"> <div class="form-group">

View File

@@ -197,16 +197,22 @@
} }
// Check if displayField matches the default for the entity type // Check if displayField matches the default for the entity type
if (rules.entityType && rules.displayField) { if (rules.entityType) {
const defaults = { const defaults = {
'dxcc': 'entity', 'dxcc': 'entity',
'state': 'state', 'state': 'state',
'grid': 'grid', 'grid': 'grid',
'callsign': 'callsign' 'callsign': 'callsign'
}; };
if (defaults[rules.entityType] === rules.displayField) { const defaultField = defaults[rules.entityType];
if (rules.displayField) {
if (defaultField === rules.displayField) {
info.push(`displayField="${rules.displayField}" is the default for entityType="${rules.entityType}". It can be omitted.`); info.push(`displayField="${rules.displayField}" is the default for entityType="${rules.entityType}". It can be omitted.`);
} }
} else if (defaultField) {
info.push(`displayField will default to "${defaultField}" for entityType="${rules.entityType}".`);
}
} }
return { warnings, info }; return { warnings, info };

View File

@@ -829,7 +829,7 @@
bind:value={formData.rules.displayField} bind:value={formData.rules.displayField}
placeholder="e.g., entity, state, grid" placeholder="e.g., entity, state, grid"
/> />
<small>Field to display as entity name (defaults to entity value)</small> <small>Field to display as entity name (defaults based on entityType)</small>
</div> </div>
<div class="form-group"> <div class="form-group">