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

chore: allow for unversioned api links #1374

Closed
wants to merge 1 commit 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
32 changes: 16 additions & 16 deletions examples/cra/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1054,32 +1054,32 @@
integrity sha512-ij4wRiunFfaJxjB0BdrYHIH8FxBJpOwNPhhAcunlmPdXudL1WQV1qoP9un6JsEBAgQH+7UXyyjh0g7jTxXK6tg==

"@dhis2/app-runtime@file:../../runtime":
version "3.10.0-alpha.2"
version "3.10.2"
dependencies:
"@dhis2/app-service-alerts" "3.10.0-alpha.2"
"@dhis2/app-service-config" "3.10.0-alpha.2"
"@dhis2/app-service-data" "3.10.0-alpha.2"
"@dhis2/app-service-offline" "3.10.0-alpha.2"
"@dhis2/app-service-plugin" "3.10.0-alpha.2"
"@dhis2/app-service-alerts" "3.10.2"
"@dhis2/app-service-config" "3.10.2"
"@dhis2/app-service-data" "3.10.2"
"@dhis2/app-service-offline" "3.10.2"
"@dhis2/app-service-plugin" "3.10.2"

"@dhis2/app-service-alerts@3.10.0-alpha.2", "@dhis2/app-service-alerts@file:../../services/alerts":
version "3.10.0-alpha.2"
"@dhis2/app-service-alerts@3.10.2", "@dhis2/app-service-alerts@file:../../services/alerts":
version "3.10.2"

"@dhis2/app-service-config@3.10.0-alpha.2", "@dhis2/app-service-config@file:../../services/config":
version "3.10.0-alpha.2"
"@dhis2/app-service-config@3.10.2", "@dhis2/app-service-config@file:../../services/config":
version "3.10.2"

"@dhis2/app-service-data@3.10.0-alpha.2", "@dhis2/app-service-data@file:../../services/data":
version "3.10.0-alpha.2"
"@dhis2/app-service-data@3.10.2", "@dhis2/app-service-data@file:../../services/data":
version "3.10.2"
dependencies:
react-query "^3.13.11"

"@dhis2/app-service-offline@3.10.0-alpha.2", "@dhis2/app-service-offline@file:../../services/offline":
version "3.10.0-alpha.2"
"@dhis2/app-service-offline@3.10.2", "@dhis2/app-service-offline@file:../../services/offline":
version "3.10.2"
dependencies:
lodash "^4.17.21"

"@dhis2/app-service-plugin@3.10.0-alpha.2", "@dhis2/app-service-plugin@file:../../services/plugin":
version "3.10.0-alpha.2"
"@dhis2/app-service-plugin@3.10.2", "@dhis2/app-service-plugin@file:../../services/plugin":
version "3.10.2"
dependencies:
post-robot "^10.0.46"

Expand Down
32 changes: 16 additions & 16 deletions examples/query-playground/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1800,32 +1800,32 @@
"@dhis2/app-service-offline" "3.8.0"

"@dhis2/app-runtime@^2.2.2", "@dhis2/app-runtime@file:../../runtime":
version "3.10.0-alpha.2"
version "3.10.2"
dependencies:
"@dhis2/app-service-alerts" "3.10.0-alpha.2"
"@dhis2/app-service-config" "3.10.0-alpha.2"
"@dhis2/app-service-data" "3.10.0-alpha.2"
"@dhis2/app-service-offline" "3.10.0-alpha.2"
"@dhis2/app-service-plugin" "3.10.0-alpha.2"
"@dhis2/app-service-alerts" "3.10.2"
"@dhis2/app-service-config" "3.10.2"
"@dhis2/app-service-data" "3.10.2"
"@dhis2/app-service-offline" "3.10.2"
"@dhis2/app-service-plugin" "3.10.2"

"@dhis2/app-service-alerts@3.10.0-alpha.2", "@dhis2/app-service-alerts@3.8.0", "@dhis2/app-service-alerts@file:../../services/alerts":
version "3.10.0-alpha.2"
"@dhis2/app-service-alerts@3.10.2", "@dhis2/app-service-alerts@3.8.0", "@dhis2/app-service-alerts@file:../../services/alerts":
version "3.10.2"

