Skip to content

Commit

Permalink
Merge pull request #4256 from beyondessential/release-2022-45
Browse files Browse the repository at this point in the history
Release 2022-45
  • Loading branch information
IgorNadj authored Nov 7, 2022
2 parents 69d22a4 + 4942312 commit 834d956
Show file tree
Hide file tree
Showing 75 changed files with 1,612 additions and 345 deletions.
14 changes: 12 additions & 2 deletions packages/admin-panel/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { PROFILE_ROUTES } from './profileRoutes';
import { getUser, getIsBESAdmin, PrivateRoute } from './authentication';
import { LoginPage } from './pages/LoginPage';
import { LogoutPage } from './pages/LogoutPage';
import { labelToId } from './utilities';

export const App = ({ user, isBESAdmin }) => {
const headerEl = React.useRef(null);
Expand All @@ -30,12 +31,21 @@ export const App = ({ user, isBESAdmin }) => {
<LogoutPage />
</Route>
<PrivateRoute path="/">
<Navbar links={ROUTES} user={user} />
<Navbar
links={ROUTES.map(route => ({ ...route, id: `app-tab-${labelToId(route.label)}` }))}
user={user}
/>
<div ref={headerEl} />
<Switch>
{[...ROUTES, ...PROFILE_ROUTES].map(route => (
<Route key={route.to} path={route.to}>
<TabsToolbar links={route.tabs} maxWidth="xl" />
<TabsToolbar
links={route.tabs.map(tab => ({
...tab,
id: `app-subTab-${labelToId(tab.label)}`,
}))}
maxWidth="xl"
/>
<Switch>
{route.tabs.map(tab => (
<Route key={`${route.to}-${tab.to}`} path={`${route.to}${tab.to}`} exact>
Expand Down
1 change: 1 addition & 0 deletions packages/admin-panel/src/editor/BulkCreateButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { openBulkEditModal } from './actions';

export const BulkCreateButtonComponent = ({ dispatch, label, actionConfig }) => (
<LightOutlinedButton
id="page-button-bulk-create"
startIcon={<AddCircleIcon />}
onClick={() => dispatch(openBulkEditModal(actionConfig))}
>
Expand Down
5 changes: 4 additions & 1 deletion packages/admin-panel/src/editor/BulkEditButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import { openBulkEditModal } from './actions';

export const BulkEditButtonComponent = ({ dispatch, value: recordId, actionConfig, row }) => {
return (
<IconButton onClick={() => dispatch(openBulkEditModal(actionConfig, recordId, row))}>
<IconButton
id="page-button-bulk-edit"
onClick={() => dispatch(openBulkEditModal(actionConfig, recordId, row))}
>
<EditIcon />
</IconButton>
);
Expand Down
1 change: 1 addition & 0 deletions packages/admin-panel/src/editor/CreateButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { openEditModal } from './actions';

export const CreateButtonComponent = ({ dispatch, label, actionConfig }) => (
<LightOutlinedButton
id="page-new-button"
startIcon={<AddCircleIcon />}
onClick={() => dispatch(openEditModal(actionConfig))}
>
Expand Down
2 changes: 1 addition & 1 deletion packages/admin-panel/src/editor/EditButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { openEditModal } from './actions';
import { fetchUsedBy } from '../usedBy';

export const EditButtonComponent = ({ onEdit }) => (
<IconButton onClick={onEdit}>
<IconButton className="edit-button" onClick={onEdit}>
<EditIcon />
</IconButton>
);
Expand Down
8 changes: 6 additions & 2 deletions packages/admin-panel/src/editor/EditModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ export const EditModalComponent = ({
</>
</ModalContentProvider>
<DialogFooter>
<Button variant="outlined" onClick={onDismiss} disabled={isLoading}>
<Button id="form-button-cancel" variant="outlined" onClick={onDismiss} disabled={isLoading}>
{errorMessage ? 'Dismiss' : 'Cancel'}
</Button>
<Button onClick={onSave} disabled={!!errorMessage || isLoading || isUnchanged}>
<Button
id="form-button-save"
onClick={onSave}
disabled={!!errorMessage || isLoading || isUnchanged}
>
Save
</Button>
</DialogFooter>
Expand Down
3 changes: 2 additions & 1 deletion packages/admin-panel/src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { InputField } from '../widgets';
import { checkVisibilityCriteriaAreMet } from '../utilities';
import { checkVisibilityCriteriaAreMet, labelToId } from '../utilities';

export const Editor = ({ fields, recordData, onEditField }) => {
const onInputChange = (inputKey, inputValue, editConfig = {}) => {
Expand Down Expand Up @@ -57,6 +57,7 @@ export const Editor = ({ fields, recordData, onEditField }) => {
value={selectValue(editConfig, accessor, source)}
disabled={!editable}
recordData={recordData}
id={`inputField-${labelToId(source)}`}
{...editConfig}
/>
))}
Expand Down
1 change: 1 addition & 0 deletions packages/admin-panel/src/importExport/ExportButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const ExportButton = ({ actionConfig, row }) => {

return (
<IconButton
className="export-button"
onClick={async () => {
const {
exportEndpoint,
Expand Down
26 changes: 21 additions & 5 deletions packages/admin-panel/src/importExport/ExportModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,34 @@ export const ExportModal = React.memo(({ title, exportEndpoint, fileName, values
const renderButtons = useCallback(() => {
switch (status) {
case STATUS.TIMEOUT:
return <Button onClick={handleClose}>Done</Button>;
return (
<Button id="form-button-done" onClick={handleClose}>
Done
</Button>
);
case STATUS.ERROR:
return (
<>
<OutlinedButton onClick={handleDismiss}>Dismiss</OutlinedButton>
<Button disabled>Export</Button>
<OutlinedButton id="form-button-dismiss" onClick={handleDismiss}>
Dismiss
</OutlinedButton>
<Button id="form-button-export" disabled>
Export
</Button>
</>
);
default:
return (
<>
<OutlinedButton onClick={handleClose}>Cancel</OutlinedButton>
<Button type="submit" isLoading={status === STATUS.LOADING} onClick={handleSubmit}>
<OutlinedButton id="form-button-cancel" onClick={handleClose}>
Cancel
</OutlinedButton>
<Button
id="form-button-export"
type="submit"
isLoading={status === STATUS.LOADING}
onClick={handleSubmit}
>
Export
</Button>
</>
Expand Down Expand Up @@ -112,6 +127,7 @@ export const ExportModal = React.memo(({ title, exportEndpoint, fileName, values
</form>
</Dialog>
<LightOutlinedButton
id="page-export-button"
startIcon={<ExportIcon />}
onClick={handleOpen}
isLoading={STATUS === STATUS.LOADING}
Expand Down
14 changes: 11 additions & 3 deletions packages/admin-panel/src/importExport/ImportModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { ModalContentProvider, InputField } from '../widgets';
import { useApi } from '../utilities/ApiProvider';
import { DATA_CHANGE_REQUEST, DATA_CHANGE_SUCCESS, DATA_CHANGE_ERROR } from '../table/constants';
import { checkVisibilityCriteriaAreMet } from '../utilities';
import { checkVisibilityCriteriaAreMet, labelToId } from '../utilities';

const STATUS = {
IDLE: 'idle',
Expand Down Expand Up @@ -135,8 +135,11 @@ export const ImportModalComponent = React.memo(
default:
return (
<>
<OutlinedButton onClick={handleClose}>Cancel</OutlinedButton>
<OutlinedButton id="form-button-cancel" onClick={handleClose}>
Cancel
</OutlinedButton>
<Button
id="form-button-import"
type="submit"
disabled={files.length === 0}
isLoading={status === STATUS.LOADING}
Expand Down Expand Up @@ -182,6 +185,7 @@ export const ImportModalComponent = React.memo(
onChange={handleValueChange}
label={label}
secondaryLabel={secondaryLabel}
id={`field-${labelToId(parameterKey)}`}
/>
);
})}
Expand All @@ -200,7 +204,11 @@ export const ImportModalComponent = React.memo(
<DialogFooter>{renderButtons()}</DialogFooter>
</form>
</Dialog>
<LightOutlinedButton startIcon={<ImportIcon />} onClick={handleOpen}>
<LightOutlinedButton
id="page-import-button"
startIcon={<ImportIcon />}
onClick={handleOpen}
>
Import
</LightOutlinedButton>
</>
Expand Down
2 changes: 1 addition & 1 deletion packages/admin-panel/src/logsTable/LogsButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { openLogsModal } from './actions';
export const LogsButtonComponent = props => {
const { openModal } = props;
return (
<IconButton onClick={openModal}>
<IconButton className="logs-button" onClick={openModal}>
<DescriptionIcon />
</IconButton>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Tupaia
* Copyright (c) 2017 - 2021 Beyond Essential Systems Pty Ltd
*/

import React from 'react';
import PropTypes from 'prop-types';
import { ResourcePage } from './ResourcePage';
import { ArrayFilter } from '../../table/columnTypes/columnFilters';
import { prettyArray } from '../../utilities';
import { TestDatabaseConnectionCell } from '../../table/customCells';

const EXTERNAL_DATABASE_CONNECTIONS_ENDPOINT = 'externalDatabaseConnections';

const FIELDS = [
{
Header: 'Code',
source: 'code',
type: 'tooltip',
},
{
Header: 'Name',
source: 'name',
},
{
Header: 'Description',
source: 'description',
},
{
Header: 'Permission groups',
source: 'permission_groups',
Filter: ArrayFilter,
Cell: ({ value }) => prettyArray(value),
editConfig: {
optionsEndpoint: 'permissionGroups',
optionLabelKey: 'name',
optionValueKey: 'name',
sourceKey: 'permission_groups',
allowMultipleValues: true,
},
},
];

const COLUMNS = [
...FIELDS,
{
Header: 'Edit',
source: 'id',
type: 'edit',
actionConfig: {
editEndpoint: EXTERNAL_DATABASE_CONNECTIONS_ENDPOINT,
title: 'Edit External Database Connection',
fields: [...FIELDS],
},
},
{
Header: 'Test',
source: 'id',
filterable: false,
sortable: false,
Cell: TestDatabaseConnectionCell,
width: 70,
},
];

const CREATE_CONFIG = {
title: 'Create a new External Database Connection',
actionConfig: {
editEndpoint: EXTERNAL_DATABASE_CONNECTIONS_ENDPOINT,
fields: [...FIELDS],
},
};

export const ExternalDatabaseConnectionsPage = ({ getHeaderEl }) => (
<ResourcePage
title="External Database Connections"
endpoint={EXTERNAL_DATABASE_CONNECTIONS_ENDPOINT}
columns={COLUMNS}
createConfig={CREATE_CONFIG}
getHeaderEl={getHeaderEl}
/>
);

ExternalDatabaseConnectionsPage.propTypes = {
getHeaderEl: PropTypes.func.isRequired,
};
3 changes: 3 additions & 0 deletions packages/admin-panel/src/pages/resources/UsersPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ const EDIT_FIELDS = [
Header: 'Password',
source: 'password',
hideValue: true,
editConfig: {
type: 'password',
},
},
];

Expand Down
1 change: 1 addition & 0 deletions packages/admin-panel/src/pages/resources/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ export { DashboardRelationsPage } from './DashboardRelationsPage';
export { LegacyReportsPage } from './LegacyReportsPage';
export { ProjectsPage } from './ProjectsPage';
export { SyncGroupsPage } from './SyncGroupsPage';
export { ExternalDatabaseConnectionsPage } from './ExternalDatabaseConnectionsPage';
15 changes: 14 additions & 1 deletion packages/admin-panel/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import React from 'react';
import { Assignment, InsertChart, PeopleAlt, Flag, Storage } from '@material-ui/icons';
import { Assignment, InsertChart, PeopleAlt, Flag, Storage, Language } from '@material-ui/icons';
import { StrivePage } from './pages/StrivePage';
import {
CountriesPage,
Expand Down Expand Up @@ -32,6 +32,7 @@ import {
ProjectsPage,
SyncGroupsPage,
DataTablesPage,
ExternalDatabaseConnectionsPage,
} from './pages/resources';
import { DataElementDataServicesPage } from './pages/resources/DataElementDataServicesPage';

Expand Down Expand Up @@ -206,4 +207,16 @@ export const ROUTES = [
},
],
},
{
label: 'External Data',
to: '/external-database-connections',
icon: <Language />,
tabs: [
{
label: 'External Database Connections',
to: '',
component: ExternalDatabaseConnectionsPage,
},
],
},
];
2 changes: 1 addition & 1 deletion packages/admin-panel/src/sync/SyncStatus.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ export const SyncStatus = props => {
if (errorMessage) {
return (
<SyncStatusContainer>
<IconButton onClick={performManualSync}>
<IconButton className="sync-button" onClick={performManualSync}>
<SyncIcon />
</IconButton>
<Tooltip title={errorMessage}>
Expand Down
10 changes: 8 additions & 2 deletions packages/admin-panel/src/table/ColumnFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,30 @@
import React from 'react';
import { TextField } from '@tupaia/ui-components';
import PropTypes from 'prop-types';
import { labelToId } from '../utilities';

export const ColumnFilter = ({ filter, onChange }) => (
export const ColumnFilter = ({ column, filter, onChange }) => (
<TextField
type="text"
placeholder="Type to filter"
value={filter ? filter.value : ''}
onChange={event => onChange(event.target.value)}
id={`dataTableColumnFilter-${labelToId(column?.id)}`}
/>
);

ColumnFilter.propTypes = {
filter: PropTypes.PropTypes.shape({
column: PropTypes.shape({
id: PropTypes.string,
}),
filter: PropTypes.shape({
value: PropTypes.string,
}),
onChange: PropTypes.func,
};

ColumnFilter.defaultProps = {
column: null,
filter: null,
onChange: null,
};
Loading

0 comments on commit 834d956

Please sign in to comment.