Skip to content

Commit

Permalink
fixing linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
mkellogg91 committed Sep 9, 2021
1 parent 370a286 commit 13cb390
Showing 1 changed file with 103 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ interface State {
zoom: number | string;
coord: string;
mgrs: string;
utm: { northing: string; easting: string; zoneNumber: string; zoneLetter: string | undefined; zone: string };
utm: {
northing: string;
easting: string;
zoneNumber: string;
zoneLetter: string | undefined;
zone: string;
};
isCoordPopoverOpen: boolean;
prevView: string | undefined;
}
Expand All @@ -90,15 +96,11 @@ export class SetViewControl extends Component<Props, State> {
};

static getDerivedStateFromProps(nextProps: Props, prevState: State) {
const nextView = getViewString(
nextProps.center.lat,
nextProps.center.lon,
nextProps.zoom
);

const nextView = getViewString(nextProps.center.lat, nextProps.center.lon, nextProps.zoom);

const utm = convertLatLonToUTM(nextProps.center.lat, nextProps.center.lon);
const mgrs = convertLatLonToMGRS(nextProps.center.lat, nextProps.center.lon);

if (nextView !== prevState.prevView) {
return {
lat: nextProps.center.lat,
Expand All @@ -109,7 +111,7 @@ export class SetViewControl extends Component<Props, State> {
prevView: nextView,
};
}

return null;
}

Expand Down Expand Up @@ -176,14 +178,14 @@ export class SetViewControl extends Component<Props, State> {
};

_onUTMChange = (name: 'easting' | 'northing' | 'zone', evt: ChangeEvent<HTMLInputElement>) => {
let value = evt.target.value;
const value = evt.target.value;
const updateObj = { ...this.state.utm };
updateObj[name] = isNull(value) ? '' : value;
if(name === 'zone' && value.length > 0){
let zoneLetter = value.substring(value.length - 1);
let zoneNumber = value.substring(0, value.length - 1);
updateObj['zoneLetter'] = isNaN(zoneLetter) ? zoneLetter : '';
updateObj['zoneNumber'] = isNaN(zoneNumber) ? '' : zoneNumber;
if (name === 'zone' && value.length > 0) {
const zoneLetter = value.substring(value.length - 1);
const zoneNumber = value.substring(0, value.length - 1);
updateObj.zoneLetter = isNaN(zoneLetter) ? zoneLetter : '';
updateObj.zoneNumber = isNaN(zoneNumber) ? '' : zoneNumber;
}
this.setState(
{
Expand Down Expand Up @@ -216,7 +218,10 @@ export class SetViewControl extends Component<Props, State> {

this.setState({ mgrs, utm });
} else {
this.setState({ mgrs: '', utm: { northing: '', easting: '', zoneNumber: '', zoneLetter: '', zone: '' } });
this.setState({
mgrs: '',
utm: { northing: '', easting: '', zoneNumber: '', zoneLetter: '', zone: '' },
});
}
};

Expand All @@ -233,7 +238,6 @@ export class SetViewControl extends Component<Props, State> {
lat = north;
lon = east;
} catch (err) {
// eslint-disable-next-line no-console
return;
}

Expand Down Expand Up @@ -267,7 +271,6 @@ export class SetViewControl extends Component<Props, State> {
this.state.utm.zoneNumber
));
} catch (err) {
// eslint-disable-next-line no-console
return;
}

Expand Down Expand Up @@ -336,13 +339,24 @@ export class SetViewControl extends Component<Props, State> {
point = convertMGRStoLL(value);
} catch (err) {
point = undefined;
// eslint-disable-next-line no-console
}

const isInvalid = value === '' || point === undefined || (!point.north || isNaN(point.north)) || (!point.south || isNaN(point.south)) || (!point.east || isNaN(point.east)) || (!point.west || isNaN(point.west));
const error = isInvalid ? i18n.translate('xpack.maps.setViewControl.mgrsInvalid', {
defaultMessage: 'MGRS is invalid'
}) : null;
const isInvalid =
value === '' ||
point === undefined ||
!point.north ||
isNaN(point.north) ||
!point.south ||
isNaN(point.south) ||
!point.east ||
isNaN(point.east) ||
!point.west ||
isNaN(point.west);
const error = isInvalid
? i18n.translate('xpack.maps.setViewControl.mgrsInvalid', {
defaultMessage: 'MGRS is invalid',
})
: null;
return {
isInvalid,
component: (
Expand Down Expand Up @@ -382,9 +396,11 @@ export class SetViewControl extends Component<Props, State> {
}

const isInvalid = value === '' || point === undefined;
const error = isInvalid ? i18n.translate('xpack.maps.setViewControl.utmInvalidZone', {
defaultMessage: 'UTM Zone is invalid'
}) : null;
const error = isInvalid
? i18n.translate('xpack.maps.setViewControl.utmInvalidZone', {
defaultMessage: 'UTM Zone is invalid',
})
: null;
return {
isInvalid,
component: (
Expand Down Expand Up @@ -419,9 +435,11 @@ export class SetViewControl extends Component<Props, State> {
point = undefined;
}
const isInvalid = value === '' || point === undefined;
const error = isInvalid ? i18n.translate('xpack.maps.setViewControl.utmInvalidEasting', {
defaultMessage: 'UTM Easting is invalid'
}) : null;
const error = isInvalid
? i18n.translate('xpack.maps.setViewControl.utmInvalidEasting', {
defaultMessage: 'UTM Easting is invalid',
})
: null;
return {
isInvalid,
component: (
Expand Down Expand Up @@ -456,9 +474,11 @@ export class SetViewControl extends Component<Props, State> {
point = undefined;
}
const isInvalid = value === '' || point === undefined;
const error = isInvalid ? i18n.translate('xpack.maps.setViewControl.utmInvalidNorthing', {
defaultMessage: 'UTM Northing is invalid'
}) : null;
const error = isInvalid
? i18n.translate('xpack.maps.setViewControl.utmInvalidNorthing', {
defaultMessage: 'UTM Northing is invalid',
})
: null;
return {
isInvalid,
component: (
Expand All @@ -482,12 +502,21 @@ export class SetViewControl extends Component<Props, State> {
};

_renderSetViewForm() {




if(this.state.coord == COORDINATE_SYSTEM_DEGREES_DECIMAL){
var { isInvalid: isLatInvalid, component: latFormRow } = this._renderNumberFormRow({
let isLatInvalid;
let latFormRow;
let isLonInvalid;
let lonFormRow;
let isMGRSInvalid;
let mgrsFormRow;
let isUtmZoneInvalid;
let utmZoneRow;
let isUtmEastingInvalid;
let utmEastingRow;
let isUtmNorthingInvalid;
let utmNorthingRow;

if (this.state.coord === COORDINATE_SYSTEM_DEGREES_DECIMAL) {
const latRenderObject = this._renderNumberFormRow({
value: this.state.lat,
min: -90,
max: 90,
Expand All @@ -497,8 +526,11 @@ export class SetViewControl extends Component<Props, State> {
}),
dataTestSubj: 'latitudeInput',
});

var { isInvalid: isLonInvalid, component: lonFormRow } = this._renderNumberFormRow({

isLatInvalid = latRenderObject.isInvalid;
latFormRow = latRenderObject.component;

const lonRenderObject = this._renderNumberFormRow({
value: this.state.lon,
min: -180,
max: 180,
Expand All @@ -508,47 +540,57 @@ export class SetViewControl extends Component<Props, State> {
}),
dataTestSubj: 'longitudeInput',
});
}


else if(this.state.coord == COORDINATE_SYSTEM_MGRS){
var { isInvalid: isMGRSInvalid, component: mgrsFormRow } = this._renderMGRSFormRow({
isLonInvalid = lonRenderObject.isInvalid;
lonFormRow = lonRenderObject.component;
} else if (this.state.coord === COORDINATE_SYSTEM_MGRS) {
const mgrsRenderObject = this._renderMGRSFormRow({
value: this.state.mgrs,
onChange: this._onMGRSChange,
label: i18n.translate('xpack.maps.setViewControl.mgrsLabel', {
defaultMessage: 'MGRS',
}),
dataTestSubj: 'mgrsInput',
});
}

else if(this.state.coord == COORDINATE_SYSTEM_UTM){
var { isInvalid: isUtmZoneInvalid, component: utmZoneRow } = this._renderUTMZoneRow({
isMGRSInvalid = mgrsRenderObject.isInvalid;
mgrsFormRow = mgrsRenderObject.component;
} else if (this.state.coord === COORDINATE_SYSTEM_UTM) {
const utmZoneRenderObject = this._renderUTMZoneRow({
value: this.state.utm !== undefined ? this.state.utm.zone : '',
onChange: this._onUTMZoneChange,
label: i18n.translate('xpack.maps.setViewControl.utmZoneLabel', {
defaultMessage: 'UTM Zone',
}),
dataTestSubj: 'utmZoneInput',
});

var { isInvalid: isUtmEastingInvalid, component: utmEastingRow } = this._renderUTMEastingRow({

isUtmZoneInvalid = utmZoneRenderObject.isInvalid;
utmZoneRow = utmZoneRenderObject.component;

const utmEastingRenderObject = this._renderUTMEastingRow({
value: this.state.utm !== undefined ? this.state.utm.easting : '',
onChange: this._onUTMEastingChange,
label: i18n.translate('xpack.maps.setViewControl.utmEastingLabel', {
defaultMessage: 'UTM Easting',
}),
dataTestSubj: 'utmEastingInput',
});

var { isInvalid: isUtmNorthingInvalid, component: utmNorthingRow } = this._renderUTMNorthingRow({

isUtmEastingInvalid = utmEastingRenderObject.isInvalid;
utmEastingRow = utmEastingRenderObject.component;

const utmNorthingRenderObject = this._renderUTMNorthingRow({
value: this.state.utm !== undefined ? this.state.utm.northing : '',
onChange: this._onUTMNorthingChange,
label: i18n.translate('xpack.maps.setViewControl.utmNorthingLabel', {
defaultMessage: 'UTM Northing',
}),
dataTestSubj: 'utmNorthingInput',
});

isUtmNorthingInvalid = utmNorthingRenderObject.isInvalid;
utmNorthingRow = utmNorthingRenderObject.component;
}

const { isInvalid: isZoomInvalid, component: zoomFormRow } = this._renderNumberFormRow({
Expand Down Expand Up @@ -632,7 +674,15 @@ export class SetViewControl extends Component<Props, State> {
<EuiButton
size="s"
fill
disabled={isLatInvalid || isLonInvalid || isZoomInvalid || isMGRSInvalid || isUtmZoneInvalid || isUtmEastingInvalid || isUtmNorthingInvalid}
disabled={
isLatInvalid ||
isLonInvalid ||
isZoomInvalid ||
isMGRSInvalid ||
isUtmZoneInvalid ||
isUtmEastingInvalid ||
isUtmNorthingInvalid
}
onClick={this._onSubmit}
data-test-subj="submitViewButton"
>
Expand Down Expand Up @@ -689,14 +739,13 @@ function convertLatLonToUTM(lat: string | number, lon: string | number) {
norwest = 'S';
}

if(utmCoord !== "undefined"){
if (utmCoord !== 'undefined') {
utmCoord.zoneLetter = isNaN(lat) ? '' : converter.UTMLetterDesignator(lat);
utmCoord.zone = `${utmCoord.zoneNumber}${utmCoord.zoneLetter}`;
utmCoord.easting = Math.round(utmCoord.easting);
utmCoord.northing = Math.round(utmCoord.northing);
utmCoord.str = `${utmCoord.zoneNumber}${utmCoord.zoneLetter} ${utmCoord.easting}${eastwest} ${utmCoord.northing}${norwest}`;
}


return utmCoord;
}
Expand Down Expand Up @@ -736,4 +785,3 @@ function convertMGRStoUSNG(mgrs: string) {
function convertMGRStoLL(mgrs: string) {
return mgrs ? converter.USNGtoLL(convertMGRStoUSNG(mgrs)) : '';
}

0 comments on commit 13cb390

Please sign in to comment.