"@dhis2/app-service-config@3.10.0-alpha.2", "@dhis2/app-service-config@3.8.0", "@dhis2/app-service-config@file:../../services/config":
version "3.10.0-alpha.2"
"@dhis2/app-service-config@3.10.2", "@dhis2/app-service-config@3.8.0", "@dhis2/app-service-config@file:../../services/config":
version "3.10.2"

"@dhis2/app-service-data@3.10.0-alpha.2", "@dhis2/app-service-data@3.8.0", "@dhis2/app-service-data@file:../../services/data":
version "3.10.0-alpha.2"
"@dhis2/app-service-data@3.10.2", "@dhis2/app-service-data@3.8.0", "@dhis2/app-service-data@file:../../services/data":
version "3.10.2"
dependencies:
react-query "^3.13.11"

"@dhis2/app-service-offline@3.10.0-alpha.2", "@dhis2/app-service-offline@3.8.0", "@dhis2/app-service-offline@file:../../services/offline":
version "3.10.0-alpha.2"
"@dhis2/app-service-offline@3.10.2", "@dhis2/app-service-offline@3.8.0", "@dhis2/app-service-offline@file:../../services/offline":
version "3.10.2"
dependencies:
lodash "^4.17.21"

"@dhis2/app-service-plugin@3.10.0-alpha.2", "@dhis2/app-service-plugin@file:../../services/plugin":
version "3.10.0-alpha.2"
"@dhis2/app-service-plugin@3.10.2", "@dhis2/app-service-plugin@file:../../services/plugin":
version "3.10.2"
dependencies:
post-robot "^10.0.46"

Expand Down
4 changes: 3 additions & 1 deletion runtime/src/Provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ type ProviderInput = {
plugin: boolean
parentAlertsAdd: any
showAlertsInPlugin: boolean
skipApiVersion: boolean
}
export const Provider = ({
config,
Expand All @@ -20,14 +21,15 @@ export const Provider = ({
plugin,
parentAlertsAdd,
showAlertsInPlugin,
skipApiVersion,
}: ProviderInput) => (
<ConfigProvider config={config}>
<AlertsProvider
plugin={plugin}
parentAlertsAdd={parentAlertsAdd}
showAlertsInPlugin={showAlertsInPlugin}
>
<DataProvider>
<DataProvider skipApiVersion={skipApiVersion}>
<OfflineProvider offlineInterface={offlineInterface}>
{children}
</OfflineProvider>
Expand Down
2 changes: 1 addition & 1 deletion services/config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ export { useConfig } from './useConfig'
export { useTimeZoneConversion } from './useTimeZoneConversion'
export { ConfigProvider } from './ConfigProvider'

export type { Config, Version } from './types'
export type { Config, ConfigWithSkipApiVersion, Version } from './types'
4 changes: 4 additions & 0 deletions services/config/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ export interface Config {
serverVersion?: Version
systemInfo?: SystemInfo
}

export interface ConfigWithSkipApiVersion extends Config {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The extra props provided to provider are actually already being passed downwards (https://github.com/dhis2/app-runtime/blob/master/services/data/src/react/components/DataProvider.tsx#L36-L39)

but the type definition used (e.g. https://github.com/dhis2/app-runtime/pull/1374/files#diff-accda02931529da3af34ae8dbe9c0ea5549c444fdbcaf5a7d504a086dfd9331eR76) caused problems, so I'm extending it.

I'm not sure what the logic was of originally passing the props as part of the config, so I haven't updated things any more.

skipApiVersion?: boolean
}
15 changes: 14 additions & 1 deletion services/data/src/links/RestAPILink/queryToResourcePath.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Config } from '@dhis2/app-service-config'
import { Config, ConfigWithSkipApiVersion } from '@dhis2/app-service-config'
import { ResolvedResourceQuery } from '../../engine'
import { RestAPILink } from '../RestAPILink'
import { queryToResourcePath } from './queryToResourcePath'
Expand Down Expand Up @@ -202,4 +202,17 @@ describe('queryToResourcePath', () => {
`${link.versionedApiPath}/tracker`
)
})

it('should return a unversioned endpoint if config.skipApiVersion is true', () => {
const query: ResolvedResourceQuery = {
resource: 'loginConfig',
}
const skipApiVersionConfig: ConfigWithSkipApiVersion = {
...defaultConfig,
skipApiVersion: true,
}
expect(
queryToResourcePath(createLink(skipApiVersionConfig), query, 'read')
).toBe(`${link.unversionedApiPath}/loginConfig`)
})
})
11 changes: 9 additions & 2 deletions services/data/src/links/RestAPILink/queryToResourcePath.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Config } from '@dhis2/app-service-config'
import type { ConfigWithSkipApiVersion } from '@dhis2/app-service-config'
import {
ResolvedResourceQuery,
QueryParameters,
Expand Down Expand Up @@ -71,7 +71,14 @@ const makeActionPath = (resource: string) =>
`${resource.substr(actionPrefix.length)}.action`
)

