generated from RENCI/react-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/RENCI/APSViz-UI-V3 into iss…
…ue-312-compare-mode-alert-removal # Conflicts: # src/components/map/adcirc-raster-layer.js
- Loading branch information
Showing
10 changed files
with
191 additions
and
64 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,95 @@ | ||
import { useEffect, useState } from "react"; | ||
import { useLayers } from "@context"; | ||
import { getNamespacedEnvParam } from "@utils"; | ||
import { useQuery } from '@tanstack/react-query'; | ||
import axios from 'axios'; | ||
|
||
/** | ||
* gets the default instance name for startup layers | ||
* | ||
*/ | ||
export const getDefaultInstanceName = () => { | ||
// init the return | ||
let ret_val = ''; | ||
|
||
// get the state variable that suppresses using the instance name | ||
const { | ||
defaultInstanceName | ||
} = useLayers(); | ||
|
||
// if there is a valid default instance name | ||
if (!defaultInstanceName.includes('Error') && defaultInstanceName.length) { | ||
// build the extended query string | ||
ret_val = '&instance_name=' + defaultInstanceName; | ||
} | ||
|
||
// return the query string addition | ||
return ret_val; | ||
}; | ||
|
||
/** | ||
* handles getting the default instance name | ||
* | ||
* @returns JSX.Element | ||
* @constructor | ||
*/ | ||
export const Config = () => { | ||
// get the message alert details from state | ||
const { setDefaultInstanceName } = useLayers(); | ||
|
||
// use this to trigger the data retrieval | ||
const [ dataUrl, setDataUrl ] = useState(null); | ||
|
||
/** | ||
* create a url to get the instance name | ||
*/ | ||
useEffect( () => { | ||
// get the site branding for the query string | ||
const theUrl = 'get_ui_instance_name?reset=false&site_branding=' + (window.location.href.includes('nopp') ? 'NOPP' : 'APSViz'); | ||
|
||
// set the data url. this will spawn a data request | ||
setDataUrl(getNamespacedEnvParam('REACT_APP_UI_DATA_URL') + theUrl); | ||
}, [] ); | ||
|
||
/** | ||
* grab the default instance name | ||
*/ | ||
useQuery( { | ||
// specify the data key and url to use | ||
queryKey: ['get_ui_instance_name', dataUrl], | ||
|
||
// create the function to call for data | ||
queryFn: async () => { | ||
// create the authorization header | ||
const requestOptions = { | ||
method: 'GET', | ||
headers: { Authorization: `Bearer ${ getNamespacedEnvParam('REACT_APP_UI_DATA_TOKEN') }`} | ||
}; | ||
|
||
// make the call to get the data | ||
const ret_val = await axios | ||
// make the call to get the data | ||
.get(dataUrl, requestOptions) | ||
// use the data returned | ||
.then (( response ) => { | ||
// return the data | ||
return response.data; | ||
}) | ||
.catch (( error ) => { | ||
// make sure we do not render anything | ||
return error.response.status; | ||
}); | ||
|
||
// if the retrieval did not have an issue | ||
if (typeof ret_val === 'string' && !ret_val.includes('Error')) | ||
// save the instance name value | ||
setDefaultInstanceName(ret_val); | ||
else | ||
// blank the instance name on any http or data gathering error. | ||
setDefaultInstanceName(''); | ||
|
||
// return something | ||
return true; | ||
}, refetchOnWindowFocus: false | ||
}); | ||
}; |
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 @@ | ||
export * from './config'; |
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
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
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