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

feat: add useLoginSettings hook [LIBS-516] #1354

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion examples/cra/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"@dhis2/app-service-alerts": "file:../../services/alerts",
"@dhis2/app-service-config": "file:../../services/config",
"@dhis2/app-service-data": "file:../../services/data",
"@dhis2/app-service-offline": "file:../../services/offline"
"@dhis2/app-service-offline": "file:../../services/offline",
"@dhis2/app-service-login-settings": "file:../../services/login-settings"
},
"scripts": {
"start": "react-scripts start",
Expand Down
30 changes: 17 additions & 13 deletions examples/cra/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1054,26 +1054,30 @@
integrity sha512-ij4wRiunFfaJxjB0BdrYHIH8FxBJpOwNPhhAcunlmPdXudL1WQV1qoP9un6JsEBAgQH+7UXyyjh0g7jTxXK6tg==

"@dhis2/app-runtime@file:../../runtime":
version "3.6.1"
version "3.9.4"
dependencies:
"@dhis2/app-service-alerts" "3.6.1"
"@dhis2/app-service-config" "3.6.1"
"@dhis2/app-service-data" "3.6.1"
"@dhis2/app-service-offline" "3.6.1"
"@dhis2/app-service-alerts" "3.9.4"
"@dhis2/app-service-config" "3.9.4"
"@dhis2/app-service-data" "3.9.4"
"@dhis2/app-service-login-settings" "3.9.4"
"@dhis2/app-service-offline" "3.9.4"

"@dhis2/app-service-alerts@3.6.1", "@dhis2/app-service-alerts@file:../../services/alerts":
version "3.6.1"
"@dhis2/app-service-alerts@3.9.4", "@dhis2/app-service-alerts@file:../../services/alerts":
version "3.9.4"

"@dhis2/app-service-config@3.6.1", "@dhis2/app-service-config@file:../../services/config":
version "3.6.1"
"@dhis2/app-service-config@3.9.4", "@dhis2/app-service-config@file:../../services/config":
version "3.9.4"

"@dhis2/app-service-data@3.6.1", "@dhis2/app-service-data@file:../../services/data":
version "3.6.1"
"@dhis2/app-service-data@3.9.4", "@dhis2/app-service-data@file:../../services/data":
version "3.9.4"
dependencies:
react-query "^3.13.11"

"@dhis2/[email protected]", "@dhis2/app-service-offline@file:../../services/offline":
version "3.6.1"
"@dhis2/[email protected]", "@dhis2/app-service-login-settings@file:../../services/login-settings":
version "3.9.4"

"@dhis2/[email protected]", "@dhis2/app-service-offline@file:../../services/offline":
version "3.9.4"
dependencies:
lodash "^4.17.21"

Expand Down
3 changes: 2 additions & 1 deletion examples/query-playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@dhis2/app-service-alerts": "file:../../services/alerts",
"@dhis2/app-service-config": "file:../../services/config",
"@dhis2/app-service-data": "file:../../services/data",
"@dhis2/app-service-offline": "file:../../services/offline"
"@dhis2/app-service-offline": "file:../../services/offline",
"@dhis2/app-service-login-settings": "file:../../services/login-settings"
}
}
30 changes: 17 additions & 13 deletions examples/query-playground/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1800,26 +1800,30 @@
"@dhis2/app-service-offline" "3.7.0"

"@dhis2/app-runtime@^2.2.2", "@dhis2/app-runtime@file:../../runtime":
version "3.6.1"
version "3.9.4"
dependencies:
"@dhis2/app-service-alerts" "3.6.1"
"@dhis2/app-service-config" "3.6.1"
"@dhis2/app-service-data" "3.6.1"
"@dhis2/app-service-offline" "3.6.1"
"@dhis2/app-service-alerts" "3.9.4"
"@dhis2/app-service-config" "3.9.4"
"@dhis2/app-service-data" "3.9.4"
"@dhis2/app-service-login-settings" "3.9.4"
"@dhis2/app-service-offline" "3.9.4"

"@dhis2/app-service-alerts@3.6.1", "@dhis2/app-service-alerts@3.7.0", "@dhis2/app-service-alerts@file:../../services/alerts":
version "3.6.1"
"@dhis2/app-service-alerts@3.7.0", "@dhis2/app-service-alerts@3.9.4", "@dhis2/app-service-alerts@file:../../services/alerts":
version "3.9.4"

"@dhis2/app-service-config@3.6.1", "@dhis2/app-service-config@3.7.0", "@dhis2/app-service-config@file:../../services/config":
version "3.6.1"
"@dhis2/app-service-config@3.7.0", "@dhis2/app-service-config@3.9.4", "@dhis2/app-service-config@file:../../services/config":
version "3.9.4"

"@dhis2/app-service-data@3.6.1", "@dhis2/app-service-data@3.7.0", "@dhis2/app-service-data@file:../../services/data":
version "3.6.1"
"@dhis2/app-service-data@3.7.0", "@dhis2/app-service-data@3.9.4", "@dhis2/app-service-data@file:../../services/data":
version "3.9.4"
dependencies:
react-query "^3.13.11"

"@dhis2/[email protected]", "@dhis2/[email protected]", "@dhis2/app-service-offline@file:../../services/offline":
version "3.6.1"
"@dhis2/[email protected]", "@dhis2/app-service-login-settings@file:../../services/login-settings":
version "3.9.4"

