Skip to content

Commit

Permalink
feat(cc-zone): add infra if any to the getText() static method
Browse files Browse the repository at this point in the history
Fixes #724
  • Loading branch information
pdesoyres-cc committed Mar 15, 2023
1 parent 1f3aa94 commit c607fbb
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/components/cc-zone/cc-zone.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,30 @@ export class CcZone extends LitElement {
// This is a bit irregular to do this but we need to reuse this text logic in a <select>.
// Moving this to a separated module feels overkill right now.
static getText (zone) {
const { title, subtitle } = CcZone._getTextParts(zone);
return [title, subtitle].filter((a) => a != null).join(', ');
const { title, subtitle, infra } = CcZone._getTextParts(zone);
return [title, subtitle, infra].filter((a) => a != null).join(', ');
}

static _getTextParts (zone) {
return (zone.tags.includes(PRIVATE_ZONE) && zone.displayName != null)
? { title: zone.displayName }
: { title: zone.city, subtitle: i18n('cc-zone.country', { code: zone.countryCode, name: zone.country }) };
: {
title: zone.city,
subtitle: i18n('cc-zone.country', { code: zone.countryCode, name: zone.country }),
infra: CcZone._getInfraProviderSlug(zone),
};
}

static _getInfraProviderSlug (zone) {
const infraTag = zone.tags.find((t) => t.startsWith('infra:'));
return infraTag?.split(':')[1] ?? null;
}

render () {

const skeleton = (this.zone == null);
const zone = skeleton ? SKELETON_ZONE : this.zone;
const { title, subtitle } = CcZone._getTextParts(zone);
const infraTag = zone.tags.find((t) => t.startsWith('infra:'));
const infraProviderSlug = infraTag?.split(':')[1] ?? null;
const { title, subtitle, infra } = CcZone._getTextParts(zone);

return html`
<cc-img class="flag" ?skeleton=${skeleton} src=${ifDefined(getFlagUrl(zone.countryCode))} text=${ifDefined(zone.countryCode)}></cc-img>
Expand All @@ -87,8 +94,8 @@ export class CcZone extends LitElement {
<span class="title ${classMap({ skeleton })}">${title}</span>
<span class="subtitle ${classMap({ skeleton })}">${subtitle}</span>
</div>
${infraProviderSlug != null ? html`
<cc-img class="infra-logo" src=${ifDefined(getInfraProviderLogoUrl(infraProviderSlug))} text=${ifDefined(infraProviderSlug)}></cc-img>
${infra != null ? html`
<cc-img class="infra-logo" src=${ifDefined(getInfraProviderLogoUrl(infra))} text=${ifDefined(infra)}></cc-img>
` : ''}
</div>
<cc-flex-gap class="tag-list">
Expand Down

0 comments on commit c607fbb

Please sign in to comment.