Skip to content

Commit

Permalink
Fix crash: visualChannels: Cannot read property label of undefined (#…
Browse files Browse the repository at this point in the history
…1886)

Signed-off-by: Ihor Dykhta <dikhta.igor@gmail.com>

Co-authored-by: Ilya Boyandin <ilyabo@gmail.com>
  • Loading branch information
igorDykhta and ilyabo committed Aug 3, 2022
1 parent 57f77dd commit 66de62c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
18 changes: 6 additions & 12 deletions src/components/map/layer-hover-info.tsx
Expand Up @@ -169,22 +169,16 @@ const CellInfo = ({
return null;
}, [fieldsToShow, sizeField, layer, data.elevationValue]);

const colorMeasure = layer.getVisualChannelDescription('color').measure;
const sizeMeasure = layer.getVisualChannelDescription('size').measure;
return (
<tbody>
<Row name={'total points'} key="count" value={String(data.points && data.points.length)} />
{colorField && layer.visualChannels.color ? (
<Row
name={layer.getVisualChannelDescription('color').measure}
key="color"
value={colorValue || 'N/A'}
/>
{colorField && layer.visualChannels.color && colorMeasure ? (
<Row name={colorMeasure} key="color" value={colorValue || 'N/A'} />
) : null}
{sizeField && layer.visualChannels.size ? (
<Row
name={layer.getVisualChannelDescription('size').measure}
key="size"
value={elevationValue || 'N/A'}
/>
{sizeField && layer.visualChannels.size && sizeMeasure ? (
<Row name={sizeMeasure} key="size" value={elevationValue || 'N/A'} />
) : null}
</tbody>
);
Expand Down
4 changes: 2 additions & 2 deletions src/components/map/map-legend.tsx
Expand Up @@ -85,7 +85,7 @@ export const VisualChannelMetric = ({name}) => {

export type LayerSizeLegendProps = {
label: string;
name: string;
name: string | undefined;
};

/** @type {typeof import('./map-legend').LayerSizeLegend} */
Expand All @@ -96,7 +96,7 @@ export const LayerSizeLegend: React.FC<LayerSizeLegendProps> = ({label, name}) =
<span className="legend--layer_by">{label ? <FormattedMessage id={label} /> : null}</span>
<span className="legend--layer_by"> by </span>
</p>
<VisualChannelMetric name={name} />
{name && <VisualChannelMetric name={name} />}
</div>
) : null;

Expand Down
6 changes: 3 additions & 3 deletions src/layers/src/aggregation-layer.ts
Expand Up @@ -166,14 +166,14 @@ export default class AggregationLayer extends Layer {
*/
getVisualChannelDescription(key: string): VisualChannelDescription {
const channel = this.visualChannels[key];
if (!channel) return {label: '', measure: ''};
if (!channel) return {label: '', measure: undefined};
// e.g. label: Color, measure: Average of ETA
const {range, field, defaultMeasure, aggregation} = channel;
const fieldConfig = this.config[field];
const label = this.visConfigSettings[range].label;
const label = this.visConfigSettings[range]?.label;

return {
label: typeof label === 'function' ? label(this.config) : label,
label: typeof label === 'function' ? label(this.config) : label || '',
measure:
fieldConfig && aggregation
? `${this.config.visConfig[aggregation]} of ${fieldConfig.displayName ||
Expand Down
6 changes: 3 additions & 3 deletions src/layers/src/base-layer.ts
Expand Up @@ -168,7 +168,7 @@ export type VisualChannel = {

export type VisualChannelDescription = {
label: string;
measure: string;
measure: string | undefined;
};

export type ColumnPairs = {[key: string]: {pair: string; fieldPairKey: string}};
Expand Down Expand Up @@ -486,12 +486,12 @@ class Layer {
getVisualChannelDescription(key: string): VisualChannelDescription {
// e.g. label: Color, measure: Vehicle Type
const channel = this.visualChannels[key];
if (!channel) return {label: '', measure: ''};
if (!channel) return {label: '', measure: undefined};
const rangeSettings = this.visConfigSettings[channel.range];
const fieldSettings = this.config[channel.field];
const label = rangeSettings?.label;
return {
label: typeof label === 'function' ? label(this.config) : label,
label: typeof label === 'function' ? label(this.config) : label || '',
measure: fieldSettings
? fieldSettings.displayName || fieldSettings.name
: channel.defaultMeasure
Expand Down

0 comments on commit 66de62c

Please sign in to comment.