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

Feature/share - Creating a screenshot #99

Merged
merged 74 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
3861ed3
adding react-router-dom
PhillipsOwen Jun 12, 2024
cb2584b
adding alias for the share component
PhillipsOwen Jun 12, 2024
6f8ee9b
adding routing and separating the man app and share renderers
PhillipsOwen Jun 12, 2024
8bebe0e
changing the app name in the help
PhillipsOwen Jun 12, 2024
404cfc9
adding the component that will handle the share url
PhillipsOwen Jun 12, 2024
1751d3e
adding react to print
PhillipsOwen Jun 12, 2024
8ba926b
adding the screenshot component. still needs work...
PhillipsOwen Jun 12, 2024
c64873b
adding comments
PhillipsOwen Jun 12, 2024
2a37160
used for testing the screenshot functionality
PhillipsOwen Jun 12, 2024
c82ba62
adding use-react-screenshot for capturing a screenshot.
PhillipsOwen Jun 12, 2024
0c7d51b
changing createRef to useRef
PhillipsOwen Jun 12, 2024
6ab4d32
changing createRef to useRef
PhillipsOwen Jun 13, 2024
2a418b5
adding react-router-dom
PhillipsOwen Jun 12, 2024
36b5766
adding alias for the share component
PhillipsOwen Jun 12, 2024
ca4340a
adding routing and separating the man app and share renderers
PhillipsOwen Jun 12, 2024
7fc794c
changing the app name in the help
PhillipsOwen Jun 12, 2024
fd4a7f8
adding the component that will handle the share url
PhillipsOwen Jun 12, 2024
84890b7
adding react to print
PhillipsOwen Jun 12, 2024
75da4c1
adding the screenshot component. still needs work...
PhillipsOwen Jun 12, 2024
6613a4f
adding comments
PhillipsOwen Jun 12, 2024
565ae7c
used for testing the screenshot functionality
PhillipsOwen Jun 12, 2024
233240d
adding use-react-screenshot for capturing a screenshot.
PhillipsOwen Jun 12, 2024
bb73839
changing createRef to useRef
PhillipsOwen Jun 12, 2024
b26d31c
changing createRef to useRef
PhillipsOwen Jun 13, 2024
f1d45ba
removing unused packages
PhillipsOwen Jun 13, 2024
63b6205
moving the screenshot component up the component tree
PhillipsOwen Jun 13, 2024
f897848
Merge remote-tracking branch 'origin/feature/share-print' into featur…
PhillipsOwen Jun 13, 2024
644653d
tidying up the directory alias links
PhillipsOwen Jun 13, 2024
8aa4b48
removing html2canvas
PhillipsOwen Jun 13, 2024
8dc75b1
no longer needed
PhillipsOwen Jun 13, 2024
6ff0960
tidying up
PhillipsOwen Jun 13, 2024
340917b
tidying up
PhillipsOwen Jun 13, 2024
fe5594c
no longer needed
PhillipsOwen Jun 13, 2024
ad15d63
this isnt used anywhere
PhillipsOwen Jun 14, 2024
ef0e7cf
adding a screenshot into the tray
PhillipsOwen Jun 14, 2024
86ffcf6
adding a lint to the screenshot tray code
PhillipsOwen Jun 14, 2024
cf00f59
renaming directory name
PhillipsOwen Jun 14, 2024
eccef0d
moving screen shot button to the tray
PhillipsOwen Jun 14, 2024
86f38ef
updating the link path
PhillipsOwen Jun 14, 2024
20fa8f0
fiddling with the DOM reference
PhillipsOwen Jun 14, 2024
e9d0661
renaming files to avoid warnings, removing the tray icon for now.
PhillipsOwen Jun 14, 2024
dd6870f
making the button be an icon
PhillipsOwen Jun 14, 2024
ee779a5
removing the screen shooter from the tray
PhillipsOwen Jun 14, 2024
cdbf1fe
adding the screen shooter button the the panel
PhillipsOwen Jun 14, 2024
5c982a8
giving the file name a timestamp
PhillipsOwen Jun 14, 2024
268a44b
removing passing a component reference around
PhillipsOwen Jun 14, 2024
244d9dd
now using document.body as the reference object
PhillipsOwen Jun 14, 2024
67cdeaa
removing the screenshot button
PhillipsOwen Jun 14, 2024
8800203
restoring original functionality
PhillipsOwen Jun 14, 2024
96e4a21
final version of the screenshot component
PhillipsOwen Jun 14, 2024
9a9486d
final version of the screenshot component
PhillipsOwen Jun 14, 2024
8f36ef0
replaces use-react-screenshot with html-to-image
PhillipsOwen Jun 14, 2024
1d58d7c
adding z-order, tidying up
PhillipsOwen Jun 17, 2024
51406d6
moving to a more common area for buttons on map
PhillipsOwen Jun 17, 2024
b57fcea
creating a box of buttons for sharing
PhillipsOwen Jun 17, 2024
b9fe9f2
removing the screenshot link
PhillipsOwen Jun 17, 2024
a433ecf
refactoring/moving/adding share functionality to a button group on th…
PhillipsOwen Jun 17, 2024
79f22c2
now creating a link for sharing the view
PhillipsOwen Jun 17, 2024
14e24ff
now creating a link for sharing the view
PhillipsOwen Jun 17, 2024
da13431
making link use a hash instead
PhillipsOwen Jun 18, 2024
dd69f8e
no longer needed.
PhillipsOwen Jun 18, 2024
5b110c5
tidying up
PhillipsOwen Jun 18, 2024
5387194
removing /share route
PhillipsOwen Jun 18, 2024
d7a2755
adjusting z-indexing based on observations.
PhillipsOwen Jun 18, 2024
bead92e
Merge remote-tracking branch 'origin/main' into feature/share-print
PhillipsOwen Jun 18, 2024
9d9fbbe
adjusting z-indexing based on observations.
PhillipsOwen Jun 18, 2024
9f48efe
Merge remote-tracking branch 'origin/main' into feature/share-print
PhillipsOwen Jun 19, 2024
edfd6e8
no longer needed
PhillipsOwen Jun 19, 2024
ba94ee8
adding a faq on how to get screenshots of the app surface.
PhillipsOwen Jun 19, 2024
3648c1a
tidying up the button style
PhillipsOwen Jun 19, 2024
826b438
fixing the accordion indexes
PhillipsOwen Jun 19, 2024
e02da7f
fixing some FAQ text
PhillipsOwen Jun 19, 2024
3bf44a0
updates for share links
PhillipsOwen Jun 20, 2024
8000e31
making sure only the first shared run id is used
PhillipsOwen Jun 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"d3": "^7.8.5",
"dayjs": "^1.11.11",
"dotenv": "^16.4.5",
"html-to-image": "^1.11.11",
"leaflet": "^1.9.4",
"mapbox-gl": "^3.1.2",
"prop-types": "^15.8.1",
Expand All @@ -73,6 +74,7 @@
"react-leaflet": "^4.2.1",
"react-map-gl": "^7.1.7",
"react-query": "^3.39.3",
"react-router-dom": "^6.23.1",
"react-timeago": "^7.2.0",
"recharts": "^2.12.6"
},
Expand Down
49 changes: 38 additions & 11 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,57 @@
import React, { Fragment } from 'react';
import { BrowserRouter, Route, Routes } from "react-router-dom";
import { Map } from '@components/map';
import { ObservationDialog } from "@components/dialog/observation-dialog";
import { useLayers } from '@context';
import { Sidebar } from '@components/sidebar';
import { ControlPanel } from '@components/control-panel';
import { MapLegend } from '@components/legend';
import { Share } from '@share/share';