const skipApiVersion = (resource: string, config: Config): boolean => {
const skipApiVersion = (
resource: string,
config: ConfigWithSkipApiVersion
): boolean => {
if (config?.skipApiVersion) {
return true
}

if (resource === 'tracker' || resource.startsWith('tracker/')) {
if (!config.serverVersion?.minor || config.serverVersion?.minor < 38) {
return true
Expand Down
1 change: 1 addition & 0 deletions services/data/src/react/components/DataProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { DataContext } from '../context/DataContext'
export interface ProviderInput {
baseUrl?: string
apiVersion?: number
skipApiVersion?: boolean
children: React.ReactNode
}

Expand Down
34 changes: 0 additions & 34 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2734,40 +2734,6 @@
"@dhis2/pwa" "10.2.0"
moment "^2.24.0"

"@dhis2/app-runtime@^3.6.1":
version "3.9.0"
resolved "https://registry.yarnpkg.com/@dhis2/app-runtime/-/app-runtime-3.9.0.tgz#c7e295fd0a68fac976a930bc77105206ded0b61a"
integrity sha512-n0S4pbyvK7FnBQFMONGrhR9YYavBQI+mQLHfCX/vtvOyeoioBUNIinuQlGysuLMEkSVaK5OjV40rvTMzdxF2kQ==
dependencies:
"@dhis2/app-service-alerts" "3.9.0"
"@dhis2/app-service-config" "3.9.0"
"@dhis2/app-service-data" "3.9.0"
"@dhis2/app-service-offline" "3.9.0"

"@dhis2/app-service-alerts@3.9.0":
version "3.9.0"
resolved "https://registry.yarnpkg.com/@dhis2/app-service-alerts/-/app-service-alerts-3.9.0.tgz#48d3805676e75ee58104fea4f76cfa779335444e"
integrity sha512-z2eZxm/pxrmFbisbK7/qJKtif2CNWJjaaAH5rfrs5OIajlHy3rO37vSaTQHWv+xWvZFQrs2Op2InxzG0qh5ncA==

"@dhis2/app-service-config@3.9.0":
version "3.9.0"
resolved "https://registry.yarnpkg.com/@dhis2/app-service-config/-/app-service-config-3.9.0.tgz#8dc59d8de246f54057c0c685d5f94b4cbade6f73"
integrity sha512-OuRn2mJGrQQ8QIC+oIVYYpclB4LErRK2wtsuy/cXLfRbeUti1qWIh110rgd1hnTx+BgRCs5s3NWdIQxS4hYGIQ==

"@dhis2/app-service-data@3.9.0":
version "3.9.0"
resolved "https://registry.yarnpkg.com/@dhis2/app-service-data/-/app-service-data-3.9.0.tgz#37f528b5f7f589cbab8dcc7f997c1668bc6566a9"
integrity sha512-/FJgJhL6YGtIVNX5oaNmavkGmimrVHQsS8ueeUO4FvTjYXGlnnN3IuxypQcy/x4yiUyigbPgFJRnbC1J2af2fg==
dependencies:
react-query "^3.13.11"

"@dhis2/app-service-offline@3.9.0":
version "3.9.0"
resolved "https://registry.yarnpkg.com/@dhis2/app-service-offline/-/app-service-offline-3.9.0.tgz#fe4f4a91a1da77554965f6a5fe6f6951d4c467f4"
integrity sha512-0q5zl0vw+a47Ab2qgu6hsZY5ybnH/ea43Vkk4aXYdgcf57xB8ck9DkIcNbc2e1+k9FhvimipxsgTZSbEA/8hJA==
dependencies:
lodash "^4.17.21"

"@dhis2/app-shell@10.2.0":
version "10.2.0"
resolved "https://registry.yarnpkg.com/@dhis2/app-shell/-/app-shell-10.2.0.tgz#2f69aa047dedb6545c75052d8969a80502f0d4a6"
Expand Down
Loading