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

203 lines
5.3 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";
import * as Sentry from "@sentry/react";
2020-10-06 09:01:51 +00:00
import withMeta, { WithMeta } from "./MetaHOC";
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,
};
}
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-10-06 09:01:51 +00:00
selectedMarker: undefined,
};
}
2020-05-07 10:51:37 +00:00
updateCenter = (lat: number, long: number) => {
2020-10-06 09:01:51 +00:00
this.props.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) => {
const markers: Array<MarkerProps> = [...(this.props.markers || [])].map(
2020-10-06 09:01:51 +00:00
(marker, i) => {
2020-04-29 10:29:02 +00:00
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-10-06 09:01:51 +00:00
},
2020-04-29 10:29:02 +00:00
);
2020-10-06 09:01:51 +00:00
this.disableDrag(false);
this.props.updateWidgetMetaProperty("markers", markers);
2020-04-29 10:29:02 +00:00
};
2020-05-07 10:51:37 +00:00
onCreateMarker = (lat: number, long: number) => {
this.disableDrag(true);
2020-10-06 16:47:16 +00:00
this.props.updateWidgetMetaProperty(
"selectedMarker",
{
lat,
long,
},
{
2020-04-15 11:42:11 +00:00
dynamicString: this.props.onCreateMarker,
event: {
type: EventType.ON_CREATE_MARKER,
},
2020-10-06 16:47:16 +00:00
},
);
2020-04-15 11:42:11 +00:00
};
2020-05-07 10:51:37 +00:00
onMarkerClick = (lat: number, long: number, title: string) => {
2020-10-06 09:01:51 +00:00
this.disableDrag(true);
const selectedMarker = {
2020-04-15 11:42:11 +00:00
lat: lat,
2020-05-07 10:51:37 +00:00
long: long,
2020-04-15 11:42:11 +00:00
title: title,
2020-10-06 09:01:51 +00:00
};
2020-10-06 16:47:16 +00:00
this.props.updateWidgetMetaProperty("selectedMarker", selectedMarker, {
dynamicString: this.props.onMarkerClick,
event: {
type: EventType.ON_MARKER_CLICK,
},
});
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 API Key"}</p>
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
<p>
{"See our"}
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
<a
target="_blank"
rel="noopener noreferrer"
href="https://docs.appsmith.com/third-party-services/google-maps"
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
>
{" documentation "}
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
</a>
{"to configure API Keys"}
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
</p>
</DisabledContainer>
)}
{google.enabled && (
<MapComponent
apiKey={google.apiKey}
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
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;
}
2020-10-06 09:01:51 +00:00
export interface MapWidgetProps extends WidgetProps, WithMeta {
2020-04-15 11:42:11 +00:00
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;
2020-10-06 09:01:51 +00:00
export const ProfiledMapWidget = Sentry.withProfiler(withMeta(MapWidget));