export const App = () => {
/**
* renders the main content
*
* @returns {JSX.Element}
* @constructor
*/
const Content = () => {
// install the selected observation list from the layer context
const {
selectedObservations
} = useLayers();
const { selectedObservations } = useLayers();

// render all the application content
return (
<Fragment>
{
// for each observation selected
selectedObservations.map (function (obs) {
// render the observation
return <ObservationDialog key={obs["station_name"]} obs={obs} />;
})
}
{
// for each observation selected
selectedObservations.map (function (obs) {
// render the observation
return <ObservationDialog key={obs["station_name"]} obs={obs} />;
})
}
<Map />
<Sidebar />
<ControlPanel/>
<MapLegend />
<Share />
</Fragment>
);
};

/**
* renders the application
*
* @returns {JSX.Element}
* @constructor
*/
export const App = () => {
// render the application
return (
<Fragment>
<BrowserRouter>
<Routes>
<Route path="/" element={ <Content/> } />
</Routes>
</BrowserRouter>
</Fragment>
);
};
2 changes: 1 addition & 1 deletion src/components/control-panel/control-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ export const ControlPanel = () => {
'&:hover': { filter: 'opacity(1.0)' },
height: 'auto',
width: '300px',
zIndex: 999,
zIndex: 401,
borderRadius: 'sm',
}}
>
Expand Down
13 changes: 9 additions & 4 deletions src/components/dialog/base-floating-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,18 @@ export default function BaseFloatingDialog({ title, dialogObject, dataKey, dataL
disableEnforceFocus
style={{ pointerEvents: 'none' }}
PaperProps={{ sx: { width: 750, height: 485, pointerEvents: 'auto'} }}
sx={{ width: 750, height: 485, '.MuiBackdrop-root': { backgroundColor: 'transparent' }}}
sx={{ zIndex: 402, width: 750, height: 485, '.MuiBackdrop-root': { backgroundColor: 'transparent' }}}
>
<DialogTitle sx={{cursor: 'move', backgroundColor: 'lightblue', textAlign: 'center', fontSize: 14, height: 35, m: 0, p: 1 }} id="draggable-dialog-title"> { title } </DialogTitle>
<DialogTitle
sx={{cursor: 'move', backgroundColor: 'lightblue', textAlign: 'center',
fontSize: 14, height: 35, m: 0, p: 1 }} id="draggable-dialog-title"> { title } </DialogTitle>

<DialogContent sx={{backgroundColor: 'white', fontSize: 14, m: 0, width: 590, height: 350 }}>{ dialogObject }</DialogContent>
<DialogContent
sx={{backgroundColor: 'white', fontSize: 14, m: 0, width: 590, height: 350 }}>{ dialogObject }</DialogContent>

<DialogActions sx={{backgroundColor: 'lightgray', height: 35, m: 0, p: 1}}><Button style={{fontSize: 14}} autoFocus onClick={ handleClose }> Close </Button></DialogActions>
<DialogActions
sx={{backgroundColor: 'lightgray', height: 35, m: 0, p: 1}}>
<Button style={{fontSize: 14}} autoFocus onClick={ handleClose }> Close </Button></DialogActions>
</Dialog>
</Fragment>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/legend/legend.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const MapLegend = () => {
height: 'auto',
width: '100px',
padding: '10px',
zIndex: 999,
zIndex: 401,
borderRadius: 'sm',
visibility: legendVisibilty,
}}
Expand Down
14 changes: 12 additions & 2 deletions src/components/map/default-layers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useLayers } from '@context';
import { useQuery } from '@tanstack/react-query';
import axios from 'axios';
import { markClicked } from '@utils/map-utils';
import { useLocation } from "react-router-dom";

