Skip to content

Commit

Permalink
merge with master
Browse files Browse the repository at this point in the history
  • Loading branch information
petterav committed Feb 22, 2024
2 parents 555dcf4 + 0dfb670 commit 6ec4d67
Show file tree
Hide file tree
Showing 22 changed files with 519 additions and 253 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/build/**
tailwind.css
/src/locales/**
154 changes: 154 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
{
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint",
"react",
"react-hooks"
],
"extends": [
"airbnb",
"eslint:recommended",
"plugin:@typescript-eslint/recommended"
],
"env": {
"browser": true,
"es2021": true
},
"globals": {
"cy": true,
"before": true,
"beforeEach": true,
"describe": true,
"document": true,
"window": true,
"it": true,
"expect": true,
"appPackage": true,
"Cypress": true
},
"settings": {
"import/core-modules": ["@dhis2/d2-i18n", "react"],
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".ts", ".tsx"]
}
},
"import/ignore": [
"node_modules",
".(json|css)$"
]
},
"rules": {
"indent": [2, 4],
"complexity": "off",
"no-prototype-builtins": "off",
"no-redeclare": "error",
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
"jsx-quotes": ["error", "prefer-single"],
"no-console": ["error", {
"allow": ["warn", "error"]
}],
"comma-dangle": [
"error",
{
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "always-multiline"
}
],
"no-multi-spaces": ["error", { "ignoreEOLComments": true }],
"no-return-assign": ["error", "except-parens"],
"react/jsx-indent": [1, 4],
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-explicit-any": "off",
"implicit-arrow-linebreak": "off",
"react/jsx-indent-props": [2, 4],
"react/prefer-es6-class": [1, "always"],
"react/jsx-filename-extension": [1, { "extensions": [".ts", ".tsx"] }],
"react/no-unused-prop-types": [2, { "skipShapeProps": true }],
"react/forbid-prop-types": [0],
"@typescript-eslint/no-unnecessary-type-constraint": "warn",
"no-param-reassign": 0,
"react/prop-types": 0,
"import/prefer-default-export": 0,
"react/prefer-stateless-function": 0,
"no-unused-expressions": 0,
"linebreak-style": "off",
"@typescript-eslint/no-unused-vars": "error",
"react/jsx-no-bind": 0,
"react/require-default-props": 0,
"react/jsx-curly-brace-presence": 0,
"react/function-component-definition": 0,
"@typescript-eslint/no-empty-function": "off",
"import/no-extraneous-dependencies": [
"error",
{
"devDependencies": [
"**/*.test.js",
"cypress/**",
"cypress.config.ts"
],
"optionalDependencies": false,
"peerDependencies": true
}
],
"react/button-has-type": 0,
"react/sort-comp": [
2,
{
"order": [
"static-methods",
"type-annotations",
"lifecycle",
"everything-else",
"render"
],
"groups": {
"lifecycle": [
"displayName",
"propTypes",
"contextTypes",
"childContextTypes",
"mixins",
"statics",
"defaultProps",
"constructor",
"getDefaultProps",
"getInitialState",
"state",
"getChildContext",
"UNSAFE_componentWillMount",
"componentDidMount",
"UNSAFE_componentWillReceiveProps",
"shouldComponentUpdate",
"UNSAFE_componentWillUpdate",
"componentDidUpdate",
"componentWillUnmount"
]
}
}
],
"eol-last": ["error", "always"],
"react-hooks/exhaustive-deps": "error",
"object-curly-newline": [
"error",
{
"ObjectExpression": { "multiline": true, "minProperties": 3 },
"ObjectPattern": { "multiline": true, "minProperties": 4 },
"ImportDeclaration": "never",
"ExportDeclaration": { "multiline": true, "minProperties": 3 }
}
],
"max-len": ["error", { "code": 120 }],
"no-shadow": "off",
"react/jsx-props-no-spreading": "off",
"camelcase": "off",
"import/extensions": ["error", "never"]
}
}

9 changes: 9 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: 2
updates:
- package-ecosystem: npm
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 5
target-branch: master
versioning-strategy: increase
66 changes: 66 additions & 0 deletions .github/workflows/verify-app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: 'Capture Growth Chart: verify app'

on:
push:
branches:

env:
NODE_VERSION: 18.x

jobs:
install_dependencies:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- uses: actions/cache@v2
id: yarn-cache
with:
path: '**/node_modules'
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}

- name: Install Dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile

lint_code:
runs-on: ubuntu-latest
needs: install_dependencies
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- uses: actions/cache@v2
id: yarn-cache
with:
path: '**/node_modules'
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}

- name: Lint Code
run: yarn lint

typescript_check:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[skip ci]')"
needs: install_dependencies
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}

- uses: actions/cache@v2
id: yarn-cache
with:
path: '**/node_modules'
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}

- name: Typescript Check
run: yarn tsc:check
8 changes: 3 additions & 5 deletions d2.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
const config = {
type: 'app',

entryPoints: {
plugin: './src/Plugin.tsx'
},
}
entryPoints: { plugin: './src/Plugin.tsx' },
};

