PromucFlow_constructor/app/client/src/widgets/MapWidget.tsx

220 lines
5.8 KiB
TypeScript
Raw Normal View History

2020-04-15 11:42:11 +00:00
import React from "react";
import BaseWidget, { WidgetProps, WidgetState } from "./BaseWidget";
import { WidgetType } from "constants/WidgetConstants";
import MapComponent from "components/designSystems/appsmith/MapComponent";
import { WidgetPropertyValidationType } from "utils/ValidationFactory";
import { VALIDATION_TYPES } from "constants/WidgetValidation";
import { EventType } from "constants/ActionConstants";
import { TriggerPropertiesMap } from "utils/WidgetFactory";
Use injected configuration from Nginx at runtime instead of build time (#30) * Use envsubst and nginx templates to generate nginx configs which can substitute environment variables and inject into the index.html file * Fix path in dockerfile. Add .gitignore and .env.example files. Fix nginx-linux template. * Add all environment variables. Add prefix to all environment variables. Update scripts to attempt to substitute all environment variables with the prefix * Setup dockerfile to execute a bash script. use env.example for fetching environment variables in development * Toggle features based on injected configs. Fix nginx template substitution script. * Update env.example file * Remove debug code from start-nginx.sh * Fix nginx config templates by adding quotes by default. Fix sed regex to include numerals. Toggle social login buttons on Login page based on the config. * Update rapid api environment variable name. Toggle oauth buttons based on config in SignUp page. Update .env.example to be a union of server and client environment variables * Adding a Map disabled message on Map widget * Adding links to Privacy policy and TNC * Use REACT_APP_ env variables with higher priority over injected config variables for toggling features * Update netlify.toml by commenting out the build environment variables * Remove env variables not required by the client * Remove start-storybook entry from package.json * Fix netlify.toml. Fallback algolia configs * Add contexts to netlify.toml for successful deploys. Swith to using APPSMITH_MARKETPLACE_URL as the toggle for RapidAPI feature on the client. Remove comments in nginx config templates. Fix template used in dockerfile. Co-authored-by: Satbir Singh <apple@apples-MacBook-Pro.local> Co-authored-by: Satbir Singh <satbir121@gmail.com>
2020-07-07 10:22:17 +00:00
import { getAppsmithConfigs } from "configs";
import styled from "styled-components";
2020-04-15 11:42:11 +00:00
Use injected configuration from Nginx at runtime instead of build time (#30) * Use envsubst and nginx templates to generate nginx configs which can substitute environment variables and inject into the index.html file * Fix path in dockerfile. Add .gitignore and .env.example files. Fix nginx-linux template. * Add all environment variables. Add prefix to all environment variables. Update scripts to attempt to substitute all environment variables with the prefix * Setup dockerfile to execute a bash script. use env.example for fetching environment variables in development * Toggle features based on injected configs. Fix nginx template substitution script. * Update env.example file * Remove debug code from start-nginx.sh * Fix nginx config templates by adding quotes by default. Fix sed regex to include numerals. Toggle social login buttons on Login page based on the config. * Update rapid api environment variable name. Toggle oauth buttons based on config in SignUp page. Update .env.example to be a union of server and client environment variables * Adding a Map disabled message on Map widget * Adding links to Privacy policy and TNC * Use REACT_APP_ env variables with higher priority over injected config variables for toggling features * Update netlify.toml by commenting out the build environment variables * Remove env variables not required by the client * Remove start-storybook entry from package.json * Fix netlify.toml. Fallback algolia configs * Add contexts to netlify.toml for successful deploys. Swith to using APPSMITH_MARKETPLACE_URL as the toggle for RapidAPI feature on the client. Remove comments in nginx config templates. Fix template used in dockerfile. Co-authored-by: Satbir Singh <apple@apples-MacBook-Pro.local> Co-authored-by: Satbir Singh <satbir121@gmail.com>
2020-07-07 10:22:17 +00:00
const { google } = getAppsmithConfigs();
const DisabledContainer = styled.div`
background-color: white;
height: 100%;
text-align: center;
display: flex;
flex-direction: column;
h1 {
margin-top: 15%;
margin-bottom: 10%;
color: #7c7c7c;
}
p {
color: #0a0b0e;
}
`;
2020-04-15 11:42:11 +00:00
class MapWidget extends BaseWidget<MapWidgetProps, WidgetState> {
static getPropertyValidationMap(): WidgetPropertyValidationType {
return {
defaultMarkers: VALIDATION_TYPES.MARKERS,
isDisabled: VALIDATION_TYPES.BOOLEAN,
isVisible: VALIDATION_TYPES.BOOLEAN,
enableSearch: VALIDATION_TYPES.BOOLEAN,
enablePickLocation: VALIDATION_TYPES.BOOLEAN,
allowZoom: VALIDATION_TYPES.BOOLEAN,
zoomLevel: VALIDATION_TYPES.NUMBER,
// onMarkerClick: VALIDATION_TYPES.ACTION_SELECTOR,
// onCreateMarker: VALIDATION_TYPES.ACTION_SELECTOR,
2020-04-15 11:42:11 +00:00
};
}
static getTriggerPropertyMap(): TriggerPropertiesMap {
return {
onMarkerClick: true,
onCreateMarker: true,
};
}
2020-04-17 16:15:09 +00:00
static getDefaultPropertiesMap(): Record<string, string> {
return {
markers: "defaultMarkers",
center: "mapCenter",
};
}
static getMetaPropertiesMap(): Record<string, undefined> {
return {
center: undefined,
markers: undefined,
};
}
2020-05-07 10:51:37 +00:00
updateCenter = (lat: number, long: number) => {
this.updateWidgetMetaProperty("center", { lat, long });
2020-04-15 11:42:11 +00:00
};
2020-05-07 10:51:37 +00:00
updateMarker = (lat: number, long: number, index: number) => {
2020-04-29 10:29:02 +00:00
const markers: Array<MarkerProps> = [...this.props.markers];
2020-05-07 10:51:37 +00:00
this.disableDrag(false);
2020-04-29 10:29:02 +00:00
this.updateWidgetMetaProperty(
"markers",
markers.map((marker, i) => {
if (index === i) {
marker.lat = lat;
2020-05-07 10:51:37 +00:00
marker.long = long;
2020-04-29 10:29:02 +00:00
}
return marker;
}),
);
};
2020-05-07 10:51:37 +00:00
onCreateMarker = (lat: number, long: number) => {
this.disableDrag(true);
this.updateWidgetMetaProperty("selectedMarker", {
lat: lat,
long: long,
});
2020-04-15 11:42:11 +00:00
if (this.props.onCreateMarker) {
super.executeAction({
dynamicString: this.props.onCreateMarker,
event: {
type: EventType.ON_CREATE_MARKER,
},
});
}
};
2020-05-07 10:51:37 +00:00
onMarkerClick = (lat: number, long: number, title: string) => {
2020-04-15 11:42:11 +00:00
this.updateWidgetMetaProperty("selectedMarker", {
lat: lat,
2020-05-07 10:51:37 +00:00
long: long,
2020-04-15 11:42:11 +00:00
title: title,
});
2020-05-07 10:51:37 +00:00
this.disableDrag(true);
2020-04-15 11:42:11 +00:00
if (this.props.onMarkerClick) {
super.executeAction({
dynamicString: this.props.onMarkerClick,
event: {
type: EventType.ON_MARKER_CLICK,
},
});
}
};
2020-04-17 16:15:09 +00:00
// componentDidMount() {
// super.componentDidMount();
// if (this.props.mapCenter) {
// this.updateWidgetMetaProperty("center", this.props.mapCenter);
// }
// }
//
// componentDidUpdate(prevProps: MapWidgetProps) {
// super.componentDidUpdate(prevProps);
// if (
// this.props.mapCenter &&
// prevProps.mapCenter &&
// (this.props.mapCenter.lat !== prevProps.mapCenter.lat ||
// this.props.mapCenter.lng !== prevProps.mapCenter.lng)
// ) {
// this.updateWidgetMetaProperty("center", this.props.mapCenter);
// }
// }
2020-04-15 11:42:11 +00:00
getPageView() {
return (
Use injected configuration from Nginx at runtime instead of build time (#30) * Use envsubst and nginx templates to generate nginx configs which can substitute environment variables and inject into the index.html file * Fix path in dockerfile. Add .gitignore and .env.example files. Fix nginx-linux template. * Add all environment variables. Add prefix to all environment variables. Update scripts to attempt to substitute all environment variables with the prefix * Setup dockerfile to execute a bash script. use env.example for fetching environment variables in development * Toggle features based on injected configs. Fix nginx template substitution script. * Update env.example file * Remove debug code from start-nginx.sh * Fix nginx config templates by adding quotes by default. Fix sed regex to include numerals. Toggle social login buttons on Login page based on the config. * Update rapid api environment variable name. Toggle oauth buttons based on config in SignUp page. Update .env.example to be a union of server and client environment variables * Adding a Map disabled message on Map widget * Adding links to Privacy policy and TNC * Use REACT_APP_ env variables with higher priority over injected config variables for toggling features * Update netlify.toml by commenting out the build environment variables * Remove env variables not required by the client * Remove start-storybook entry from package.json * Fix netlify.toml. Fallback algolia configs * Add contexts to netlify.toml for successful deploys. Swith to using APPSMITH_MARKETPLACE_URL as the toggle for RapidAPI feature on the client. Remove comments in nginx config templates. Fix template used in dockerfile. Co-authored-by: Satbir Singh <apple@apples-MacBook-Pro.local> Co-authored-by: Satbir Singh <satbir121@gmail.com>
2020-07-07 10:22:17 +00:00
<>
{!google.enabled && (
<DisabledContainer>
<h1>{"Map Widget disabled"}</h1>
<p>
{"Map widget requires a Google Maps "}
<a
target="_blank"
rel="noopener noreferrer"
href="https://developers.google.com/maps/documentation/javascript/get-api-key"
>
API Key
</a>
</p>
<p>{"Refer our Docs to configure API Keys"}</p>
</DisabledContainer>
)}
{google.enabled && (
<MapComponent
widgetId={this.props.widgetId}
isVisible={this.props.isVisible}
zoomLevel={this.props.zoomLevel}
allowZoom={this.props.allowZoom}
center={this.props.center || this.props.mapCenter}
enableCreateMarker
selectedMarker={this.props.selectedMarker}
updateCenter={this.updateCenter}
isDisabled={this.props.isDisabled}
enableSearch={this.props.enableSearch}
enablePickLocation={this.props.enablePickLocation}
saveMarker={this.onCreateMarker}
updateMarker={this.updateMarker}
selectMarker={this.onMarkerClick}
markers={this.props.markers || []}
disableDrag={() => {
this.disableDrag(false);
}}
/>
)}
</>
2020-04-15 11:42:11 +00:00
);
}
getWidgetType(): WidgetType {
return "MAP_WIDGET";
}
}
export interface MarkerProps {
lat: number;
2020-05-07 10:51:37 +00:00
long: number;
2020-04-15 11:42:11 +00:00
title?: string;
description?: string;
}
export interface MapWidgetProps extends WidgetProps {
isDisabled?: boolean;
isVisible?: boolean;
enableSearch: boolean;
zoomLevel: number;
allowZoom: boolean;
enablePickLocation: boolean;
mapCenter: {
lat: number;
2020-05-07 10:51:37 +00:00
long: number;
2020-04-15 11:42:11 +00:00
};
center?: {
lat: number;
2020-05-07 10:51:37 +00:00
long: number;
2020-04-15 11:42:11 +00:00
};
defaultMarkers?: Array<MarkerProps>;
markers?: Array<MarkerProps>;
2020-04-29 10:29:02 +00:00
selectedMarker?: {
lat: number;
long: number;
title?: string;
};
2020-04-15 11:42:11 +00:00
onMarkerClick?: string;
onCreateMarker?: string;
}
export default MapWidget;