From 2dedc2f2bca041a98b563088bf55547188bac86a Mon Sep 17 00:00:00 2001 From: Glauber Costa Vila Verde Date: Tue, 11 Jun 2024 16:47:11 +0000 Subject: [PATCH] feat(Enviroment-Alert): added an alert when portal running in development --- backend/common/views.py | 12 +++++-- .../src/components/AlertEnvironment/index.js | 19 ++++++++++ frontend/src/pages/PredictionEvents/Detail.js | 11 ++++++ .../src/pages/PublicPortal/Banner/index.js | 36 +------------------ frontend/src/pages/PublicPortal/Home/index.js | 19 ++++++++-- 5 files changed, 58 insertions(+), 39 deletions(-) create mode 100644 frontend/src/components/AlertEnvironment/index.js diff --git a/backend/common/views.py b/backend/common/views.py index cc90ab4f..3734c815 100755 --- a/backend/common/views.py +++ b/backend/common/views.py @@ -7,8 +7,9 @@ from django.http import HttpResponse from django.shortcuts import redirect from rest_framework.decorators import action, api_view, permission_classes +from rest_framework.permissions import AllowAny from rest_framework.response import Response -from rest_framework.permissions import AllowAny + @api_view(["GET"]) def teste(request): @@ -64,13 +65,20 @@ def test_background_task(request): ) return Response(result) + @api_view(["GET"]) @permission_classes([AllowAny]) def which_environment(request): + if request.method == "GET": - result={settings.ENVIRONMENT_NAME} + env_name = settings.ENVIRONMENT_NAME + + dev_env = ["Development", "development", "dev", "Staging", "Homolog"] + is_dev = True if env_name in dev_env else False + result = {"enviroment_name": settings.ENVIRONMENT_NAME, "is_dev": is_dev} return Response(result) + @action(detail=False, methods=["GET"]) def logout_view(request): logout(request) diff --git a/frontend/src/components/AlertEnvironment/index.js b/frontend/src/components/AlertEnvironment/index.js new file mode 100644 index 00000000..996f6e05 --- /dev/null +++ b/frontend/src/components/AlertEnvironment/index.js @@ -0,0 +1,19 @@ +import React from 'react' +import Alert from '@mui/material/Alert' +import AlertTitle from '@mui/material/AlertTitle' + +function AlertEnvironment() { + return ( + + This is a development and testing version of this platform. + Do not use its data or reference it in any way. +
+ For the official product, visit the link   + + https://solarsystem.linea.org.br. + +
+ ) +} + +export default AlertEnvironment diff --git a/frontend/src/pages/PredictionEvents/Detail.js b/frontend/src/pages/PredictionEvents/Detail.js index 316960e3..ce474173 100644 --- a/frontend/src/pages/PredictionEvents/Detail.js +++ b/frontend/src/pages/PredictionEvents/Detail.js @@ -17,6 +17,8 @@ import HelpOutlineIcon from '@mui/icons-material/HelpOutline' import { getOccultationById, getStarByOccultationId } from '../../services/api/Occultation' import PredictOccultationMap from './partials/PredictMap' import AladinV3 from '../../components/AladinV3/index' +import AlertEnvironment from '../../components/AlertEnvironment/index' +import { whichEnvironment } from '../../services/api/Auth' function PredictionEventDetail() { const { id } = useParams() @@ -25,6 +27,7 @@ function PredictionEventDetail() { const [circumstances, setCircumstances] = useState([]) const [star, setStar] = useState([]) const [object, setObject] = useState([]) + const [isDev, setIsDev] = useState(false) useEffect(() => { getOccultationById({ id }).then((res) => { @@ -37,6 +40,13 @@ function PredictionEventDetail() { ...res }) }) + whichEnvironment() + .then((res) => { + setIsDev(res.is_dev) + }) + .catch(() => { + // TODO: Aviso de erro + }) }, [id]) useEffect(() => { @@ -248,6 +258,7 @@ function PredictionEventDetail() { return ( + {isDev && } Occultation by {occultation.name} {occultation.number ? `(${occultation.number})` : ''} diff --git a/frontend/src/pages/PublicPortal/Banner/index.js b/frontend/src/pages/PublicPortal/Banner/index.js index 6a092a75..39c679de 100644 --- a/frontend/src/pages/PublicPortal/Banner/index.js +++ b/frontend/src/pages/PublicPortal/Banner/index.js @@ -1,48 +1,14 @@ -import React, { useEffect, useState } from 'react' +import React from 'react' import Grid from '@mui/material/Grid' import styles from './styles' import Box from '@mui/material/Box' -import { Alert } from '../../../../node_modules/@mui/lab/index' -import { whichEnvironment } from '../../../services/api/Auth' -//import { Typography } from '../../../../node_modules/@mui/material/index' function PublicBanner() { const classes = styles() - const [resultsDev, setResultsDev] = useState([]) - - useEffect(() => { - // Get results by year - whichEnvironment() - .then((res) => { - setResultsDev(res) - }) - .catch(() => { - setResultsDev([]) - }) - }, []) - - const verifyPage = resultsDev[0] - //const verifyPageM = verifyPage.toLowerCase() - //console.log(verifyPageM) - return ( - {verifyPage?.toLowerCase() === 'development' ? - - - {/*{verifyPage?.toLowerCase()}*/} - This is a development and testing version of this platform. Do not use its data or reference it in any way. -

For the official product, visit the link   - - https://solarsystem.linea.org.br. - -
-
- : - ' ' - } Data Release Interface

LIneA Occultation Prediction Database

diff --git a/frontend/src/pages/PublicPortal/Home/index.js b/frontend/src/pages/PublicPortal/Home/index.js index 58ffa87d..e907fb03 100644 --- a/frontend/src/pages/PublicPortal/Home/index.js +++ b/frontend/src/pages/PublicPortal/Home/index.js @@ -1,4 +1,4 @@ -import React from 'react' +import React, { useEffect, useState } from 'react' import Grid from '@mui/material/Grid' import Box from '@mui/material/Box' import Card from '@mui/material/Card' @@ -8,10 +8,24 @@ import PredictionEventsDataGrid from '../../../components/PredictionEventsDataGr import PredictionHighlights from '../../../components/PredictionHighlights/index' import PublicBanner from '../Banner/index' import Container from '@mui/material/Container' - +import { whichEnvironment } from '../../../services/api/Auth' +import AlertEnvironment from '../../../components/AlertEnvironment/index' function Main() { + const [isDev, setIsDev] = useState(false) + + useEffect(() => { + whichEnvironment() + .then((res) => { + setIsDev(res.is_dev) + }) + .catch(() => { + // TODO: Aviso de erro + }) + }, []) + return ( <> + {isDev && } @@ -26,6 +40,7 @@ function Main() {
+ {isDev && }