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

Waitp 1259 map components to ts #4600

Merged
merged 36 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
67e311a
WAITP-1259 setup ts build for ui-map-components
alexd-bes May 24, 2023
e98a7f0
WAITP-1259 Update build script to allow watch
alexd-bes May 24, 2023
2b9f6d8
WAITP-1259 Change index to ts
alexd-bes May 25, 2023
62e9d75
WAITP-1259 ActivePolygon to ts
alexd-bes May 25, 2023
3d32219
WAITP-1259 AreaTooltip to ts
alexd-bes May 25, 2023
6f0c190
WAITP-1259 PopupDataItemList to ts
alexd-bes May 25, 2023
dee800f
WAITP-1259 EntityPolygon to ts
alexd-bes May 25, 2023
2005f14
WAITP-1259 InteractivePolygon to TS
alexd-bes May 25, 2023
a3022e7
WAITP-1259 UnversePolygonMask to ts
alexd-bes May 25, 2023
bb8ddc2
WAITP-1259 LeafletMap to ts
alexd-bes May 25, 2023
778b5fa
WAITP-1259 LeafletStyles to ts
alexd-bes May 25, 2023
e527e7a
WAITP-1259 Markers and MarkerLayer to TS
alexd-bes May 25, 2023
705b5d7
WAITP-1259 Update types
alexd-bes May 26, 2023
b3d8055
WAITP-1259 PolygonLayer to ts
alexd-bes May 26, 2023
bf96892
WAITP-1259 TIleLayer to TS
alexd-bes May 26, 2023
055859a
WAITP-1259 Legends to ts
alexd-bes May 26, 2023
9d7c539
WAITP-1259 Table to ts
alexd-bes May 28, 2023
b1e63d6
Merge branch 'epic-frontend-rewrite' into waitp-1259-map-components-t…
alexd-bes May 28, 2023
c2c9983
WAITP-1259 fix react types version mismatch
alexd-bes May 28, 2023
8371226
WAITP-1259 TilePicker to ts
alexd-bes May 28, 2023
0b6df81
WAITP-1259 colors to ts
alexd-bes May 28, 2023
54d0052
WAITP-1259 utils and fixes to types
alexd-bes May 29, 2023
2113372
WAITP-1259 Update type arrangement
alexd-bes May 29, 2023
280fb4e
WAITP-1259 remove ts-ignores
alexd-bes May 29, 2023
42181ee
WAITP-1259 handle default value
alexd-bes May 29, 2023
7362e82
WAITP-1259 Update storybook config
alexd-bes May 29, 2023
e31052b
Revert commit 'merge epic-landing-pages into waitp-1259-map-component…
alexd-bes May 29, 2023
f4e3e6a
WAITP-2359 get web frontend working
alexd-bes May 29, 2023
2ae1877
WAITP-1259 fix issues on frontend
alexd-bes May 29, 2023
d6d1250
WAITP-1259 get tests running
alexd-bes May 29, 2023
5e0b96f
Revert "Revert commit 'merge epic-landing-pages into waitp-1259-map-c…
alexd-bes May 29, 2023
43e4250
Update tsconfig.json
alexd-bes May 29, 2023
dcff0f6
Update tsconfig-build.json
alexd-bes May 29, 2023
ffebef9
Merge branch 'epic-frontend-rewrite' into waitp-1259-map-components-t…
tcaiger Jun 12, 2023
1d2444c
Update yarn.lock
tcaiger Jun 12, 2023
9449762
WAITP-1259 remove disaster icons
alexd-bes Jun 12, 2023
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
7 changes: 6 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,12 @@
"packages/ui-map-components/**"
],
"rules": {
"import/no-extraneous-dependencies": "off"
"import/no-extraneous-dependencies": "off",
"react/prop-types": "off",
"import/no-unresolved": 0, // Turn off linting error for imports
"import/extensions": 0, // Turn off linting error for imports
"react/require-default-props": "off",
"no-bitwise": "off" // Turn off linting error for bitwise operators because of generic style types using '>>'
}
},
{
Expand Down
3 changes: 2 additions & 1 deletion packages/lesmis/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
"start-lesmis-server": "yarn workspace @tupaia/lesmis-server start-dev",
"test": "yarn package:test",
"start-ui-components": "yarn workspace @tupaia/ui-components build -w",
"start-ui-map-components": "yarn workspace @tupaia/ui-map-components build -w",
"start-ui-chart-components": "yarn workspace @tupaia/ui-chart-components build -w",
"start-frontend": "npm-run-all -c -l -p start-ui-components start-ui-chart-components start-dev",
"start-frontend": "npm-run-all -c -l -p start-ui-components start-ui-chart-components start-ui-map-components start-dev",
"start-servers": "npm-run-all -c -l -p start-central-server start-entity-server start-report-server start-web-config-server start-lesmis-server"
},
"browserslist": [
Expand Down
4 changes: 2 additions & 2 deletions packages/ui-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@
"@storybook/react": "^6.3.9",
"@types/jest": "^29.5.1",
"@types/lodash.throttle": "^4.1.7",
"@types/react-dom": "^18.2.4",
"@types/react-dom": "^16.9.18",
"@types/react-router-dom": "^5.3.3",
"@types/react-table": "^7.7.14",
"@types/styled-components": "^5.1.26",
"@types/styled-components": "^5.0.0",
"faker": "^4.1.0",
"fast-glob": "^3.2.5",
"react-docgen-typescript-plugin": "^1.0.5",
Expand Down
6 changes: 3 additions & 3 deletions packages/ui-components/src/components/ReferenceTooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ const StyledToolTip = withStyles(theme => ({
},
}))(Tooltip);

