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

refactor: use creact-react-app/react-scripts instead of .d2 folder #711

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
refactor(shell): make shell a library that exports a react component
  • Loading branch information
Mohammer5 committed Mar 29, 2022
commit c0b2b72299867b212ef132435ddef65676ded722
5 changes: 0 additions & 5 deletions shell/.browserslistrc

This file was deleted.

1 change: 0 additions & 1 deletion shell/.env

This file was deleted.

12 changes: 12 additions & 0 deletions shell/d2.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const config = {
type: 'lib',
name: '@dhis2/app-shell',
title: 'App Shell',
description: 'Provides wrappers and contexts',
coreApp: true,
entryPoints: {
lib: './src/index.js',
},
}

module.exports = config
11 changes: 8 additions & 3 deletions shell/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,20 @@
"typescript": "^3.6.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"build": "d2-app-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"analyze": "source-map-explorer 'build/static/js/*.js'"
},
"devDependencies": {
"@dhis2/cli-app-scripts": "^9.0.0",
"enzyme": "^3.10.0",
"enzyme-adapter-react-16": "^1.14.0",
"react-test-renderer": "^16.8.6"
},
"main": "./build/cjs/index.js",
"module": "./build/es/index.js",
"exports": {
"import": "./build/es/index.js",
"require": "./build/cjs/index.js"
}
}
Binary file removed shell/public/android-chrome-192x192.png
Binary file not shown.
Binary file removed shell/public/android-chrome-384x384.png
Binary file not shown.
Binary file removed shell/public/apple-touch-icon.png
Binary file not shown.
9 changes: 0 additions & 9 deletions shell/public/browserconfig.xml

This file was deleted.

Binary file removed shell/public/dhis2-app-icon.png
Binary file not shown.
Binary file removed shell/public/favicon-16x16.png
Binary file not shown.
Binary file removed shell/public/favicon-32x32.png
Binary file not shown.
Binary file removed shell/public/favicon-48x48.png
Binary file not shown.
Binary file removed shell/public/favicon.ico
Binary file not shown.
75 changes: 0 additions & 75 deletions shell/public/index.html

This file was deleted.

Binary file removed shell/public/mstile-150x150.png
Binary file not shown.
51 changes: 0 additions & 51 deletions shell/public/safari-pinned-tab.svg

This file was deleted.

20 changes: 0 additions & 20 deletions shell/public/service-worker.js

This file was deleted.

34 changes: 0 additions & 34 deletions shell/src/App.js

This file was deleted.

9 changes: 0 additions & 9 deletions shell/src/App.test.js

This file was deleted.

5 changes: 0 additions & 5 deletions shell/src/D2App/app.js

This file was deleted.

9 changes: 0 additions & 9 deletions shell/src/index.css

This file was deleted.

16 changes: 2 additions & 14 deletions shell/src/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,2 @@
import { CssReset } from '@dhis2/ui'
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import 'typeface-roboto'
import './index.css'

ReactDOM.render(
<>
<CssReset />
<App />
</>,
document.getElementById('dhis2-app-root')
)
import { Shell } from './shell.js'
export default Shell
3 changes: 0 additions & 3 deletions shell/src/service-worker.js

This file was deleted.

4 changes: 0 additions & 4 deletions shell/src/setupTests.js

This file was deleted.

32 changes: 32 additions & 0 deletions shell/src/shell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import AppAdapter from '@dhis2/app-adapter'
import { CssReset } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React from 'react'
import createAppConfig from './shell/create-app-config.js'
import LoadingDisplay from './shell/loading-display.js'
import verifyChildrenIsTheApp from './shell/verify-children-is-the-app.js'

export function Shell({ children }) {
verifyChildrenIsTheApp(children)

const appConfig = createAppConfig()
const appWithConfig = React.Children.map(
children,
child => React.cloneElement(child, { config: appConfig })
)

return (
<>
<CssReset />
<AppAdapter {...appConfig}>
<React.Suspense fallback={<LoadingDisplay />}>
{appWithConfig}
</React.Suspense>
</AppAdapter>
</>
)
}

Shell.propTypes = {
children: PropTypes.node,
}
10 changes: 10 additions & 0 deletions shell/src/shell/create-app-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default function createAppConfig() {
return {
url:
process.env.REACT_APP_DHIS2_BASE_URL ||
window.localStorage.DHIS2_BASE_URL,
appName: process.env.REACT_APP_DHIS2_APP_NAME || '',
apiVersion: parseInt(process.env.REACT_APP_DHIS2_API_VERSION),
pwaEnabled: process.env.REACT_APP_DHIS2_APP_PWA_ENABLED === 'true',
}
}
21 changes: 21 additions & 0 deletions shell/src/shell/loading-display.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import {
CenteredContent,
CircularLoader,
CssReset,
Layer,
layers
} from '@dhis2/ui'
import React from 'react'

export default function LoadingDisplay() {
return (
<>
<CssReset />
<Layer translucent level={layers.alert}>
<CenteredContent>
<CircularLoader />
</CenteredContent>
</Layer>
</>
)
}
10 changes: 10 additions & 0 deletions shell/src/shell/verify-children-is-the-app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'

export default function verifyChildrenIsTheApp(children) {
const childCount = React.Children.count(children)
if (childCount !== 1) {
throw new Error(
`The app-shell expects exactly 1 child (the app), received ${childCount} children`
)
}
}