-
Notifications
You must be signed in to change notification settings - Fork 405
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #7585: refactor of the Print plugin as a plugins container * #7585: refactor of the Print plugin as a plugins container, restored standard components * #7585: refactor of the Print plugin as a plugins container, implemented override and removal of standard plugins * #7585: refactor of the Print plugin as a plugins container, fix in Option to correctly use properties with path * #7585: refactor of the Print plugin as a plugins container, fix for the build * #7585: refactor of the Print plugin as a plugins container, moved the Null plugin in plugins/print, removed print subplugins from product plugins.js, updated docs * Update web/client/plugins/Print.jsx Co-authored-by: Lorenzo Natali <offtherailz@gmail.com> * Update web/client/plugins/Print.jsx Co-authored-by: Lorenzo Natali <offtherailz@gmail.com> * #7585: Print plugin refactor as a plugins container, improved docs Co-authored-by: Lorenzo Natali <offtherailz@gmail.com>
- Loading branch information
1 parent
a3475e5
commit 1a3a0b5
Showing
19 changed files
with
1,019 additions
and
240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
import React, {useEffect} from "react"; | ||
import ReactDOM from "react-dom"; | ||
import expect from "expect"; | ||
|
||
import Print from "../Print"; | ||
import { getLazyPluginForTest } from './pluginsTestUtils'; | ||
import {Null} from "../print/Null"; | ||
|
||
function getByXPath(xpath) { | ||
return document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; | ||
} | ||
|
||
const initialState = { | ||
controls: { | ||
print: { | ||
enabled: true | ||
} | ||
}, | ||
print: { | ||
spec: {}, | ||
capabilities: { | ||
layouts: [], | ||
dpis: [], | ||
scales: [] | ||
} | ||
} | ||
}; | ||
|
||
const CustomComponent = ({actions}) => { | ||
useEffect(() => { | ||
actions.addParameter("custom", ""); | ||
}, []); | ||
return <div>print.mycustomplugin</div>; | ||
}; | ||
|
||
function expectDefaultItems() { | ||
expect(document.getElementById("mapstore-print-panel")).toExist(); | ||
expect(getByXPath("//*[text()='print.title']")).toExist(); | ||
expect(getByXPath("//*[text()='print.description']")).toExist(); | ||
expect(document.getElementById("print_preview")).toExist(); | ||
expect(getByXPath("//*[text()='print.sheetsize']")).toExist(); | ||
expect(getByXPath("//*[text()='print.alternatives.legend']")).toExist(); | ||
expect(getByXPath("//*[text()='print.alternatives.2pages']")).toExist(); | ||
expect(getByXPath("//*[text()='print.alternatives.landscape']")).toExist(); | ||
expect(getByXPath("//*[text()='print.alternatives.portrait']")).toExist(); | ||
expect(getByXPath("//*[text()='print.legend.font']")).toExist(); | ||
expect(getByXPath("//*[text()='print.legend.forceLabels']")).toExist(); | ||
expect(getByXPath("//*[text()='print.legend.iconsSize']")).toExist(); | ||
expect(getByXPath("//*[text()='print.legend.dpi']")).toExist(); | ||
expect(getByXPath("//*[text()='print.resolution']")).toExist(); | ||
expect(getByXPath("//*[text()='print.submit']")).toExist(); | ||
expect(document.getElementById("mapstore-print-preview-panel")).toNotExist(); | ||
} | ||
|
||
function getPrintPlugin({items = [], layers = [], preview = false} = {}) { | ||
return getLazyPluginForTest({ | ||
plugin: Print, | ||
storeState: { | ||
...initialState, | ||
browser: "good", | ||
layers, | ||
print: { | ||
pdfUrl: preview ? "http://fakepreview" : undefined, | ||
...initialState.print, | ||
map: { | ||
center: {x: 0, y: 0}, | ||
layers | ||
} | ||
} | ||
}, | ||
items | ||
}); | ||
} | ||
|
||
describe('Print Plugin', () => { | ||
beforeEach((done) => { | ||
document.body.innerHTML = '<div id="container"></div>'; | ||
setTimeout(done); | ||
}); | ||
|
||
afterEach((done) => { | ||
ReactDOM.unmountComponentAtNode(document.getElementById("container")); | ||
document.body.innerHTML = ''; | ||
setTimeout(done); | ||
}); | ||
|
||
it('default configuration', (done) => { | ||
getPrintPlugin().then(({ Plugin }) => { | ||
try { | ||
ReactDOM.render(<Plugin />, document.getElementById("container")); | ||
expectDefaultItems(); | ||
done(); | ||
} catch (ex) { | ||
done(ex); | ||
} | ||
}); | ||
}); | ||
|
||
it('default configuration with preview enabled', (done) => { | ||
getPrintPlugin({ | ||
preview: true | ||
}).then(({ Plugin }) => { | ||
try { | ||
ReactDOM.render(<Plugin />, document.getElementById("container")); | ||
expect(document.getElementById("mapstore-print-preview-panel")).toExist(); | ||
done(); | ||
} catch (ex) { | ||
done(ex); | ||
} | ||
}); | ||
}); | ||
|
||
it('default configuration with not allowed layers', (done) => { | ||
getPrintPlugin({ | ||
layers: [{visibility: true, type: "bing"}] | ||
}).then(({ Plugin }) => { | ||
try { | ||
ReactDOM.render(<Plugin />, document.getElementById("container")); | ||
expectDefaultItems(); | ||
expect(getByXPath("//*[text()='print.defaultBackground']")).toExist(); | ||
done(); | ||
} catch (ex) { | ||
done(ex); | ||
} | ||
}); | ||
}); | ||
|
||
it('custom plugin', (done) => { | ||
getPrintPlugin({items: [{ | ||
plugin: CustomComponent, | ||
target: "left-panel" | ||
}]}).then(({ Plugin }) => { | ||
try { | ||
ReactDOM.render(<Plugin />, document.getElementById("container")); | ||
expectDefaultItems(); | ||
expect(getByXPath("//*[text()='print.mycustomplugin']")).toExist(); | ||
done(); | ||
} catch (ex) { | ||
done(ex); | ||
} | ||
}); | ||
}); | ||
|
||
it('custom plugin sets initial state', (done) => { | ||
getPrintPlugin({items: [{ | ||
plugin: CustomComponent, | ||
target: "left-panel" | ||
}]}).then(({ Plugin, store }) => { | ||
try { | ||
ReactDOM.render(<Plugin />, document.getElementById("container")); | ||
expect(store.getState()?.print?.spec?.params?.custom).toNotBe(undefined); | ||
done(); | ||
} catch (ex) { | ||
done(ex); | ||
} | ||
}); | ||
}); | ||
|
||
it('custom plugin replaces existing', (done) => { | ||
getPrintPlugin({items: [{ | ||
plugin: CustomComponent, | ||
target: "name" | ||
}]}).then(({ Plugin }) => { | ||
try { | ||
ReactDOM.render(<Plugin />, document.getElementById("container")); | ||
expect(getByXPath("//*[text()='print.title']")).toNotExist(); | ||
expect(getByXPath("//*[text()='print.mycustomplugin']")).toExist(); | ||
done(); | ||
} catch (ex) { | ||
done(ex); | ||
} | ||
}); | ||
}); | ||
|
||
it('custom plugin removes existing', (done) => { | ||
getPrintPlugin({items: [{ | ||
plugin: Null, | ||
target: "name" | ||
}]}).then(({ Plugin }) => { | ||
try { | ||
ReactDOM.render(<Plugin />, document.getElementById("container")); | ||
expect(getByXPath("//*[text()='print.title']")).toNotExist(); | ||
done(); | ||
} catch (ex) { | ||
done(ex); | ||
} | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import React from "react"; | ||
import {connect} from "react-redux"; | ||
import {createPlugin, handleExpression} from "../../utils/PluginsUtils"; | ||
import {Glyphicon, Button} from "react-bootstrap"; | ||
import Spinner from 'react-spinkit'; | ||
import Message from "../../components/I18N/Message"; | ||
|
||
export const ActionButton = (props) => { | ||
const {text, actions, action, enabled, actionConfig, loading, className = ""} = props; | ||
const {glyph, buttonConfig} = actionConfig; | ||
const icon = glyph ? <Glyphicon glyph={glyph}/> : <span/>; | ||
const enable = !!handleExpression({}, {...props}, "{" + enabled + "}"); | ||
return ( | ||
<Button className={className} disabled={!enable} {...buttonConfig} style={{marginTop: "10px", marginRight: "5px"}} onClick={actions[action]}> | ||
{loading ? <Spinner spinnerName="circle" overrideSpinnerClassName="spinner" noFadeIn /> : icon} <Message msgId={text}/> | ||
</Button> | ||
); | ||
}; | ||
|
||
export default createPlugin("Action", { | ||
component: connect( | ||
(state) => ({ | ||
spec: state?.print?.spec || {}, | ||
loading: state.print && state.print.isLoading || false | ||
}) | ||
)(ActionButton), | ||
containers: { | ||
Print: { | ||
priority: 1 | ||
} | ||
} | ||
}); |
Oops, something went wrong.