Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] visualChannels: Cannot read property label of undefined #1886

Merged
merged 1 commit into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/components/map/layer-hover-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,22 +166,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 @@ -482,12 +482,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