Skip to content

Commit

Permalink
Merge branch 'development' into Maps-Update
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisMart21 authored Aug 13, 2024
2 parents b71527a + 0f05982 commit 90db2c6
Show file tree
Hide file tree
Showing 34 changed files with 1,317 additions and 1,376 deletions.
33 changes: 21 additions & 12 deletions src/client/app/components/FormFileUploaderComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import * as React from 'react';
import { FormattedMessage } from 'react-intl';
import { Col, Input, FormGroup, FormText, Label } from 'reactstrap';
import { Col, Input, FormGroup, Label } from 'reactstrap';
import translate from '../utils/translate';

interface FileUploader {
reference: React.RefObject<HTMLInputElement>;
required: boolean;
formText: string;
labelStyle?: React.CSSProperties;
isInvalid: boolean;
onFileChange: (file: File | null) => void;
}

/**
Expand All @@ -19,17 +17,28 @@ interface FileUploader {
* @returns File uploader element
*/
export default function FileUploaderComponent(props: FileUploader) {

const handleFileChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const file = event.target.files?.[0] || null;
props.onFileChange(file);
};

return (
<FormGroup>
<Label style={props.labelStyle}>
<FormattedMessage id='csv.file' />
<Label for='csvfile'>
<div className='pb-1'>
{translate('csv.file')}
</div>
</Label>
<Col>
<Input innerRef={props.reference} type='file' name='csvfile' required={props.required} />
<Input
type='file'
name='csvfile'
id='csvfile'
onChange={handleFileChange}
invalid={!props.isInvalid}
/>
</Col>
<FormText color='muted'>
<FormattedMessage id={props.formText}/>
</FormText>
</FormGroup>
);
}
19 changes: 14 additions & 5 deletions src/client/app/components/HeaderButtonsComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export default function HeaderButtonsComponent() {
shouldGroupsButtonDisabled: true,
shouldMetersButtonDisabled: true,
shouldMapsButtonDisabled: true,
shouldCSVButtonDisabled: true,
shouldCSVMetersButtonDisabled: true,
shouldCSVReadingsButtonDisabled: true,
shouldUnitsButtonDisabled: true,
shouldConversionsButtonDisabled: true,
// Translated menu title that depend on whether logged in.
Expand Down Expand Up @@ -93,7 +94,8 @@ export default function HeaderButtonsComponent() {
shouldGroupsButtonDisabled: pathname === '/groups',
shouldMetersButtonDisabled: pathname === '/meters',
shouldMapsButtonDisabled: pathname === '/maps',
shouldCSVButtonDisabled: pathname === '/csv',
shouldCSVMetersButtonDisabled: pathname === '/csvMeters',
shouldCSVReadingsButtonDisabled: pathname === '/csvReadings',
shouldUnitsButtonDisabled: pathname === '/units',
shouldConversionsButtonDisabled: pathname === '/conversions'
}));
Expand Down Expand Up @@ -172,12 +174,19 @@ export default function HeaderButtonsComponent() {
to="/conversions">
<FormattedMessage id='conversions' />
</DropdownItem>
<DropdownItem
style={state.adminViewableLinkStyle}
disabled={state.shouldCSVMetersButtonDisabled}
tag={Link}
to="/csvMeters">
<FormattedMessage id='csvMeters' />
</DropdownItem>
<DropdownItem
style={state.csvViewableLinkStyle}
disabled={state.shouldCSVButtonDisabled}
disabled={state.shouldCSVReadingsButtonDisabled}
tag={Link}
to="/csv">
<FormattedMessage id='csv' />
to="/csvReadings">
<FormattedMessage id='csvReadings' />
</DropdownItem>
<DropdownItem
disabled={state.shouldGroupsButtonDisabled}
Expand Down
5 changes: 3 additions & 2 deletions src/client/app/components/RouteComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,16 @@ const router = createBrowserRouter([
{ path: 'admin', element: <AdminComponent /> },
{ path: 'calibration', element: <MapCalibrationComponent /> },
{ path: 'maps', element: <MapsDetailComponent /> },
{ path: 'units', element: <UnitsDetailComponent /> },
{ path: 'conversions', element: <ConversionsDetailComponent /> },
{ path: 'csvMeters', element: <MetersCSVUploadComponent /> },
{ path: 'units', element: <UnitsDetailComponent /> },
{ path: 'users', element: <UsersDetailComponent /> }
]
},
{
element: <RoleOutlet role={UserRole.CSV} />,
children: [
{ path: 'csv', element: <UploadCSVContainer /> }
{ path: 'csvReadings', element: <ReadingsCSVUploadComponent /> }
]
},
{ path: '*', element: <NotFound /> }
Expand Down
5 changes: 3 additions & 2 deletions src/client/app/components/TooltipHelpComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ export default function TooltipHelpComponent(props: TooltipHelpProps) {
'help.admin.unitcreate': { link: `${helpUrl}/adminUnitCreating/` },
'help.admin.unitedit': { link: `${helpUrl}/adminUnitEditing/` },
'help.admin.unitview': { link: `${helpUrl}/adminUnitViewing/` },
'help.admin.user': { link: `${helpUrl}/adminUser/` },
'help.csv.header': { link: `${helpUrl}/adminDataAcquisition/` },
'help.admin.users': { link: `${helpUrl}/adminUser/` },
'help.csv.meters': { link: `${helpUrl}/adminMetersImport/` },
'help.csv.readings': { link: `${helpUrl}/adminReadingsImport/` },
'help.home.area.normalize': { link: `${helpUrl}/areaNormalization/` },
'help.home.bar.days.tip': { link: `${helpUrl}/barGraphic/#usage` },
'help.home.bar.interval.tip': { link: `${helpUrl}/barGraphic/#usage` },
Expand Down
48 changes: 30 additions & 18 deletions src/client/app/components/admin/PreferencesComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export default function PreferencesComponent() {
setLocalAdminPref({ ...localAdminPref, [key]: value });
};

const discardChanges = () => {
setLocalAdminPref(cloneDeep(adminPreferences));
};

return (
<div className='d-flex flex-column '>
<UnsavedWarningComponent
Expand Down Expand Up @@ -316,24 +320,32 @@ export default function PreferencesComponent() {
onChange={e => makeLocalChanges('defaultHelpUrl', e.target.value)}
/>
</div>

<Button
type='submit'
onClick={() =>
submitPreferences(localAdminPref)
.unwrap()
.then(() => {
showSuccessNotification(translate('updated.preferences'));
})
.catch(() => {
showErrorNotification(translate('failed.to.submit.changes'));
})
}
disabled={!hasChanges}
className='align-self-end mt-3'
>
{translate('submit')}
</Button>
<div className='d-flex justify-content-end mt-3'>
<Button
type='button'
onClick={discardChanges}
disabled={!hasChanges}
style={{ marginRight: '20px' }}
>
{translate('discard.changes')}
</Button>
<Button
type='submit'
onClick={() =>
submitPreferences(localAdminPref)
.unwrap()
.then(() => {
showSuccessNotification(translate('updated.preferences'));
})
.catch(() => {
showErrorNotification(translate('failed.to.submit.changes'));
})
}
disabled={!hasChanges}
>
{translate('submit')}
</Button>
</div>
</div >
);
}
Expand Down
Loading

0 comments on commit 90db2c6

Please sign in to comment.