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

Users/v pnizetic/improvements fixes #104

Merged
merged 4 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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 @@ -17,6 +17,7 @@
"react": "^17.0.2",
"react-azure-maps": "^0.4.4",
"react-dom": "^17.0.2",
"react-hot-toast": "^2.4.1",
"react-i18next": "^11.18.6",
"react-id-generator": "^3.0.2",
"react-json-view": "^1.21.3",
Expand Down
26 changes: 17 additions & 9 deletions src/common/api/conversions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,20 @@ const getTilesets = () => {
return fetch(url);
};

export const getAllData = () =>
Promise.all([getUploads(), getConversions(), getDatasets(), getTilesets()])
.then(re => Promise.all([re[0].json(), re[1].json(), re[2].json(), re[3].json()]))
.then(([uploads, conversions, datasets, tilesets]) => ({
...uploads,
...conversions,
...datasets,
...tilesets,
}));
export const getExistingConversions = async () => {
const responses = await Promise.all([getUploads(), getConversions(), getDatasets(), getTilesets()]);

if (responses.some(res => res.status !== 200)) {
return { error: true };
}

const [uploads, conversions, datasets, tilesets] = await Promise.all(responses.map(res => res.json()));

return {
error: false,
...uploads,
...conversions,
...datasets,
...tilesets,
};
};
10 changes: 5 additions & 5 deletions src/common/store/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export { getDomain, useUserStore } from './user.store';
export { useResponseStore } from './response.store';
export { progressBarSteps, progressBarStepsByKey, useCompletedSteps, useProgressBarStore } from './progress-bar-steps';
export { conversionSteps, useConversionStore } from './conversion.store';
export { useDissolvedExterior, useGeometryStore } from './geometry.store';
export { useLayersStore } from './layers.store';
export { useLevelsStore } from './levels.store';
export { useReviewManifestJson, useReviewManifestStore } from './review-manifest.store';
export { useConversionStore, conversionSteps } from './conversion.store';
export { progressBarSteps, progressBarStepsByKey, useCompletedSteps, useProgressBarStore } from './progress-bar-steps';
export { resetStores } from './reset';
export { LRO_STATUS, useResponseStore } from './response.store';
export { useReviewManifestJson, useReviewManifestStore } from './review-manifest.store';
export { getDomain, useUserStore } from './user.store';
1 change: 1 addition & 0 deletions src/common/translations/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const en = {
feedback: 'Feedback',
'feedback.link': 'Feedback link',
'filter.by.name': 'Filter by name',
'filter.by.description': 'Filter by description',
geography: 'Geography',
'file.name': 'File name',
'geography.europe': 'Europe',
Expand Down
13 changes: 1 addition & 12 deletions src/components/bread-crumb-nav/bread-crumb-nav.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
import { Breadcrumb } from '@fluentui/react/lib/Breadcrumb';
import { PATHS, ROUTE_NAME_BY_PATH } from 'common/constants';
import { getSplitPaths } from 'common/functions';
import { useConversionStore, useUserStore } from 'common/store';
import { useEffect } from 'react';
import { useConversionStore } from 'common/store';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom';
import { shallow } from 'zustand/shallow';
import { breadcrumbStyle } from './bread-crumb-nav.style';

const routesReset = [PATHS.CONVERSION];

const userStoreSelector = s => [s.subscriptionKey];

const BreadCrumbNav = () => {
const { t } = useTranslation();
const navigate = useNavigate();
const { pathname: currentPath } = useLocation();
const [subKey] = useUserStore(userStoreSelector, shallow);

const splitPaths = getSplitPaths(currentPath);
const itemsWithHeading = [];

useEffect(() => {
if (!subKey) {
navigate(PATHS.INDEX, { replace: true });
}
}, [navigate, currentPath, subKey]);

splitPaths.forEach(nextPath => {
if (ROUTE_NAME_BY_PATH.hasOwnProperty(nextPath)) {
itemsWithHeading.push({
Expand Down
12 changes: 12 additions & 0 deletions src/components/route/__snapshots__/route.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Object {

<body>
<div>
<div
style="position: fixed; z-index: 9999; top: 16px; left: 16px; right: 16px; bottom: 16px; pointer-events: none;"
/>
<div>
TopBar
</div>
Expand Down Expand Up @@ -60,6 +63,9 @@ Object {
}

<div>
<div
style="position: fixed; z-index: 9999; top: 16px; left: 16px; right: 16px; bottom: 16px; pointer-events: none;"
/>
<div>
TopBar
</div>
Expand Down Expand Up @@ -158,6 +164,9 @@ Object {

<body>
<div>
<div
style="position: fixed; z-index: 9999; top: 16px; left: 16px; right: 16px; bottom: 16px; pointer-events: none;"
/>
<div>
TopBar
</div>
Expand Down Expand Up @@ -199,6 +208,9 @@ Object {
}

<div>
<div
style="position: fixed; z-index: 9999; top: 16px; left: 16px; right: 16px; bottom: 16px; pointer-events: none;"
/>
<div>
TopBar
</div>
Expand Down
44 changes: 31 additions & 13 deletions src/components/route/route.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,36 @@
import { useTranslation } from 'react-i18next';
import PropTypes from 'prop-types';
import { cx } from '@emotion/css';
import { PATHS } from 'common';
import { LRO_STATUS, progressBarSteps, useResponseStore, useUserStore } from 'common/store';
import PropTypes from 'prop-types';
import { useEffect, useMemo } from 'react';
import { Toaster } from 'react-hot-toast';
import { useTranslation } from 'react-i18next';
import { useLocation, useNavigate } from 'react-router-dom';

import BreadCrumbNav from '../bread-crumb-nav/bread-crumb-nav';
import Footer from '../footer/footer';
import TopBar from '../top-bar/top-bar';
import ProgressBar from '../progress-bar/progress-bar';
import { routeStyle, footerPadding } from './route.style';
import { useResponseStore, LRO_STATUS } from 'common/store/response.store';
import { PATHS } from 'common';
import { progressBarSteps } from 'common/store';
import TopBar from '../top-bar/top-bar';
import { footerPadding, routeStyle } from './route.style';

const responseStoreSelector = s => s.lroStatus;
const userStoreSelector = s => s.subscriptionKey;

const Route = ({ title, component: Component, dataRequired }) => {
const { t } = useTranslation();
const navigate = useNavigate();
const { pathname } = useLocation();
const { pathname: currentPath } = useLocation();

const lroStatus = useResponseStore(responseStoreSelector);
const subKey = useUserStore(userStoreSelector);

const shouldShowFooter = useMemo(
() => progressBarSteps.findIndex(route => route.href === pathname) !== -1,
[pathname]
);
const shouldShowFooter = useMemo(() => {
return progressBarSteps.findIndex(route => route.href === currentPath) !== -1;
}, [currentPath]);

useEffect(() => {
// Redirect to index if there is no subscription key
if (!subKey) navigate(PATHS.INDEX, { replace: true });
}, [navigate, currentPath, subKey]);

useEffect(() => {
if (dataRequired && lroStatus !== LRO_STATUS.SUCCEEDED && lroStatus !== LRO_STATUS.FETCHING_DATA) {
Expand All @@ -34,6 +40,18 @@ const Route = ({ title, component: Component, dataRequired }) => {

return (
<>
<Toaster
position="bottom-center"
toastOptions={{
duration: 5000,
style: {
background: '#525252',
color: '#fff',
borderRadius: 4,
padding: '0.75rem 1rem',
},
}}
/>
<TopBar />
<div className={cx(routeStyle, { [footerPadding]: shouldShowFooter })}>
<BreadCrumbNav />
Expand Down
37 changes: 23 additions & 14 deletions src/pages/conversions/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { TextField } from '@fluentui/react';
import { Spinner, SpinnerSize, TextField } from '@fluentui/react';
import { DetailsList, DetailsListLayoutMode, DetailsRow } from '@fluentui/react/lib/DetailsList';
import { PATHS } from 'common';
import { getAllData } from 'common/api/conversions';
import { getExistingConversions } from 'common/api/conversions';
import { useConversionPastStore } from 'common/store/conversion-past.store';
import { conversionStatuses, useConversionStore } from 'common/store/conversion.store';
import { useCallback, useEffect, useState } from 'react';
import toast from 'react-hot-toast';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import { shallow } from 'zustand/shallow';
Expand All @@ -13,7 +14,7 @@ import { filterInputStyles, iconsContainer, nameFilterContainer } from './style'
import { groupItems } from './utils';

const defaultColumns = [
{ key: 'nameCol', name: 'Name', fieldName: 'name', minWidth: 40, maxWidth: 200, isResizable: true },
{ key: 'nameCol', name: 'Description', fieldName: 'description', minWidth: 40, maxWidth: 460, isResizable: true },
{ key: 'statusCol', name: 'Status', fieldName: 'status', minWidth: 40, maxWidth: 200, isResizable: true },
{
key: 'dateCol',
Expand Down Expand Up @@ -85,7 +86,7 @@ const Conversions = () => {
const [items, setItems] = useState([]);
const [sorting, setSorting] = useState({ fieldName: 'date', descending: true });
const [columns, setColumns] = useState([]);
const [nameFilter, setNameFilter] = useState('');
const [descriptionFilter, setDescriptionFilter] = useState('');

const ongoingConversion = useConversionStore(conversionStoreSelector, shallow);
const setPastConversionData = useConversionPastStore(pastConversionStoreSelector, shallow);
Expand All @@ -98,19 +99,23 @@ const Conversions = () => {
[navigate, setPastConversionData]
);

const onNameFilterChange = (e, text) => setNameFilter(text);
const onNameFilterChange = (e, text) => setDescriptionFilter(text);

useEffect(() => {
// setIsLoading(true);
setColumns(
defaultColumns.map(column => ({
...column,
onColumnClick: getOnColumnClickCallback(defaultColumns, setColumns, setSorting),
}))
);
getAllData().then(({ conversions, datasets, mapDataList, tilesets }) => {
getExistingConversions().then(({ error, conversions, datasets, mapDataList, tilesets }) => {
setIsLoading(false);
if (error) {
toast.error('Unable to fetch existing conversions. Check your Geography and Subscription key');
navigate(PATHS.INDEX);
}
const groupedItems = groupItems(ongoingConversion, { conversions, datasets, mapDataList, tilesets });
groupedItems.sort((a, b) => (a.date < b.date ? 1 : -1));
setExistingConversions(groupedItems);
});
}, []); // eslint-disable-line
Expand Down Expand Up @@ -149,7 +154,7 @@ const Conversions = () => {
items
.map((item, i) => ({
key: i,
name:
description:
item.upload?.description ??
item.conversion?.description ??
item.dataset?.description ??
Expand Down Expand Up @@ -184,28 +189,32 @@ const Conversions = () => {
bbox: item.tileset?.bbox,
},
}))
.filter(item => item.name.includes(nameFilter))
.filter(item => item.description.includes(descriptionFilter))
.sort((a, b) => {
if (a[sorting.fieldName] < b[sorting.fieldName]) {
return sorting.descending ? 1 : -1;
}
return sorting.descending ? -1 : 1;
})
);
}, [existingConversions, ongoingConversion, t, sorting, nameFilter]);
}, [existingConversions, ongoingConversion, t, sorting, descriptionFilter]);

if (isLoading) {
return <div>{t('loading')}</div>;
return (
<div style={{ height: '80vh', display: 'flex', justifyContent: 'center', alignItems: 'center' }}>
<Spinner size={SpinnerSize.large} label={t('loading')} />
</div>
);
}

return (
<>
<div className={nameFilterContainer}>
<TextField
ariaLabel={t('filter.by.name')}
placeholder={t('filter.by.name')}
ariaLabel={t('filter.by.description')}
placeholder={t('filter.by.description')}
styles={filterInputStyles}
value={nameFilter}
value={descriptionFilter}
onChange={onNameFilterChange}
/>
</div>
Expand Down
Loading