Skip to content

Commit

Permalink
Revert commit 'merge epic-landing-pages into waitp-1259-map-component…
Browse files Browse the repository at this point in the history
…s-ts'
  • Loading branch information
alexd-bes committed May 29, 2023
1 parent 7362e82 commit e31052b
Show file tree
Hide file tree
Showing 206 changed files with 1,123 additions and 4,994 deletions.
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ dump.sql
/snapshots.js
.idea
packages/.vscode/settings.json
packages/devops/docker
**/testRequests/*.http
*:Zone.Identifier

Expand Down
87 changes: 17 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,105 +2,52 @@

[![Codeship Status for beyondessential/tupaia#dev](https://app.codeship.com/projects/70159bc0-0dac-0138-fdcb-260b82737f4e/status?branch=dev)](https://app.codeship.com/projects/379708)

## Open Source Info

### Open Source Mission statement

> By engaging and collaborating with our community we can deliver a more robust product that bridges cultural differences and empowers decision making within health systems worldwide.
### Code of Conduct

For contributor's code of conduct - see the [code-of-conduct.md](https://gitlab.com/beyond-essential/tupaia/blob/master/code-of-conduct.md) published in the repo.

## Packages

> This is a [mono-repo](https://github.com/babel/babel/blob/master/doc/design/monorepo.md)
It is set up using `yarn workspaces`, meaning any command you would normally run inside a package can
be run from the root directory using `yarn workspace @tupaia/package-name command`, e.g.
`yarn workspace @tupaia/central-server start-dev`

## Packages

The easiest way to open the packages in vscode is to double click 'tupaia-packages.code-workspace'.
This opens all packages as roots in the workspace, and means linting etc. will work correctly.

### Package structure

The Tupaia mono-repo is comprised for 3 types of packages:

- Platform interfaces (Frontend React applications that the user interacts with)
- Servers
- Orchestration servers (dedicated backend applications for each platform interface)
- Micro servers (applications which are used by the orchestration servers to perform common system functions)
- Libraries (various utility and common libraries that are used throughout the mono-repo)

While each package type has their own structure, there are a few common standards:

- `<package>/package.json` - package definition
- `<package>/src/` - contains source code
- `<package>/.env.example` - file showing what environment variables are required by the package
- `<package>/.env` - environment variables used by package (ignored in git)
- `<package>/src/__tests__/` - contains unit tests

### Platform interfaces
### Main packages

- [Tupaia](https://github.com/beyondessential/tupaia/blob/dev/packages/web-frontend/README.md) (for legacy reasons referred to as web-frontend)
- [Admin Panel](https://github.com/beyondessential/tupaia/blob/dev/packages/admin-panel/README.md)
- [LESMIS](https://github.com/beyondessential/tupaia/blob/dev/packages/lesmis/README.md)
- [PSSS](https://github.com/beyondessential/tupaia/blob/dev/packages/psss/README.md)
- [Meditrak](https://github.com/beyondessential/tupaia/blob/dev/packages/meditrak-app/README.md)

### Servers

#### Orchestration servers

- [web-config-server](https://github.com/beyondessential/tupaia/blob/dev/packages/web-config-server/README.md) (Tupaia's orchestration server, referred to as web-config-server for legacy reasons)
- [admin-panel](https://github.com/beyondessential/tupaia/blob/dev/packages/admin-panel/README.md)
- [admin-panel-server](https://github.com/beyondessential/tupaia/blob/dev/packages/admin-panel-server/README.md)
- [central-server](https://github.com/beyondessential/tupaia/blob/dev/packages/central-server/README.md)
- [lesmis](https://github.com/beyondessential/tupaia/blob/dev/packages/lesmis/README.md)
- [lesmis-server](https://github.com/beyondessential/tupaia/blob/dev/packages/lesmis-server/README.md)
- [psss-server](https://github.com/beyondessential/tupaia/blob/dev/packages/psss-server/README.md)
- [meditrak-app](https://github.com/beyondessential/tupaia/blob/dev/packages/meditrak-app/README.md)
- [meditrak-app-server](https://github.com/beyondessential/tupaia/blob/dev/packages/meditrak-app-server/README.md)
- [psss](https://github.com/beyondessential/tupaia/blob/dev/packages/psss/README.md)
- [psss-server](https://github.com/beyondessential/tupaia/blob/dev/packages/psss-server/README.md)
- [web-config-server](https://github.com/beyondessential/tupaia/blob/dev/packages/web-config-server/README.md)
- [web-frontend](https://github.com/beyondessential/tupaia/blob/dev/packages/web-frontend/README.md)

#### Micro servers

- [central-server](https://github.com/beyondessential/tupaia/blob/dev/packages/central-server/README.md)
- [entity-server](https://github.com/beyondessential/tupaia/blob/dev/packages/entity-server/README.md)
- [report-server](https://github.com/beyondessential/tupaia/blob/dev/packages/report-server/README.md)
- [data-table-server](https://github.com/beyondessential/tupaia/blob/dev/packages/data-table-server/README.md)

Server packages can be built by running `yarn workspace @tupaia/package-name build`.
Server packages can then be started by running `yarn workspace @tupaia/package-name start`.

All servers are NodeJS express applications, and the packages follow the same basic structure:

- `<package>/examples.http` - example queries showing the server interface
- `<package>/src/index.ts` - server entrypoint
- `<package>/src/app/createApp.ts` - express router definition
- `<package>/src/routes/` - route definitions
Any of the main packages can be run using `yarn workspace @tupaia/package-name start-dev`.
In the case of the two servers, this will also build and watch all of the internal dependencies, so
that hot reload detects changes to other packages within the mono-repo. As this delays startup time,
if you prefer to pre-build internal dependencies, add `--skip-internal` to the above command.

### Libraries
### Internal dependencies

- [access-policy](https://github.com/beyondessential/tupaia/blob/dev/packages/access-policy/README.md)
- [aggregator](https://github.com/beyondessential/tupaia/blob/dev/packages/aggregator/README.md)
- [api-client](https://github.com/beyondessential/tupaia/blob/dev/packages/api-client/README.md)
- [auth](https://github.com/beyondessential/tupaia/blob/dev/packages/auth/README.md)
- [data-api](https://github.com/beyondessential/tupaia/blob/dev/packages/data-api/README.md)
- [data-broker](https://github.com/beyondessential/tupaia/blob/dev/packages/data-broker/README.md)
- [data-lake-api](https://github.com/beyondessential/tupaia/blob/dev/packages/data-lake-api/README.md)
- [database](https://github.com/beyondessential/tupaia/blob/dev/packages/database/README.md)
- [data-broker](https://github.com/beyondessential/tupaia/blob/dev/packages/data-broker/README.md)
- [devops](https://github.com/beyondessential/tupaia/blob/dev/packages/devops/README.md)
- [dhis-api](https://github.com/beyondessential/tupaia/blob/dev/packages/dhis-api/README.md)
- [e2e](https://github.com/beyondessential/tupaia/blob/dev/packages/e2e/README.md)
- [expression-parser](https://github.com/beyondessential/tupaia/blob/dev/packages/expression-parser/README.md)
- [indicators](https://github.com/beyondessential/tupaia/blob/dev/packages/indicators/README.md)
- [ui-components](https://github.com/beyondessential/tupaia/blob/dev/packages/ui-components/README.md)
- [ui-chart-components](https://github.com/beyondessential/tupaia/blob/dev/packages/ui-chart-components/README.md)
- [ui-map-components](https://github.com/beyondessential/tupaia/blob/dev/packages/ui-map-components/README.md)
- [server-boilerplate](https://github.com/beyondessential/tupaia/blob/dev/packages/server-boilerplate/README.md)
- [superset-api](https://github.com/beyondessential/tupaia/blob/dev/packages/superset-api/README.md)
- [ui-components](https://github.com/beyondessential/tupaia/blob/dev/packages/ui-components/README.md)
- [utils](https://github.com/beyondessential/tupaia/blob/dev/packages/utils/README.md)
- [tsutils](https://github.com/beyondessential/tupaia/blob/dev/packages/tsutils/README.md)
- [types](https://github.com/beyondessential/tupaia/blob/dev/packages/types/README.md)
- [weather-api](https://github.com/beyondessential/tupaia/blob/dev/packages/weather-api/README.md)

## Getting started

Expand Down
2 changes: 1 addition & 1 deletion packages/access-policy/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# @tupaia/access-policy
# Tupaia Access Policy

Methods for parsing the access policy that is received by Tupaia projects during authentication.

Expand Down
2 changes: 1 addition & 1 deletion packages/admin-panel-server/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# @tupaia/admin-panel-server

Orchestration server for the Admin Panel web app.
Back end server for the Admin Panel web app.
15 changes: 4 additions & 11 deletions packages/admin-panel/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
# @tupaia/admin-panel

Frontend interface for the [Admin Panel](https://admin.tupaia.org/) web app.
# Tupaia Admin

## User Guide

Most aspects are fairly self explanatory, but this guide should cover any tricky bits as they get added

### Importing geojson

Documentation for importing geojson can be found [here](doc/importingNewGeojson.md)

### Creating an Api Client

When creating a new user, you have the option to create them as an api client. When you do this, you have one chance only to retrieve the client secret. The steps for Google Chrome are:
Expand All @@ -23,9 +17,8 @@ When creating a new user, you have the option to create them as an api client. W
This secret key is used as the password in Basic Auth headers sent by api clients. Their permissions are verified based on the user the api client is attached to.

### Viz Builder App

The Viz Builder App is an interface for creating Tupaia visualisations such as cartesian charts and pie charts.
The Viz Builder App is an interface for creating Tupaia visualisations such as cartesian charts and pie charts.
It is a standalone app that sits inside the admin panel on the `viz-builder` route.
It is inside the admin panel so that it can use the admin panel authentication and to give a more seamless user experience.
It is inside the admin panel so that it can use the admin panel authentication and to give a more seamless user experience.
The Viz Builder App code is contained from the admin panel code so that it can be exported and imported into other apps such as Lesmis if required.
It is also separated from the admin panel code so that we can use modern react techniques such as react-query.
It is also separated from the admin panel code so that we can use modern react techniques such as react-query.
4 changes: 1 addition & 3 deletions packages/admin-panel/src/editor/EditModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { getEditorState, getIsUnchanged } from './selectors';
import { Editor } from './Editor';
import { ModalContentProvider } from '../widgets';
import { UsedBy } from '../usedBy/UsedBy';
import { getExplodedFields } from '../utilities';

const getFieldSourceToEdit = field => {
const { source, editConfig = {} } = field;
Expand Down Expand Up @@ -49,8 +48,7 @@ export const EditModalComponent = ({
saveButtonText,
extraDialogProps,
}) => {
// key the fields by their source so we can easily find the field to edit. Use the exploded fields so that any subfields are placed into the top level of the array
const fieldsBySource = keyBy(getExplodedFields(fields), 'source');
const fieldsBySource = keyBy(fields, 'source');

return (
<Dialog onClose={onDismiss} open={isOpen} disableBackdropClick {...extraDialogProps}>
Expand Down
116 changes: 32 additions & 84 deletions packages/admin-panel/src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,20 @@

import React from 'react';
import PropTypes from 'prop-types';
import styled from 'styled-components';
import { InputGroup } from '@tupaia/ui-components';
import { InputField } from '../widgets';
import { checkVisibilityCriteriaAreMet, labelToId } from '../utilities';
import { createBase64Image } from '../utilities/createBase64Image';
import { SECTION_FIELD_TYPE } from './constants';

const EditorWrapper = styled.div`
.file_upload_label {
font-size: 0.9375rem;
text-transform: initial;
color: ${props => props.theme.palette.text.secondary};
}
`;

export const Editor = ({ fields, recordData, onEditField }) => {
const onInputChange = async (inputKey, inputValue, editConfig = {}) => {
const { setFieldsOnChange, type } = editConfig;
let updatedValue = inputValue;
if (type === 'image' && inputValue) {
// If the input is a file, we need to convert the file to a base64 encoded image.
updatedValue = await createBase64Image(inputValue);
}
const onInputChange = (inputKey, inputValue, editConfig = {}) => {
const { setFieldsOnChange } = editConfig;
if (setFieldsOnChange) {
const newFields = setFieldsOnChange(updatedValue, recordData);
const newFields = setFieldsOnChange(inputValue, recordData);
Object.entries(newFields).forEach(([fieldKey, fieldValue]) => {
onEditField(fieldKey, fieldValue);
});
}
onEditField(inputKey, updatedValue);

onEditField(inputKey, inputValue);
};

const selectValue = (editConfig, accessor, source) => {
Expand All @@ -47,73 +31,37 @@ export const Editor = ({ fields, recordData, onEditField }) => {
return recordData[source];
};

// Get the fields that are visible from an array
const filterVisibleFields = allFields => {
return allFields.filter(({ show = true, editConfig = {} }) => {
const { visibilityCriteria } = editConfig;

if (!show) {
return false;
}

// show or hide a field based on another field's value
if (visibilityCriteria) {
return checkVisibilityCriteriaAreMet(visibilityCriteria, recordData);
}

return true;
});
};
return (
<div>
{fields
.filter(({ show = true, editConfig = {} }) => {
const { visibilityCriteria } = editConfig;

// Get the input for the field
const getFieldInput = field => {
const { editable = true, editConfig = {}, source, Header, accessor } = field;
return (
<InputField
key={source}
inputKey={source}
label={Header}
onChange={(inputKey, inputValue) => onInputChange(inputKey, inputValue, editConfig)}
value={selectValue(editConfig, accessor, source)}
disabled={!editable}
recordData={recordData}
id={`inputField-${labelToId(source)}`}
{...editConfig}
/>
);
};
if (!show) {
return false;
}

// Get the form fields and sections that are visible from the fields prop, handling nested sections
const visibleFormItems = filterVisibleFields(fields).reduce((result, field) => {
if (field.type === SECTION_FIELD_TYPE) {
const visibleSubfields = filterVisibleFields(field.fields);
if (!visibleSubfields.length) return result;
return [
...result,
{
...field,
fields: visibleSubfields,
},
];
}
return [...result, field];
}, []);
// show or hide a field based on another field's value
if (visibilityCriteria) {
return checkVisibilityCriteriaAreMet(visibilityCriteria, recordData);
}

return (
<EditorWrapper>
{visibleFormItems.map(item =>
item.type === SECTION_FIELD_TYPE ? (
<InputGroup
key={item.title}
title={item.title}
description={item.description}
fields={item.fields.map(subfield => getFieldInput(subfield))}
return true;
})
.map(({ editable = true, editConfig = {}, source, Header, accessor }) => (
<InputField
key={source}
inputKey={source}
label={Header}
onChange={(inputKey, inputValue) => onInputChange(inputKey, inputValue, editConfig)}
value={selectValue(editConfig, accessor, source)}
disabled={!editable}
recordData={recordData}
id={`inputField-${labelToId(source)}`}
{...editConfig}
/>
) : (
getFieldInput(item)
),
)}
</EditorWrapper>
))}
</div>
);
};

Expand Down
Loading

0 comments on commit e31052b

Please sign in to comment.