interface Reference {
export interface ReferenceProps {
text?: string;
tcaiger marked this conversation as resolved.
Show resolved Hide resolved
name?: string;
link?: string;
}

const Content = ({ text = '', name = '', link = '' }: Reference) => {
const Content = ({ text = '', name = '', link = '' }: ReferenceProps) => {
if (text) {
return (
<TextCaption variant="caption">
Expand All @@ -72,7 +72,7 @@ const Content = ({ text = '', name = '', link = '' }: Reference) => {

interface ReferenceTooltipProps {
iconStyleOption?: string;
reference?: Reference;
reference?: ReferenceProps;
}

export const ReferenceTooltip = ({
Expand Down
3 changes: 3 additions & 0 deletions packages/ui-map-components/.storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@
module.exports = {
stories: ['../stories/**/*.stories.js'],
addons: ['@storybook/addon-essentials'],
typescript: {
reactDocgen: 'react-docgen-typescript-plugin',
},
};
tcaiger marked this conversation as resolved.
Show resolved Hide resolved
13 changes: 10 additions & 3 deletions packages/ui-map-components/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,23 @@
* Tupaia
* Copyright (c) 2017 - 2023 Beyond Essential Systems Pty Ltd
*/
const baseConfig = require('../../jest.config-ts.json');

module.exports = {
moduleDirectories: ['node_modules'],
collectCoverageFrom: ['**/src/components/**/*.js'],
...baseConfig,
rootDir: '.',
moduleDirectories: ['node_modules', 'helpers'],
collectCoverageFrom: ['**/src/**/**'],
testMatch: ['<rootDir>/src/__tests__/**/**.test.**'],
// handle static assets @see https://jestjs.io/docs/webpack#handling-static-assets
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|css)$':
'<rootDir>/jestFileMock.js',
'^file-loader': '<rootDir>/jestFileMock.js',
},
transformIgnorePatterns: ['/node_modules/'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
'^.+\\.js$': 'babel-jest',
},
testTimeout: 30 * 1000, // 30 seconds. Needed for CI as some test take a while if CPU has high load
};
14 changes: 10 additions & 4 deletions packages/ui-map-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
"author": "Beyond Essential Systems <admin@tupaia.org> (https://beyondessential.com.au)",
"source": "src/index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "rm -rf dist && npm run --prefix ../../ package:build:js",
"build": "rm -rf dist && yarn package:build:ts",
"build-dev": "npm run build",
"lint": "yarn package:lint:js",
"lint:fix": "yarn lint --fix",
"storybook": "start-storybook -s public -p 6006",
"test": "yarn package:test --env=jsdom",
"test:coverage": "yarn test --coverage",
"test:watch": "yarn test --watch",
"build-dev:watch": "yarn run package:build:js -w"
"test:watch": "yarn test --watch"
},
"dependencies": {
"@material-ui/core": "^4.9.8",
Expand All @@ -38,6 +38,12 @@
},
"devDependencies": {
"@material-ui/styles": "^4.9.10",
"@storybook/react": "^6.3.9"
"@mui/types": "^7.2.4",
"@storybook/react": "^6.3.9",
"@types/jest": "^29.5.1",
"@types/leaflet": "^1.7.1",
"@types/react-dom": "^16.9.18",
"@types/styled-components": "^5.1.26",
"react-docgen-typescript-plugin": "^1.0.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@
*/

import React from 'react';
import PropTypes from 'prop-types';
import { Polygon } from 'react-leaflet';
import { Polygon, PolygonProps as LeafletPolygonProps } from 'react-leaflet';
import styled from 'styled-components';
import { MAP_COLORS } from '../constants';

const { POLYGON_HIGHLIGHT } = MAP_COLORS;

const StyledPolygon = styled(Polygon)`
interface PolygonProps {
shade?: string;
hasChildren?: boolean;
hasShadedChildren?: boolean;
}

const StyledPolygon = styled(Polygon)<PolygonProps>`
stroke: ${props => props.shade || POLYGON_HIGHLIGHT};
opacity: 1;
fill: ${props => props.shade || 'none'};
Expand All @@ -27,7 +32,15 @@ const StyledPolygon = styled(Polygon)`
/**
* ActivePolygon: The polygon that is selected on the map. This handles the style logic
*/
const ActivePolygon = ({ coordinates, shade, hasChildren, hasShadedChildren }) => (
interface ActivePolygonProps extends PolygonProps {
coordinates: LeafletPolygonProps['positions'];
}
const ActivePolygon = ({
coordinates,
shade,
hasChildren = false,
hasShadedChildren = false,
}: ActivePolygonProps) => (
<StyledPolygon
positions={coordinates}
shade={shade}
Expand All @@ -36,19 +49,4 @@ const ActivePolygon = ({ coordinates, shade, hasChildren, hasShadedChildren }) =
/>
);

ActivePolygon.propTypes = {
coordinates: PropTypes.arrayOf(
PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.arrayOf(PropTypes.number))),
).isRequired,
shade: PropTypes.string,
hasChildren: PropTypes.bool,
hasShadedChildren: PropTypes.bool,
};

ActivePolygon.defaultProps = {
shade: null,
hasChildren: false,
hasShadedChildren: false,
};

export default ActivePolygon;
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
*/

import React from 'react';
import PropTypes from 'prop-types';
import { Tooltip } from 'react-leaflet';
import styled from 'styled-components';
import { PopupDataItemList } from './PopupDataItemList';
import { MeasureData, Series } from '../types';

const Heading = styled.span`
const Heading = styled.span<{
hasMeasureValue: boolean;
}>`
text-align: center;
font-weight: ${props => (props.hasMeasureValue ? 'bold' : 'normal')};
`;
Expand All @@ -19,15 +21,25 @@ const Grid = styled.div`
display: grid;
`;

interface AreaTooltipProps {
permanent?: boolean;
sticky?: boolean;
orgUnitName?: string;
hasMeasureValue?: boolean;
serieses?: Series[];
orgUnitMeasureData?: MeasureData;
text?: string;
}

export const AreaTooltip = ({
permanent,
sticky,
permanent = false,
sticky = false,
orgUnitName,
hasMeasureValue,
serieses,
orgUnitMeasureData,
hasMeasureValue = false,
serieses = [],
orgUnitMeasureData = {} as MeasureData,
text,
}) => {
}: AreaTooltipProps) => {
return (
<Tooltip
pane="tooltipPane"
Expand All @@ -52,23 +64,3 @@ export const AreaTooltip = ({
</Tooltip>
);
};

AreaTooltip.propTypes = {
permanent: PropTypes.bool,
sticky: PropTypes.bool,
hasMeasureValue: PropTypes.bool,
serieses: PropTypes.arrayOf(PropTypes.object),
orgUnitMeasureData: PropTypes.object,
orgUnitName: PropTypes.string,
text: PropTypes.string,
};

AreaTooltip.defaultProps = {
permanent: false,
sticky: false,
hasMeasureValue: false,
serieses: [],
orgUnitMeasureData: {},
orgUnitName: null,
text: null,
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
*
*/
import React from 'react';
import PropTypes from 'prop-types';
import { Polygon as PolygonComponent } from 'react-leaflet';
import styled from 'styled-components';
import { blue } from '@material-ui/core/colors';
import { AreaTooltip } from './AreaTooltip';
import { Entity } from '../types';

export const POLYGON_COLOR = '#EE6230';

Expand All @@ -23,7 +23,7 @@ const BasicPolygon = styled(PolygonComponent)`
}
`;

export const EntityPolygon = ({ entity }) => {
export const EntityPolygon = ({ entity }: { entity?: Entity }) => {
if (!entity || !Array.isArray(entity.region)) {
return null;
}
Expand All @@ -36,14 +36,3 @@ export const EntityPolygon = ({ entity }) => {
</BasicPolygon>
);
};

EntityPolygon.propTypes = {
entity: PropTypes.shape({
name: PropTypes.string,
region: PropTypes.array,
}),
};

EntityPolygon.defaultProps = {
entity: null,
};
Loading