module.exports = config
module.exports = config;
25 changes: 20 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,37 @@
"build": "d2-app-scripts build",
"start": "d2-app-scripts start",
"test": "d2-app-scripts test",
"deploy": "d2-app-scripts deploy"
"deploy": "d2-app-scripts deploy",
"tsc:check": "tsc --noEmit",
"lint": "eslint -c .eslintrc.json . --quiet"
},
"devDependencies": {
"@dhis2/cli-app-scripts": "^10.4.0",
"eslint": "8.56.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jsx-a11y": "^6.8.0",
"eslint-plugin-react": "^7.33.2",
"react-scripts": "5.1.0-next.14",
"tailwindcss": "^3.4.1"
"tailwindcss": "^3.4.1",
"typescript": "^5.3.3"
},
"dependencies": {
"@dhis2/app-runtime": "^3.10.2",
"@dhis2/d2-i18n": "^1.1.3",
"@dhis2/prop-types": "^3.1.2",
"@dhis2/ui": "^9.0.1",
"@material-ui/core": "^4.12.4",
"@material-ui/core": "4.12.4",
"@tailwindcss/line-clamp": "^0.4.4",
"@tanstack/react-query": "^4",
"@types/chart.js": "^2.9.41",
"chart.js": "^3.0.0",
"react-chartjs-2": "^5.2.0"
"chart.js": "^4.4.1",
"classnames": "^2.5.1",
"prop-types": "15.8.1",
"react": "^16.8.0",
"react-chartjs-2": "^5.2.0",
"react-dom": "^16.8.0",
"styled-jsx": "^4"
},
"resolutions": {
"@dhis2/ui": "^9.0.1",
Expand Down
16 changes: 7 additions & 9 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import React from 'react'
import Plugin from "./Plugin";
import React from 'react';
import Plugin from './Plugin';
import './tailwind.css';
import './index.css';

const query = {
me: {
resource: 'me',
},
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const query = { me: { resource: 'me' } };

const MyApp = () => (
// eslint-disable-next-line react/jsx-filename-extension
<div>
<Plugin
pluginSource={'http://localhost:3002/plugin.html'}
/>
</div>
)
);

export default MyApp
export default MyApp;
15 changes: 0 additions & 15 deletions src/App.test.js

This file was deleted.

6 changes: 3 additions & 3 deletions src/Components/GrowthChart/GrowthChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { chartData } from "../../DataSets/ChartData";
import { ChartSettingsButton } from "./ChartSettingsButton";

export const GrowthChart = () => {
const { datasets, metadata } = chartData["Weight-for-age GIRLS"];
const dataSetValues = datasets["Girls0to5Years"];
const dataSetMetadata = metadata["Girls0to5Years"];
const { datasets, metadata } = chartData['Weight-for-age GIRLS'];
const dataSetValues = datasets.Girls0to5Years;
const dataSetMetadata = metadata.Girls0to5Years;

const xLabelValues = useRangeTimePeriod(dataSetMetadata.range.start, dataSetMetadata.range.end);
const keysDataSet = Object.keys(dataSetValues[0]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import React from 'react';
import i18n from '@dhis2/d2-i18n'
import i18n from '@dhis2/d2-i18n';
import { Line } from 'react-chartjs-2';
import 'chart.js/auto';
import { ChartDataTypes } from '../../../types/chartDataTypes';
import { chartLineColorPicker } from '../../../utils/chartLineColorPicker';


export const GrowthChartBuilder = ({ dataSetValues, dataSetMetadata, xLabelValues, keysDataSet }: ChartDataTypes) => {
export const GrowthChartBuilder = ({
dataSetValues, dataSetMetadata, xLabelValues, keysDataSet,
}: ChartDataTypes) => {
const data = {
labels: xLabelValues,
datasets: keysDataSet.map(key => ({
data: dataSetValues.map(entry => entry[key]),
datasets: keysDataSet.map((key) => ({
data: dataSetValues.map((entry) => entry[key]),
borderWidth: 0.9,
borderColor: chartLineColorPicker(key),
})),
Expand All @@ -20,7 +21,7 @@ export const GrowthChartBuilder = ({ dataSetValues, dataSetMetadata, xLabelValue
elements: { point: { radius: 0, hoverRadius: 0 } },
plugins: { legend: { display: false } },
scales: {
x: { title: { display: true, text: i18n.t(`age (${dataSetMetadata.unit})`)} },
x: { title: { display: true, text: i18n.t(`age (${dataSetMetadata.unit})`) } },
y: { title: { display: true, text: dataSetMetadata.yaxis } },
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/Components/GrowthChart/GrowthChartBuilder/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { GrowthChartBuilder } from './GrowthChartBuilder'
export { useRangeTimePeriod } from './useRangeTimePeriod'
export { useRangeTimePeriod } from './useRangeTimePeriod'
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const useRangeTimePeriod = (start: number, end: number) => {
return Array.from({ length: end - start + 1 }, (_, index) => start + index);
};
export const useRangeTimePeriod = (start: number, end: number) => Array.from(
{ length: end - start + 1 },
(_, index) => start + index,
);
Loading

0 comments on commit 6ec4d67

Please sign in to comment.