"@dhis2/[email protected]", "@dhis2/[email protected]", "@dhis2/app-service-offline@file:../../services/offline":
version "3.9.4"
dependencies:
lodash "^4.17.21"

Expand Down
3 changes: 2 additions & 1 deletion runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"@dhis2/app-service-config": "3.9.4",
"@dhis2/app-service-data": "3.9.4",
"@dhis2/app-service-alerts": "3.9.4",
"@dhis2/app-service-offline": "3.9.4"
"@dhis2/app-service-offline": "3.9.4",
"@dhis2/app-service-login-settings": "3.9.4"
},
"peerDependencies": {
"prop-types": "^15.7.2",
Expand Down
12 changes: 11 additions & 1 deletion runtime/src/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,34 @@ import { AlertsProvider } from '@dhis2/app-service-alerts'
import { ConfigProvider } from '@dhis2/app-service-config'
import { Config } from '@dhis2/app-service-config/build/types/types'
import { DataProvider } from '@dhis2/app-service-data'
import { LoginSettingsProvider } from '@dhis2/app-service-login-settings'
import { OfflineProvider } from '@dhis2/app-service-offline'
import React from 'react'

type ProviderInput = {
config: Config
children: React.ReactNode
offlineInterface?: any // temporary until offline service has types
loginApp: boolean
}

export const Provider = ({
config,
children,
offlineInterface,
loginApp,
}: ProviderInput) => (
<ConfigProvider config={config}>
<AlertsProvider>
<DataProvider>
<OfflineProvider offlineInterface={offlineInterface}>
{children}
{loginApp ? (
<LoginSettingsProvider>
{children}
</LoginSettingsProvider>
) : (
<>{children}</>
)}
</OfflineProvider>
</DataProvider>
</AlertsProvider>
Expand Down
2 changes: 2 additions & 0 deletions runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ export {
clearSensitiveCaches,
} from '@dhis2/app-service-offline'

export { useLoginSettings } from '@dhis2/app-service-login-settings'

export { Provider } from './Provider'
5 changes: 5 additions & 0 deletions services/login-settings/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# DHIS2 Platform
node_modules
.d2
src/locales
build
11 changes: 11 additions & 0 deletions services/login-settings/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# DHIS2 App Login Settings Service

This service exposes system settings needed for login applications for [DHIS2](https://dhis2.org).

This library is intended for use with the [DHIS2 Application Platform](https://github.com/dhis2/app-platform).

## Installation

This package is internal to `@dhis2/app-runtime` and generally should not be installed independently.

See [the docs](https://runtime.dhis2.nu) for more.
9 changes: 9 additions & 0 deletions services/login-settings/d2.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const config = {
type: 'lib',

entryPoints: {
lib: './src/index.ts',
},
}

module.exports = config
14 changes: 14 additions & 0 deletions services/login-settings/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
collectCoverageFrom: [
'src/**/*.(js|jsx|ts|tsx)',
'!src/index.ts',
'!src/**/types/*',
'!src/**/types.ts',
],

// Setup react-testing-library
setupFilesAfterEnv: ['<rootDir>/src/setupRTL.ts'],
// Fix for Jest 27
// https://github.com/facebook/jest/issues/11404#issuecomment-1003328922
testRunner: 'jest-jasmine2',
}
41 changes: 41 additions & 0 deletions services/login-settings/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@dhis2/app-service-login-settings",
"description": "A runtime service for login settings",
"version": "3.9.4",
"main": "./build/cjs/index.js",
"module": "./build/es/index.js",
"types": "build/types/index.d.ts",
"exports": {
"import": "./build/es/index.js",
"require": "./build/cjs/index.js"
},
"repository": {
"type": "git",
"url": "https://github.com/dhis2/app-runtime.git",
"directory": "services/login-settings"
},
"author": "Thomas Zemp <[email protected]>",
"license": "BSD-3-Clause",
"publishConfig": {
"access": "public"
},
"files": [
"build/**"
],
"scripts": {
"build:types": "tsc --emitDeclarationOnly --outDir ./build/types",
"build:package": "d2-app-scripts build",
"build": "concurrently -n build,types \"yarn build:package\" \"yarn build:types\"",
"watch": "NODE_ENV=development concurrently -n build,types \"yarn build:package --watch\" \"yarn build:types --watch\"",
"type-check": "tsc --noEmit --allowJs --checkJs",
"type-check:watch": "yarn type-check --watch",
"test": "d2-app-scripts test",
"coverage": "yarn test --coverage"
},
"peerDependencies": {
"@dhis2/app-service-config": "3.9.4",
"prop-types": "^15.7.2",
"react": "^16.8.6",
"react-dom": "^16.8.6"
}
}
26 changes: 26 additions & 0 deletions services/login-settings/src/LoginSettingsContext.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from 'react'
import { LoginSettings } from './types'

export const LoginSettingsContext = React.createContext<LoginSettings>({
applicationDescription: '',
applicationFooter: '',
applicationNotification: '',
allowAccountRecovery: false,
applicationTitle: '',
countryFlag: '',
useCountryFlag: false,
loginPageLogo: '',
useLoginPageLogo: false,
emailConfigured: false,
selfRegistrationEnabled: false,
selfRegistrationNoRecaptcha: false,
systemUiLocale: '',
uiLocale: '',
localesUI: [],
htmlTemplate: '',
refreshOnTranslation: ({ locale }) => {
throw new Error('This function is not implemented')
},
error: null,
called: false,
})
Loading