Skip to content

Commit

Permalink
feat: add keyEmbeddedDashboardsEnabled [DHIS2-18472] (#1409)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp authored Dec 16, 2024
1 parent 93bc7a0 commit 8e36284
Show file tree
Hide file tree
Showing 5 changed files with 406 additions and 116 deletions.
7 changes: 5 additions & 2 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2024-06-28T11:48:52.681Z\n"
"PO-Revision-Date: 2024-06-28T11:48:52.681Z\n"
"POT-Creation-Date: 2024-11-27T12:04:49.662Z\n"
"PO-Revision-Date: 2024-11-27T12:04:49.662Z\n"

msgid "Failed to load: {{error}}"
msgstr "Failed to load: {{error}}"
Expand Down Expand Up @@ -548,6 +548,9 @@ msgstr "Respect category option start and end date in analytics table export"
msgid "Include zero data values in analytics tables"
msgstr "Include zero data values in analytics tables"

msgid "Enable embedded dashboards"
msgstr "Enable embedded dashboards"

msgid "Caching factor"
msgstr "Caching factor"

Expand Down
48 changes: 30 additions & 18 deletions src/app.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import React from 'react'
import styles from './App.module.css'
import configOptionStore from './configOptionStore.js'
import settingsActions from './settingsActions.js'
import { categoryOrder, categories } from './settingsCategories.js'
import {
categoryOrder,
categories,
filterCategoryOrderByApiVersion,
filterCategoriesByApiVersion,
filterSettingsByApiVersion,
} from './settingsCategories.js'
import SettingsFields from './settingsFields.component.js'
import appTheme from './theme.js'

Expand All @@ -18,7 +24,10 @@ class AppComponent extends React.Component {

this.state = {
category: categoryOrder[0],
currentSettings: categories[categoryOrder[0]].settings,
currentSettings: filterSettingsByApiVersion({
settings: categories[categoryOrder[0]].settings,
apiVersion: props.apiVersion,
}),
snackbarMessage: '',
showSnackbar: false,
formValidator: undefined,
Expand All @@ -37,7 +46,7 @@ class AppComponent extends React.Component {
}

componentDidMount() {
settingsActions.load()
settingsActions.load({ apiVersion: this.props.apiVersion })
this.subscriptions = []

this.subscriptions.push(
Expand Down Expand Up @@ -78,7 +87,10 @@ class AppComponent extends React.Component {

this.setState({
category,
currentSettings,
currentSettings: filterSettingsByApiVersion({
settings: currentSettings,
apiVersion: this.props.apiVersion,
}),
searchText:
category === 'search' ? this.state.searchText : '',
})
Expand All @@ -97,25 +109,25 @@ class AppComponent extends React.Component {

// Filter categories based on apiVersion
const { apiVersion } = this.props
const filteredCategoryOrder = categoryOrder.filter(
(category) =>
!categories[category].maximumApiVersion ||
apiVersion <= categories[category].maximumApiVersion
)
const filteredCategories = Object.fromEntries(
Object.entries(categories).filter(
([key]) =>
!categories[key].maximumApiVersion ||
apiVersion <= categories[key].maximumApiVersion
)
)
const filteredCategoryOrder = filterCategoryOrderByApiVersion({
categoryOrder,
categories,
apiVersion,
})

const filteredCategories = filterCategoriesByApiVersion({
categories,
apiVersion,
})

this.setState({
filteredCategoryOrder,
filteredCategories,
category: filteredCategoryOrder[0],
currentSettings:
filteredCategories[filteredCategoryOrder[0]].settings,
currentSettings: filterSettingsByApiVersion({
settings: filteredCategories[filteredCategoryOrder[0]].settings,
apiVersion: apiVersion,
}),
})

// Helper function for setting app state based on location using filtered categories
Expand Down
18 changes: 15 additions & 3 deletions src/settingsActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import i18n from '@dhis2/d2-i18n'
import { getInstance as getD2 } from 'd2'
import Action from 'd2-ui/lib/action/Action.js'
import { Observable } from 'rxjs'
import { categories } from './settingsCategories.js'
import {
categories,
filterCategoriesByApiVersion,
filterSettingsByApiVersion,
} from './settingsCategories.js'
import settingsKeyMapping from './settingsKeyMapping.js'
import settingsStore from './settingsStore.js'

Expand Down Expand Up @@ -92,6 +96,7 @@ settingsActions.saveKey.subscribe((args) => {
const settingsSearchMap = Observable.fromPromise(
new Promise((resolve) => {
settingsActions.load.subscribe((args) => {
const { apiVersion } = args?.data || {}
getD2().then((d2) => {
// Get current settings and configuration
Promise.all([
Expand Down Expand Up @@ -142,15 +147,22 @@ const settingsSearchMap = Observable.fromPromise(
)

// Build the search index
const searchMapping = Object.keys(categories)
const searchMapping = Object.keys(
filterCategoriesByApiVersion({ categories, apiVersion })
)
.filter(
(categoryKey) =>
!categories[categoryKey].authority ||
d2.currentUser.authorities.has(
categories[categoryKey].authority
)
)
.map((categoryKey) => categories[categoryKey].settings)
.map((categoryKey) =>
filterSettingsByApiVersion({
settings: categories[categoryKey].settings,
apiVersion,
})
)
.reduce(
(searchArray, categoryKeys) =>
searchArray.concat(categoryKeys),
Expand Down
Loading

1 comment on commit 8e36284

@dhis2-bot
Copy link
Contributor

Choose a reason for hiding this comment

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

Please sign in to comment.