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

[Feat] use appName in exported image html json map and csv data #1528

Merged
merged 1 commit into from
Jul 18, 2021
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
1 change: 1 addition & 0 deletions src/components/kepler-gl.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ export const bottomWidgetSelector = (props, theme) => ({
});

export const modalContainerSelector = (props, rootNode) => ({
appName: props.appName,
mapStyle: props.mapStyle,
visState: props.visState,
mapState: props.mapState,
Expand Down
15 changes: 8 additions & 7 deletions src/components/modal-container.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {ProviderState} from 'reducers/provider-state-updaters';
import {OnSuccessCallBack} from 'actions';

export type ModalContainerProps = {
rootNode: object;
appName: string;
rootNode: React.ReactNode;
containerW: number;
containerH: number;
mapboxApiAccessToken: string;
Expand All @@ -27,12 +28,12 @@ export type ModalContainerProps = {
uiStateActions: typeof UIStateActions;
mapStyleActions: typeof MapStyleActions;
providerActions: typeof ProviderActions;
onSaveToStorage: () => void,
cloudProviders: object[],
onLoadCloudMapSuccess: OnSuccessCallBack,
onLoadCloudMapError: OnErrorCallBack,
onExportToCloudSuccess:OnSuccessCallBack,
onExportToCloudError: OnErrorCallBack
onSaveToStorage: () => void;
cloudProviders: object[];
onLoadCloudMapSuccess: OnSuccessCallBack;
onLoadCloudMapError: OnErrorCallBack;
onExportToCloudSuccess: OnSuccessCallBack;
onExportToCloudError: OnErrorCallBack;
};

export default function ModalContainerFactory(): React.Component<ModelContainerProps>;
2 changes: 1 addition & 1 deletion src/components/modal-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export default function ModalContainerFactory(

_onExportImage = () => {
if (!this.props.uiState.exportImage.processing) {
exportImage(this.props);
exportImage(this.props, `${this.props.appName}.png`);
this.props.uiStateActions.cleanupExportImage();
this._closeModal();
}
Expand Down
19 changes: 10 additions & 9 deletions src/utils/export-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ import {set, generateHashId} from 'utils/utils';
/**
* Default file names
*/
export const DEFAULT_IMAGE_NAME = 'kepler-gl.png';
export const DEFAULT_IMAGE_NAME = 'kepler.gl.png';
export const DEFAULT_HTML_NAME = 'kepler.gl.html';
export const DEFAULT_JSON_NAME = 'keplergl.json';
export const DEFAULT_DATA_NAME = 'kepler-gl';
export const DEFAULT_JSON_NAME = 'kepler.gl.json';
export const DEFAULT_DATA_NAME = 'kepler.gl';

/**
* Default json export settings
Expand Down Expand Up @@ -133,11 +133,11 @@ export function downloadFile(fileBlob, fileName) {
}
}

export function exportImage(state) {
export function exportImage(state, filename = DEFAULT_IMAGE_NAME) {
const {imageDataUri} = state.uiState.exportImage;
if (imageDataUri) {
const file = dataURItoBlob(imageDataUri);
downloadFile(file, DEFAULT_IMAGE_NAME);
downloadFile(file, filename);
}
}

Expand Down Expand Up @@ -170,7 +170,8 @@ export function exportJson(state, options = {}) {
const map = getMapJSON(state, options);

const fileBlob = new Blob([exportToJsonString(map)], {type: 'application/json'});
downloadFile(fileBlob, DEFAULT_JSON_NAME);
const fileName = state.appName ? `${state.appName}.json` : DEFAULT_JSON_NAME;
downloadFile(fileBlob, fileName);
}

export function exportHtml(state, options) {
Expand All @@ -184,15 +185,15 @@ export function exportHtml(state, options) {
};

const fileBlob = new Blob([exportMapToHTML(data)], {type: 'text/html'});
downloadFile(fileBlob, DEFAULT_HTML_NAME);
downloadFile(fileBlob, state.appName ? `${state.appName}.html` : DEFAULT_HTML_NAME);
}

export function exportData(state, option) {
const {visState} = state;
const {visState, appName} = state;
const {datasets} = visState;
const {selectedDataset, dataType, filtered} = option;
// get the selected data
const filename = DEFAULT_DATA_NAME;
const filename = appName ? appName : DEFAULT_DATA_NAME;
const selectedDatasets = datasets[selectedDataset]
? [datasets[selectedDataset]]
: Object.values(datasets);
Expand Down