Skip to content

Commit

Permalink
SonarCloud: nullish coalescing
Browse files Browse the repository at this point in the history
  • Loading branch information
oeni2023 committed Dec 2, 2024
1 parent e128b5a commit a2b81b6
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 49 deletions.
6 changes: 3 additions & 3 deletions ui/src/authService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {
import type {
CognitoIdentityCredentialProvider,
CognitoIdentityCredentials
} from '@aws-sdk/credential-provider-cognito-identity';
Expand Down Expand Up @@ -47,11 +47,11 @@ export default class AuthService {
if (params.has('access_token') && params.has('id_token') &&
params.get('token_type') === 'Bearer' && params.get('state') === this.state()) {
localStorage.setItem('rawCognitoResponse', response);
const token = params.get('access_token') || '';
const token = params.get('access_token') ?? '';
const payload = atob(token.split('.')[1]);
const claims = JSON.parse(payload);
this.setUser(claims);
this.setAccessToken(params.get('id_token') || '');
this.setAccessToken(params.get('id_token') ?? '');
}
} else if (this.getUser()) {
// this strange line sets up observable and autologout
Expand Down
12 changes: 6 additions & 6 deletions ui/src/elements/dashboard/ngm-add-member-form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export class NgmAddMemberForm extends LitElementI18n {

onAdd() {
if (!this.name || !this.surname || !isEmail(this.email) || !this.memberRole) {
this.name = this.name || '';
this.surname = this.surname || '';
this.email = this.email || '';
this.name = this.name ?? '';
this.surname = this.surname ?? '';
this.email = this.email ?? '';
this.roleNotSelected = !this.memberRole;
return;
}
Expand All @@ -63,21 +63,21 @@ export class NgmAddMemberForm extends LitElementI18n {
return html`
<div class="ngm-member-add-form">
<div class="ngm-input ${classMap({'ngm-input-warning': !this.name && this.name !== undefined})}">
<input type="text" placeholder="required" .value=${this.name || ''}
<input type="text" placeholder="required" .value=${this.name ?? ''}
@input=${evt => {
this.name = evt.target.value;
}}/>
<span class="ngm-floating-label">${i18next.t('project_member_name')}</span>
</div>
<div class="ngm-input ${classMap({'ngm-input-warning': !this.surname && this.surname !== undefined})}">
<input type="text" placeholder="required" .value=${this.surname || ''}
<input type="text" placeholder="required" .value=${this.surname ?? ''}
@input=${evt => {
this.surname = evt.target.value;
}}/>
<span class="ngm-floating-label">${i18next.t('project_member_surname')}</span>
</div>
<div class="ngm-input ${classMap({'ngm-input-warning': !isEmail(this.email) && this.email !== undefined})}">
<input type="email" placeholder="required" .value=${this.email || ''}
<input type="email" placeholder="required" .value=${this.email ?? ''}
@input=${evt => {
this.email = evt.target.value;
}}/>
Expand Down
4 changes: 2 additions & 2 deletions ui/src/elements/dashboard/ngm-project-topic-overview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class NgmProjectTopicOverview extends LitElementI18n {
if (!this.topicOrProject) return '';
const project = isProject(this.topicOrProject) ? this.topicOrProject : undefined;
const ownerEmail = project?.owner?.email;
const owner = ownerEmail || i18next.t('swisstopo');
const owner = ownerEmail ?? i18next.t('swisstopo');
const date = this.topicOrProject?.modified ? this.topicOrProject?.modified : this.topicOrProject?.created;
const backgroundImage = this.topicOrProject.image?.length ? `url('${this.topicOrProject.image}')` : 'none';
const editorEmails = project?.editors?.map(m => m.email) || [];
Expand Down Expand Up @@ -161,7 +161,7 @@ export class NgmProjectTopicOverview extends LitElementI18n {
@click=${() => this.duplicateToProject()}>
${i18next.t('duplicate_to_project')}
</div>
<a class="item" target="_blank" href="mailto:?body=${encodeURIComponent(this.getLink() || '')}">
<a class="item" target="_blank" href="mailto:?body=${encodeURIComponent(this.getLink() ?? '')}">
${i18next.t('dashboard_share_topic_email')}
</a>
${isProject(this.topicOrProject) && this.topicOrProject.owner.email !== this.userEmail ? '' : html`
Expand Down
4 changes: 2 additions & 2 deletions ui/src/elements/ngm-ion-modal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export class NgmIonModal extends LitElementI18n {
<div class="content-container">
<div class="ngm-ion-load-container">
<div class="ngm-input ${classMap({'ngm-input-warning': !this.token && this.token !== null})}">
<input type="text" placeholder="required" .value=${this.token || ''}
<input type="text" placeholder="required" .value=${this.token ?? ''}
@input=${evt => {
this.token = evt.target.value;
}}/>
Expand Down Expand Up @@ -133,4 +133,4 @@ export class NgmIonModal extends LitElementI18n {
// no shadow dom
return this;
}
}
}
8 changes: 4 additions & 4 deletions ui/src/elements/ngm-side-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ export class SideBar extends LitElementI18n {
}
layer.visible = urlLayer.visible;
layer.opacity = urlLayer.opacity;
layer.wmtsCurrentTime = urlLayer.timestamp || layer.wmtsCurrentTime;
layer.wmtsCurrentTime = urlLayer.timestamp ?? layer.wmtsCurrentTime;
layer.setOpacity && layer.setOpacity(layer.opacity);
layer.displayed = true;
layer.setVisibility && layer.setVisibility(layer.visible);
Expand All @@ -395,7 +395,7 @@ export class SideBar extends LitElementI18n {
type: LayerType.tiles3d,
assetId: Number(assetId),
ionToken: ionToken,
label: ionAsset?.name || assetId,
label: ionAsset?.name ?? assetId,
layer: assetId,
visible: true,
displayed: true,
Expand Down Expand Up @@ -607,12 +607,12 @@ export class SideBar extends LitElementI18n {
config = searchLayer;
config.visible = true;
config.origin = 'layer';
config.label = searchLayer.title || searchLayer.label;
config.label = searchLayer.title ?? searchLayer.label;
config.legend = config.type === LayerType.swisstopoWMTS ? config.layer : undefined;
} else {
config = {
type: LayerType.swisstopoWMTS,
label: searchLayer.title || searchLayer.label,
label: searchLayer.title ?? searchLayer.label,
layer: searchLayer.layer,
visible: true,
displayed: true,
Expand Down
8 changes: 4 additions & 4 deletions ui/src/layers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ export async function create3DVoxelsTilesetFromConfig(viewer: Viewer, config: La
});

const searchParams = new URLSearchParams(location.search);
const stepSize = parseFloat(searchParams.get('stepSize') || '1');
const stepSize = parseFloat(searchParams.get('stepSize') ?? '1');

primitive.nearestSampling = true;
primitive.stepSize = stepSize;
primitive.depthTest = true;
primitive.show = !!config.visible;
primitive.pickable = config.pickable !== undefined ? config.pickable : false;
primitive.pickable = config.pickable ?? false;
primitive.layer = config.layer;

viewer.scene.primitives.add(primitive);
Expand Down Expand Up @@ -114,7 +114,7 @@ export async function create3DTilesetFromConfig(viewer: Viewer, config: LayerCon
tileset.style = new Cesium3DTileStyle(config.style);
}

tileset.pickable = config.pickable !== undefined ? config.pickable : false;
tileset.pickable = config.pickable ?? false;
viewer.scene.primitives.add(tileset);

config.setVisibility = visible => {
Expand Down Expand Up @@ -180,7 +180,7 @@ export async function createSwisstopoWMTSImageryLayer(viewer: Viewer, config: La
}, 100);
};
viewer.scene.imageryLayers.add(layer);
layer.alpha = config.opacity || 1;
layer.alpha = config.opacity ?? 1;
layer.show = !!config.visible;
return layer;
}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/layers/ngm-layers-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export class NgmLayersItem extends LitElementI18n {
<input type="range" class="ngm-slider ${classMap({disabled: this.changeOrderActive})}" ?hidden=${this.config.opacityDisabled}
style="background-image: linear-gradient(to right, var(--ngm-interaction-active), var(--ngm-interaction-active) ${this.config.opacity! * 100}%, white ${this.config.opacity! * 100}%)"
min=0 max=1 step=0.01
.value=${this.config.opacity?.toString() || '1'}
.value=${this.config.opacity?.toString() ?? '1'}
@input=${this.inputOpacity}
@mousedown=${e => this.changeOrderActive && e.preventDefault()}>
</div>
Expand Down
2 changes: 1 addition & 1 deletion ui/src/ngm-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export class NgmApp extends LitElementI18n {

// Temporarily increasing the maximum screen space error to load low LOD tiles.
const searchParams = new URLSearchParams(document.location.search);
globe.maximumScreenSpaceError = parseFloat(searchParams.get('initialScreenSpaceError') || '2000');
globe.maximumScreenSpaceError = parseFloat(searchParams.get('initialScreenSpaceError') ?? '2000');

let currentStep = 1;
const unlisten = globe.tileLoadProgressEvent.addEventListener(queueLength => {
Expand Down
4 changes: 2 additions & 2 deletions ui/src/permalink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export function syncLayersParam(activeLayers: LayerConfig[]) {
const transparency = !l.opacity || isNaN(l.opacity) ? 0 : (1 - l.opacity);
layersTransparency.push(transparency.toFixed(2));
layersVisibility.push(!!l.visible);
layersTimestamps.push(l.wmtsCurrentTime || '');
layersTimestamps.push(l.wmtsCurrentTime ?? '');
}
});

Expand Down Expand Up @@ -329,7 +329,7 @@ export function getPermalink() {

export function getExaggeration() {
const params = getURLSearchParams();
let zExaggeration = parseFloat(params.get(EXAGGERATION_PARAM) || '1');
let zExaggeration = parseFloat(params.get(EXAGGERATION_PARAM) ?? '1');
if (zExaggeration < 1) zExaggeration = 1;
if (zExaggeration > 20) zExaggeration = 20;
return zExaggeration;
Expand Down
12 changes: 6 additions & 6 deletions ui/src/swisstopoImagery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export function getSwisstopoImagery(
.replace('{format}', swisstopoConfig.format);
imageryProvider = new UrlTemplateImageryProvider({
url: url,
maximumLevel: localConfig.maximumLevel || swisstopoConfig.maximumLevel,
maximumLevel: localConfig.maximumLevel ?? swisstopoConfig.maximumLevel,
rectangle: SWITZERLAND_RECTANGLE,
credit: new Credit(swisstopoConfig.attribution),
customTags: {
Expand Down Expand Up @@ -84,7 +84,7 @@ export function getSwisstopoImagery(
return;
}
const imageryLayer = new ImageryLayer(imageryProvider, {
alpha: localConfig.opacity !== undefined ? localConfig.opacity : 1
alpha: localConfig.opacity ?? 1
});
resolve(imageryLayer);
} else {
Expand Down Expand Up @@ -137,7 +137,7 @@ async function parseWMTSCapabilities(wmtsCapabilities: Document): Promise<Swisst
format: format.split('/')[1],
type: 'wmts',
timestamps: [],
defaultTimestamp: defaultTimestamp || undefined,
defaultTimestamp: defaultTimestamp ?? undefined,
sr: tileMatrixSet && Number(tileMatrixSet[0]),
maximumLevel: tileMatrixSet && Number(tileMatrixSet[1]),
title: titles && titles[0]?.textContent ? titles[0].textContent : layerName
Expand Down Expand Up @@ -170,8 +170,8 @@ async function parseWMSCapabilities(wmsCapabilities: Document): Promise<Swisstop
format: format,
type: 'wms',
timestamps: [],
defaultTimestamp: defaultTimestamp || undefined,
title: layerTitle || layerName
defaultTimestamp: defaultTimestamp ?? undefined,
title: layerTitle ?? layerName
};
configs[layerName].timestamps = layer.querySelector('Dimension')?.textContent?.split(',') || [];
}
Expand Down Expand Up @@ -209,7 +209,7 @@ async function fetchWMSCapabilities(lang: string) {
export async function getLayersConfig(): Promise<SwisstopoImageryLayersConfig> {
if (!layerConfigs) {
const params = getURLSearchParams();
const lang = params.get('lang') || 'en';
const lang = params.get('lang') ?? 'en';
const wmsConfig = await fetchWMSCapabilities(lang);
const wmtsConfig = await fetchWMTSCapabilities(lang);
layerConfigs = {...wmsConfig, ...wmtsConfig};
Expand Down
20 changes: 10 additions & 10 deletions ui/src/toolbox/GeometryController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,8 @@ export class GeometryController {
const type = attributes.type;
const name = type.charAt(0).toUpperCase() + type.slice(1);
const entityAttrs: Entity.ConstructorOptions = {
id: attributes.id || undefined,
name: attributes.name || `${name} ${this.geometriesCounter[type]}`,
id: attributes.id ?? undefined,
name: attributes.name ?? `${name} ${this.geometriesCounter[type]}`,
show: attributes.show,
properties: {
area: attributes.area,
Expand All @@ -468,11 +468,11 @@ export class GeometryController {
type: type,
volumeShowed: !!attributes.volumeShowed,
volumeHeightLimits: attributes.volumeHeightLimits || null,
description: attributes.description || '',
image: attributes.image || '',
website: attributes.website || '',
editable: attributes.editable === undefined ? true : attributes.editable,
copyable: attributes.copyable === undefined ? true : attributes.copyable,
description: attributes.description ?? '',
image: attributes.image ?? '',
website: attributes.website ?? '',
editable: attributes.editable ?? attributes.editable,
copyable: attributes.copyable ?? attributes.copyable,
}
};
const color = attributes.color;
Expand All @@ -484,17 +484,17 @@ export class GeometryController {
entityAttrs.position = Cartographic.toCartesian(cartPosition);
}
entityAttrs.billboard = {
image: attributes.pointSymbol || `./images/${POINT_SYMBOLS[0]}`,
image: attributes.pointSymbol ?? `./images/${POINT_SYMBOLS[0]}`,
color: color ? new Color(color.red, color.green, color.blue) : DEFAULT_AOI_COLOR,
scale: 0.5,
verticalOrigin: VerticalOrigin.BOTTOM,
disableDepthTestDistance: 0,
heightReference: HeightReference.RELATIVE_TO_GROUND
};
entityAttrs.properties!.swissforagesId = attributes.swissforagesId;
attributes.depth = attributes.depth || 400;
attributes.depth = attributes.depth ?? 400;
entityAttrs.properties!.depth = attributes.depth;
attributes.diameter = attributes.diameter || 40;
attributes.diameter = attributes.diameter ?? 40;
entityAttrs.properties!.diameter = attributes.diameter;
const height = Cartographic.fromCartesian(entityAttrs.position).height;
entityAttrs.ellipse = {
Expand Down
14 changes: 7 additions & 7 deletions ui/src/toolbox/ngm-geometry-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class NgmGeometryInfo extends LitElementI18n {
<div class="ngm-geom-info-content">
<div class="ngm-geom-description">
<div class="ngm-geom-info-label">${i18next.t('obj_info_description_label')}</div>
<div class="ngm-geom-info-value">${geom.description || ''}</div>
<div class="ngm-geom-info-value">${geom.description ?? ''}</div>
</div>
<div class="ngm-geom-img">
<div class="ngm-geom-info-label">${i18next.t('obj_info_image_label')}</div>
Expand All @@ -157,36 +157,36 @@ export class NgmGeometryInfo extends LitElementI18n {
<div ?hidden=${!geom.volumeShowed} class="ngm-geom-limits">
<div ?hidden=${geom.type === 'point'}>
<div class="ngm-geom-info-label">${i18next.t('tbx_volume_lower_limit_label')}</div>
<div class="ngm-geom-info-value">${geom.volumeHeightLimits?.lowerLimit.toFixed(1) || '-'} m</div>
<div class="ngm-geom-info-value">${geom.volumeHeightLimits?.lowerLimit.toFixed(1) ?? '-'} m</div>
</div>
<div>
<div class="ngm-geom-info-label">${i18next.t('tbx_volume_height_label')}</div>
<div class="ngm-geom-info-value">${this.getHeight(geom)} m</div>
</div>
<div ?hidden=${geom.type !== 'point'}>
<div class="ngm-geom-info-label">${i18next.t('tbx_point_depth_label')}</div>
<div class="ngm-geom-info-value">${geom.depth?.toFixed(1) || '-'} m</div>
<div class="ngm-geom-info-value">${geom.depth?.toFixed(1) ?? '-'} m</div>
</div>
</div>
<div ?hidden=${!geom.volumeShowed} class="ngm-geom-limits">
<div ?hidden=${geom.type !== 'point'}>
<div class="ngm-geom-info-label">${i18next.t('tbx_point_diameter_label')}</div>
<div class="ngm-geom-info-value">${geom.diameter?.toFixed(1) || '-'} m</div>
<div class="ngm-geom-info-value">${geom.diameter?.toFixed(1) ?? '-'} m</div>
</div>
</div>
<div ?hidden=${geom.type === 'point' || geom.type === 'line'}>
<div class="ngm-geom-info-label">${i18next.t('obj_info_area_label')}</div>
<div class="ngm-geom-info-value">${geom.area || '-'} km²</div>
<div class="ngm-geom-info-value">${geom.area ?? '-'} km²</div>
</div>
<div ?hidden=${geom.type === 'point'}>
<div class="ngm-geom-info-label">
${geom.type === 'line' ? i18next.t('obj_info_length_label') : i18next.t('obj_info_perimeter_label')}
</div>
<div class="ngm-geom-info-value">${geom.perimeter || '-'} km</div>
<div class="ngm-geom-info-value">${geom.perimeter ?? '-'} km</div>
</div>
<div ?hidden=${geom.type === 'point'}>
<div class="ngm-geom-info-label">${i18next.t('obj_info_number_segments_label')}</div>
<div class="ngm-geom-info-value">${geom.numberOfSegments || ''}</div>
<div class="ngm-geom-info-value">${geom.numberOfSegments ?? ''}</div>
</div>
<div>
${geom.pointSymbol ?
Expand Down
2 changes: 1 addition & 1 deletion ui/src/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export async function setupViewer(container: Element, rethrowRenderErrors: boole
// Position the sun the that shadows look nice
let sunDate = new Date('2018-06-21T10:00:00.000Z');
if (searchParams.has('date')) {
const betterDate = new Date(searchParams.get('date') || '');
const betterDate = new Date(searchParams.get('date') ?? '');
if (Number.isNaN(betterDate.getDate())) {
console.error(`Provided date is wrong: ${searchParams.get('date')}`);
} else {
Expand Down

0 comments on commit a2b81b6

Please sign in to comment.