Chore: Fix unnecessary nullish-coalescing (#97555)

* Fix unnecessary nullish-coalescing

* Fix nullish use as per code review

* Fix other incorrect use of nullish coalescing
This commit is contained in:
Tom Ratcliffe
2024-12-11 17:34:06 +00:00
committed by GitHub
parent 084aad0b84
commit 19cc2efaf2
10 changed files with 19 additions and 19 deletions
@@ -69,8 +69,7 @@ export const CloudReceiverForm = ({ contactPoint, alertManagerSourceName, readOn
// this basically checks if we can manage the selected alert manager data source, either because it's a Grafana Managed one
// or a Mimir-based AlertManager
const isManageableAlertManagerDataSource =
!readOnly ?? !isVanillaPrometheusAlertManagerDataSource(alertManagerSourceName);
const isManageableAlertManagerDataSource = !readOnly && !isVanillaAM;
return (
<>
@@ -180,7 +180,8 @@ function StateVisualization({ ruleUID, timeRange, labels }: StateVisualizationPr
return null;
}
const numberOfTransitions = dataFrames[0]?.fields[0]?.values?.length - 1 ?? 0; // we subtract 1 as the first value is the initial state
// we subtract 1 as the first value is the initial state
const numberOfTransitions = dataFrames[0]?.fields[0]?.values?.length - 1 || 0;
return (
<>
+1 -1
View File
@@ -135,7 +135,7 @@ export class FrameState extends ElementState {
if (shiftItemsOnDuplicate) {
const { constraint, placement: oldPlacement } = element.options;
const { vertical, horizontal } = constraint ?? {};
const placement: Placement = { ...oldPlacement } ?? {};
const placement: Placement = { ...oldPlacement };
switch (vertical) {
case VerticalConstraint.Top:
@@ -8,7 +8,7 @@ import { ACTIONS_PRIORITY, DEFAULT_PRIORITY, PREFERENCES_PRIORITY } from '../val
// TODO: Clean this once ID is mandatory on nav items
function idForNavItem(navItem: NavModelItem) {
return 'navModel.' + navItem.id ?? navItem.url ?? navItem.text ?? navItem.subTitle;
return 'navModel.' + (navItem.id ?? navItem.url ?? navItem.text ?? navItem.subTitle);
}
function navTreeToActions(navTree: NavModelItem[], parents: NavModelItem[] = []): CommandPaletteAction[] {
@@ -855,7 +855,7 @@ export class DashboardMigrator {
// Update any overrides referencing the cell display mode
if (panel.fieldConfig?.overrides) {
for (const override of panel.fieldConfig.overrides) {
for (let j = 0; j < override.properties?.length ?? 0; j++) {
for (let j = 0; j < (override.properties?.length || 0); j++) {
let overrideDisplayMode = override.properties[j].value;
if (override.properties[j].id === 'custom.displayMode') {
override.properties[j].id = 'custom.cellOptions';
@@ -57,8 +57,8 @@ export const heatmapTransformer: SynchronousDataTransformerInfo<HeatmapTransform
if (config.featureToggles.transformationsVariableSupport) {
const optionsCopy = {
...options,
xBuckets: { ...options.xBuckets } ?? undefined,
yBuckets: { ...options.yBuckets } ?? undefined,
xBuckets: { ...options.xBuckets },
yBuckets: { ...options.yBuckets },
};
if (optionsCopy.xBuckets?.value) {
@@ -21,7 +21,7 @@ export const Selector = ({ refId, query, templateVariableOptions, onChange, data
inputId={`${refId}-slo-selector`}
width="auto"
allowCustomValue
value={[...SELECTORS, ...templateVariableOptions].find((s) => s.value === query?.selectorName ?? '')}
value={[...SELECTORS, ...templateVariableOptions].find((s) => s.value === query?.selectorName)}
options={[
{
label: 'Template Variables',
@@ -208,8 +208,8 @@ export class Connections {
return;
}
const x = event.pageX - parentBoundingRect.x ?? 0;
const y = event.pageY - parentBoundingRect.y ?? 0;
const x = event.pageX - (parentBoundingRect.x ?? 0);
const y = event.pageY - (parentBoundingRect.y ?? 0);
this.connectionLine.setAttribute('x2', `${x / transformScale}`);
this.connectionLine.setAttribute('y2', `${y / transformScale}`);
@@ -328,8 +328,8 @@ export class Connections {
return;
}
const x = (event.pageX - parentBoundingRect.x) / transformScale ?? 0;
const y = (event.pageY - parentBoundingRect.y) / transformScale ?? 0;
const x = (event.pageX - parentBoundingRect.x) / transformScale;
const y = (event.pageY - parentBoundingRect.y) / transformScale;
this.connectionVertex?.setAttribute('cx', `${x}`);
this.connectionVertex?.setAttribute('cy', `${y}`);
@@ -483,8 +483,8 @@ export class Connections {
return;
}
const x = (event.pageX - parentBoundingRect.x) / transformScale ?? 0;
const y = (event.pageY - parentBoundingRect.y) / transformScale ?? 0;
const x = (event.pageX - parentBoundingRect.x) / transformScale;
const y = (event.pageY - parentBoundingRect.y) / transformScale;
this.connectionVertex?.setAttribute('cx', `${x}`);
this.connectionVertex?.setAttribute('cy', `${y}`);
@@ -20,19 +20,19 @@ export function getLayersExtent(
} else if (l instanceof VectorLayer || l instanceof VectorImage) {
if (allLayers) {
// Return everything from all layers
return [l.getSource().getExtent()] ?? [];
return [l.getSource().getExtent()];
} else if (lastOnly && layer === ll.options.name) {
// Return last only for selected layer
const feat = l.getSource().getFeatures();
const featOfInterest = feat[feat.length - 1];
const geo = featOfInterest?.getGeometry();
if (geo) {
return [geo.getExtent()] ?? [];
return [geo.getExtent()];
}
return [];
} else if (!lastOnly && layer === ll.options.name) {
// Return all points for selected layer
return [l.getSource().getExtent()] ?? [];
return [l.getSource().getExtent()];
}
return [];
} else {
+1 -1
View File
@@ -137,7 +137,7 @@ export function prepareGraphableFields(
const frameFields = nullToValue(nulledFrame).fields;
for (let fieldIdx = 0; fieldIdx < frameFields?.length ?? 0; fieldIdx++) {
for (let fieldIdx = 0; fieldIdx < (frameFields?.length || 0); fieldIdx++) {
const field = frameFields[fieldIdx];
switch (field.type) {