Skip to content

Commit

Permalink
enhancement/api-report-download (#221)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJJackson authored May 31, 2024
1 parent e14ad29 commit 6714720
Show file tree
Hide file tree
Showing 22 changed files with 320 additions and 146 deletions.
1 change: 1 addition & 0 deletions .env.production
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ VITE_CROSS_SECTION=true
VITE_DEVELOPMENT_BANNER=false
VITE_API_URL=https://midas.sec.usace.army.mil/api
VITE_URL_BASE_PATH=/midas
VITE_REPORT_DOWNLOAD=false
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ VITE_CROSS_SECTION=true
VITE_DEVELOPMENT_BANNER=false
VITE_API_URL=https://midas-test.cwbi.us/api
VITE_URL_BASE_PATH=/midas
VITE_REPORT_DOWNLOAD=false
1 change: 1 addition & 0 deletions .github/workflows/develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
VITE_INSTRUMENT_CHART: true
VITE_CROSS_SECTION: true
VITE_DEVELOPMENT_BANNER: true
VITE_REPORT_DOWNLOAD: false
VITE_API_URL: https://develop-midas-api.rsgis.dev
VITE_URL_BASE_PATH: ''
runs-on: ubuntu-latest
Expand Down
38 changes: 38 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"@iconify/utils": "^2.1.22",
"@mui/icons-material": "^5.14.0",
"@mui/material": "^5.14.2",
"@tanstack/react-query": "^5.36.2",
"@tanstack/react-table": "^8.9.3",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
Expand Down
10 changes: 9 additions & 1 deletion src/app-bundles/create-auth-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ const createAuthBundle = (opts) => {
type: 'AUTH_LOGGED_IN',
payload: { token: token, error: null, shouldVerifyToken: true },
});
sessionStorage.setItem('accessToken', token);
} else {
const url = store.selectAuthUrl();
//@todo move to fetch api at some point
try {
xhr(url, (err, response, body) => {
if (err) {
Expand All @@ -68,6 +68,7 @@ const createAuthBundle = (opts) => {
type: 'AUTH_LOGGED_IN',
payload: { token: token, error: null, shouldVerifyToken: true },
});
sessionStorage.setItem('accessToken', token);
}
});
} catch (err) {
Expand All @@ -82,11 +83,18 @@ const createAuthBundle = (opts) => {
},

doAuthLogout: () => ({ dispatch, store }) => {
const isMock = store.selectAuthIsMocked();

if (store.selectAuthTokenRaw()) {
dispatch({
type: 'AUTH_LOGGED_OUT',
payload: { token: null, error: null },
});

if (!isMock) {
sessionStorage.removeItem('accessToken');
}

store.doRemoveProfile();
const redirect = store.selectAuthRedirectOnLogout();
if (redirect) store.doUpdateRelativeUrl(redirect);
Expand Down
37 changes: 22 additions & 15 deletions src/app-bundles/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,19 @@ const mockTokenApplicationAdmin =
// const mockTokenProjectMember =
// 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI0IiwibmFtZSI6IlVzZXIuUHJvamVjdE1lbWJlciIsImlhdCI6MTUxNjIzOTAyMiwiZXhwIjoyMDAwMDAwMDAwLCJyb2xlcyI6W119.ujBvw9bCksuSbXGJreIpdXZcVIHtb8GhgviBTvrO9AQ';

// const jwtPaths = [
// '/members',
// '/datalogger',
// '/report_configs',
// ];
const inclusionPaths = [
'/instruments',
'/instrument_groups',
'/collection_groups',
'/domains',
'/timeseries',
];

const exactPaths = [
'/home',
'/projects',
'/districts',
]

export default composeBundles(
createAuthBundle({
Expand All @@ -98,16 +106,15 @@ export default composeBundles(
unless: {
// Example Scenario:
//
// GET requests do not include token unless path starts with /my_ or includes any path in the jwtPaths array.
// custom: ({ method, path }) => {
// if (method === 'GET') {
// if (path.slice(0, 4) === '/my_' || jwtPaths.some(el => path.includes(el))) {
// return false;
// }
// return true;
// }
// return false;
// },
// GET requests do not include token unless path is in the nonTokenPaths array.
custom: ({ method, path }) => {
if (method === 'GET') {
if (inclusionPaths.some(el => path.includes(el)) || exactPaths.some(el => path === el)) {
return true;
}
}
return false;
},
},
}),
createCacheBundle({
Expand Down
23 changes: 0 additions & 23 deletions src/app-bundles/report-configurations-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export default {
getReducer: () => {
const initialState = {
projectConfigs: [],
downloads: [],
};

return (state = initialState, { type, payload }) => {
Expand All @@ -13,11 +12,6 @@ export default {
...state,
projectConfigs: payload,
};
case 'UPDATE_REPORT_CONFIGURATIONS_DOWNLOADS':
return {
...state,
downloads: payload,
};
default:
return state;
}
Expand Down Expand Up @@ -45,23 +39,6 @@ export default {
});
},

doFetchReportConfigurationDownloads: ({ reportConfigId }) => ({ dispatch, store, apiGet }) => {
const projectId = store.selectProjectsIdByRoute()?.projectId;
const uri = `/projects/${projectId}/report_configs/${reportConfigId}/downloads`;

apiGet(uri, (err, body) => {
if (err) {
// eslint-disable-next-line no-console
console.log('todo', err);
} else {
dispatch({
type: 'UPDATE_REPORT_CONFIGURATIONS_DOWNLOADS',
payload: body,
});
}
});
},

doCreateNewReportConfiguration: (data) => ({ store, apiPost }) => {
const projectId = store.selectProjectsIdByRoute()?.projectId;
const uri = `/projects/${projectId}/report_configs`;
Expand Down
4 changes: 2 additions & 2 deletions src/app-components/hero/hero.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
justify-content: space-between;

.logo-left {
margin-top: 95px;
margin-left: 15px;
margin-top: 108px;
margin-left: 35px;
}

.logo-right {
Expand Down
4 changes: 2 additions & 2 deletions src/app-pages/help/apiHelp.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const ApiHelp = () => (
</p>
<hr />
<div>
<p className='text-primary'>Click the link below to view the Swagger Documentation for the API:</p>
<a href={`${apiURL}/swagger/index.html`} target='_blank' rel='noreferrer'>{apiURL}/swagger/index.html</a>
<p className='text-primary'>Click the link below to view the Documentation for the API:</p>
<a href={`${apiURL}/docs`} target='_blank' rel='noreferrer'>{apiURL}/docs</a>
</div>
</Card.Body>
</Card>
Expand Down
28 changes: 16 additions & 12 deletions src/app-pages/instrument/details.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,23 @@ export default connect(
</div>
</div>
</section>
<section className='container-fluid mt-4'>
<Settings />
</section>
{isShapeArray && (
<section className='container-fluid my-4'>
<SaaDepthBasedPlots />
</section>
)}
{isIPI && (
<section className='container-fluid my-4'>
<IpiDepthBasedPlots />
<RoleFilter
allowRoles={[`${project.slug.toUpperCase()}.*`]}
>
<section className='container-fluid mt-4'>
<Settings />
</section>
)}
{isShapeArray && (
<section className='container-fluid my-4'>
<SaaDepthBasedPlots />
</section>
)}
{isIPI && (
<section className='container-fluid my-4'>
<IpiDepthBasedPlots />
</section>
)}
</RoleFilter>
<section className='container-fluid my-4'>
<Notes />
</section>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const BatchPlotErrors = ({
if (!found || found?.x?.length) return;

const ts = timeseries.find(data => data.id === el);
const {instrument, name, unit } = ts;
const { instrument, name, unit } = ts || {};

emptyDataSets.push(`${instrument} - ${name} (${unit})`);
});
Expand Down
7 changes: 6 additions & 1 deletion src/app-pages/project/batch-plotting/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ export const generateNewChartData = (measurements, timeseries, chartSettings, pl
name,
unit,
parameter,
} = timeseries.find(t => t.id === timeseries_id);
} = timeseries.find(t => t.id === timeseries_id) || {};

if (!instrument) {
console.error('Error: timeseries id (%s) does not exist in `timeseries` array.', String(timeseries_id));

Check warning on line 41 in src/app-pages/project/batch-plotting/helper.js

View workflow job for this annotation

GitHub Actions / build (16.x)

Unexpected console statement
return;
}

const filteredItems = items.filter(item => {
const { masked, validated } = item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const BatchPlotAdvancedSettings = connect(
/>
</div>
</Accordion.Item>
<Accordion.Item headingText='Secondary Y-Axis'>
<Accordion.Item headingText='Y-Axis Configuration'>
<div className='p-3 border-bottom'>
{/* Secondary Y-Axis: Name | Parameter to fill | on/off */}
<SecondaryAxis
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useState } from 'react';
import { Button, FormControl, Input, InputLabel, MenuItem, Select } from '@mui/material';
import { Button, Divider, FormControl, Input, InputLabel, MenuItem, Select } from '@mui/material';

Check warning on line 2 in src/app-pages/project/batch-plotting/modals/components/SecondaryAxis.jsx

View workflow job for this annotation

GitHub Actions / build (16.x)

'Divider' is defined but never used
import { connect } from 'redux-bundler-react';

const generateTimeseriesOptions = (timeseriesIds = [], timeseries = []) => {
Expand All @@ -26,14 +26,15 @@ const SecondaryAxis = connect(
doBatchPlotConfigurationsSave,
}) => {
const [axisSettings, setAxisSettings] = useState({
title: plotConfig?.display?.layout?.secondary_axis_title,
primaryTitle: plotConfig?.display?.layout?.yaxis_title || 'Measurement',
secondaryTitle: plotConfig?.display?.layout?.secondary_axis_title,
timeseriesIds: plotConfig?.display?.traces?.filter(trace => trace.y_axis === 'y2').map(el => el.timeseries_id) || [],
});
const chartTimeseriesIds = chartData?.map(d => d.timeseriesId);
const timeseriesOptions = generateTimeseriesOptions(chartTimeseriesIds, timeseries);

const saveSecondaryAxisSettings = () => {
const { title, timeseriesIds } = axisSettings;
const { primaryTitle, secondaryTitle, timeseriesIds } = axisSettings;

const newTraces = plotConfig.display.traces.map(trace => {
let axis = 'y1';
Expand All @@ -52,7 +53,8 @@ const SecondaryAxis = connect(
...plotConfig.display,
layout: {
...plotConfig.display.layout,
secondary_axis_title: title,
yaxis_title: primaryTitle,
secondary_axis_title: secondaryTitle,
},
traces: newTraces,
},
Expand All @@ -61,16 +63,26 @@ const SecondaryAxis = connect(

return (
<>
<span>
<FormControl fullWidth className='mt-3'>
<InputLabel htmlFor='primary-axis-title'>Primary Axis Title</InputLabel>
<Input
id='primary-axis-title'
type='text'
value={axisSettings.primaryTitle}
onChange={e => setAxisSettings(prev => ({ ...prev, primaryTitle: e.target.value }))}
/>
</FormControl>
<hr className='' />
<i style={{ fontSize: '14px' }}>
Fill in the information below to apply timeseries to a secondary axis on the batch plot. If no timeseries are provided, the secondary axis will not be displayed on the plot.
</span>
</i>
<FormControl fullWidth className='mt-3'>
<InputLabel htmlFor='axis-title'>Secondary Axis Title</InputLabel>
<InputLabel htmlFor='secondary-axis-title'>Secondary Axis Title</InputLabel>
<Input
id='axis-title'
id='secondary-axis-title'
type='text'
value={axisSettings.title}
onChange={e => setAxisSettings(prev => ({ ...prev, title: e.target.value }))}
value={axisSettings.secondaryTitle}
onChange={e => setAxisSettings(prev => ({ ...prev, secondaryTitle: e.target.value }))}
/>
</FormControl>
<FormControl fullWidth className='mt-3'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const BatchPlotChart = connect(
mirror: true,
},
yaxis: {
title: 'Measurement',
title: plotConfig?.display?.layout?.yaxis_title || 'Measurement',
showline: true,
mirror: true,
domain: [0, withPrecipitation ? 0.66 : 1],
Expand Down
Loading

0 comments on commit 6714720

Please sign in to comment.