const newLayerDefaultState = (layer) => {
const { product_type } = layer.properties;
Expand All @@ -23,10 +24,19 @@ const newLayerDefaultState = (layer) => {
};

export const DefaultLayers = () => {

const [obsData, setObsData] = useState("");
const map = useMap();

// get the hash location (if any)
const { hash } = useLocation();

let share_run = '';

if (hash !== '') {
share_run = '&run_id=' + hash.split('=')[1];
share_run = share_run.split(',')[0];
}

const {
defaultModelLayers,
setDefaultModelLayers,
Expand Down Expand Up @@ -88,7 +98,7 @@ export const DefaultLayers = () => {
};

// create the URLs to the data endpoints
const data_url = `${process.env.REACT_APP_UI_DATA_URL}get_ui_data_secure?limit=1&use_new_wb=true&use_v3_sp=true`;
const data_url = `${process.env.REACT_APP_UI_DATA_URL}get_ui_data_secure?limit=1&use_new_wb=true&use_v3_sp=true` + share_run;
const gs_wms_url = `${process.env.REACT_APP_GS_DATA_URL}wms`;
const gs_wfs_url = `${process.env.REACT_APP_GS_DATA_URL}`;

Expand Down
64 changes: 64 additions & 0 deletions src/components/share/buildlink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React, { Fragment } from 'react';
import { IconButton } from '@mui/joy';
import ShareRoundedIcon from '@mui/icons-material/ShareRounded';
import {useLayers} from "@context/map-context";

/**
* renders the link builder to recreate the current view elsewhere
*
* @returns {JSX.Element}
* @constructor
*/
export const BuildLink = () => {
// get the layers in state
const { defaultModelLayers } = useLayers();

/**
* create the query string that can be used to share the current view
*/
const createLink = () => {
// get the list of selected layers
const groups = defaultModelLayers
// get all the distinct groups
.filter((val, idx, self) =>
( idx === self.findIndex((t)=> ( t['group'] === val['group'] ))))
// return the group name
.map((mbr) => (
mbr['group']
))
// generate a query string
.join(',');

// check to see if there was one or more groups selected
if (groups !== '') {
// copy the link to the cut/paste buffer
copyTextToClipboard(window.location.origin + '/#share=' + groups).then();

// tell the user what just happened
alert('The share link has been copied to the clipboard.');
}
// no layers were selected on the map
else
alert('There were no layers selected.');
};

/**
* async function to copy the share link to the clipboard
*
* @param text
* @returns {Promise<void>}
*/
async function copyTextToClipboard(text) {
// wait for the copy to complete
return await navigator.clipboard.writeText(text);
}

// render the button
return (
<Fragment>
<IconButton onClick={ createLink }>Share&nbsp;
<ShareRoundedIcon color={'primary'} />
</IconButton>
</Fragment>
);
};
3 changes: 3 additions & 0 deletions src/components/share/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './share';
export * from './buildlink';
export * from './screenshot';
Loading