Skip to content

Commit

Permalink
fix: use new TranslationDialog component (#2111)
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardo authored Oct 18, 2022
1 parent 0efd674 commit ce58d7f
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 301 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
"private": true,
"license": "BSD-3-Clause",
"dependencies": {
"@dhis2/analytics": "^24.1.1",
"@dhis2/analytics": "^24.2.5",
"@dhis2/app-runtime": "^3.4.4",
"@dhis2/app-runtime-adapter-d2": "^1.1.0",
"@dhis2/d2-i18n": "^1.1.0",
"@dhis2/d2-ui-core": "^7.3.3",
"@dhis2/d2-ui-interpretations": "^7.4.0",
"@dhis2/d2-ui-mentions-wrapper": "^7.3.3",
"@dhis2/d2-ui-rich-text": "^7.3.3",
"@dhis2/d2-ui-translation-dialog": "^7.3.3",
"@dhis2/data-visualizer-plugin": "^39.2.10",
"@dhis2/ui": "^8.5.1",
"classnames": "^2.3.1",
Expand Down
2 changes: 1 addition & 1 deletion src/components/DropdownButton/DropdownButton.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { OfflineTooltip } from '@dhis2/analytics'
import { Button, Layer, Popper } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React, { useRef } from 'react'
import OfflineTooltip from '../OfflineTooltip.js'
import { ArrowDown, ArrowUp } from './assets/Arrow.js'
import styles from './DropdownButton.module.css'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ exports[`renders disabled menu items when offline 1`] = `
class="jsx-3508410433 label"
>
<span
class="span notAllowed"
class="jsx-3661110597 tooltip notAllowed"
>
View as Chart
</span>
Expand Down Expand Up @@ -68,7 +68,7 @@ exports[`renders disabled menu items when offline 1`] = `
class="jsx-3508410433 label"
>
<span
class="span notAllowed"
class="jsx-3661110597 tooltip notAllowed"
>
View as Table
</span>
Expand Down Expand Up @@ -106,7 +106,7 @@ exports[`renders menu for active type CHART and type MAP 1`] = `
class="jsx-3508410433 label"
>
<span
class="span"
class="jsx-3661110597 tooltip"
>
View as Table
</span>
Expand Down Expand Up @@ -139,7 +139,7 @@ exports[`renders menu for active type CHART and type MAP 1`] = `
class="jsx-3508410433 label"
>
<span
class="span"
class="jsx-3661110597 tooltip"
>
View as Map
</span>
Expand Down Expand Up @@ -177,7 +177,7 @@ exports[`renders menu for active type CHART and type REPORT_TABLE 1`] = `
class="jsx-3508410433 label"
>
<span
class="span"
class="jsx-3661110597 tooltip"
>
View as Table
</span>
Expand Down Expand Up @@ -210,7 +210,7 @@ exports[`renders menu for active type CHART and type REPORT_TABLE 1`] = `
class="jsx-3508410433 label"
>
<span
class="span"
class="jsx-3661110597 tooltip"
>
View as Map
</span>
Expand Down Expand Up @@ -248,7 +248,7 @@ exports[`renders menu for active type EVENT_CHART and type EVENT_REPORT 1`] = `
class="jsx-3508410433 label"
>
<span
class="span"
class="jsx-3661110597 tooltip"
>
View as Table
</span>
Expand Down Expand Up @@ -293,7 +293,7 @@ exports[`renders menu for active type EVENT_REPORT and type EVENT_CHART 1`] = `
class="jsx-3508410433 label"
>
<span
class="span"
class="jsx-3661110597 tooltip"
>
View as Chart
</span>
Expand Down Expand Up @@ -338,7 +338,7 @@ exports[`renders menu for active type MAP and type CHART 1`] = `
class="jsx-3508410433 label"
>
<span
class="span"
class="jsx-3661110597 tooltip"
>
View as Chart
</span>
Expand Down Expand Up @@ -371,7 +371,7 @@ exports[`renders menu for active type MAP and type CHART 1`] = `
class="jsx-3508410433 label"
>
<span
class="span"
class="jsx-3661110597 tooltip"
>
View as Table
</span>
Expand Down Expand Up @@ -416,7 +416,7 @@ exports[`renders menu for active type MAP and type MAP without Thematic layer 1`
class="jsx-3508410433 label"
>
<span
class="span notAllowed"
class="jsx-3661110597 tooltip notAllowed"
>
View as Chart
</span>
Expand Down Expand Up @@ -449,7 +449,7 @@ exports[`renders menu for active type MAP and type MAP without Thematic layer 1`
class="jsx-3508410433 label"
>
<span
class="span notAllowed"
class="jsx-3661110597 tooltip notAllowed"
>
View as Table
</span>
Expand Down Expand Up @@ -494,7 +494,7 @@ exports[`renders menu for active type MAP and type MAP without Thematic layer wh
class="jsx-3508410433 label"
>
<span
class="span notAllowed"
class="jsx-3661110597 tooltip notAllowed"
>
View as Chart
</span>
Expand Down Expand Up @@ -527,7 +527,7 @@ exports[`renders menu for active type MAP and type MAP without Thematic layer wh
class="jsx-3508410433 label"
>
<span
class="span notAllowed"
class="jsx-3661110597 tooltip notAllowed"
>
View as Table
</span>
Expand Down Expand Up @@ -572,7 +572,7 @@ exports[`renders menu for active type REPORT_TABLE and type CHART 1`] = `
class="jsx-3508410433 label"
>
<span
class="span"
class="jsx-3661110597 tooltip"
>
View as Chart
</span>
Expand Down Expand Up @@ -605,7 +605,7 @@ exports[`renders menu for active type REPORT_TABLE and type CHART 1`] = `
class="jsx-3508410433 label"
>
<span
class="span"
class="jsx-3661110597 tooltip"
>
View as Map
</span>
Expand Down
2 changes: 1 addition & 1 deletion src/components/MenuItemWithTooltip.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { OfflineTooltip } from '@dhis2/analytics'
import { useOnlineStatus } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import { MenuItem } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React from 'react'
import OfflineTooltip from './OfflineTooltip.js'

const MenuItemWithTooltip = ({
disabledWhenOffline,
Expand Down
49 changes: 0 additions & 49 deletions src/components/OfflineTooltip.js

This file was deleted.

11 changes: 0 additions & 11 deletions src/components/styles/Tooltip.module.css

This file was deleted.

25 changes: 7 additions & 18 deletions src/pages/edit/ActionsBar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { OfflineTooltip, TranslationDialog } from '@dhis2/analytics'
import { useOnlineStatus, useDataEngine, useAlert } from '@dhis2/app-runtime'
import { useD2 } from '@dhis2/app-runtime-adapter-d2'
import i18n from '@dhis2/d2-i18n'
import TranslationDialog from '@dhis2/d2-ui-translation-dialog'
import { Button, ButtonStrip } from '@dhis2/ui'
import PropTypes from 'prop-types'
import React, { useState } from 'react'
Expand All @@ -18,7 +17,6 @@ import {
import { acClearPrintDashboard } from '../../actions/printDashboard.js'
import { acClearSelected } from '../../actions/selected.js'
import ConfirmActionDialog from '../../components/ConfirmActionDialog.js'
import OfflineTooltip from '../../components/OfflineTooltip.js'
import {
sGetEditDashboardRoot,
sGetIsPrintPreviewView,
Expand All @@ -41,8 +39,9 @@ const deleteFailedMessage = i18n.t(
'Failed to delete dashboard. You might be offline or not have access to edit this dashboard.'
)

const fieldsToTranslate = ['name', 'description']

const EditBar = ({ dashboard, ...props }) => {
const { d2 } = useD2()
const dataEngine = useDataEngine()
const { online } = useOnlineStatus()
const [translationDlgIsOpen, setTranslationDlgIsOpen] = useState(false)
Expand Down Expand Up @@ -159,23 +158,13 @@ const EditBar = ({ dashboard, ...props }) => {
}

const translationDialog = () =>
dashboard.id ? (
translationDlgIsOpen ? (
<TranslationDialog
className="translation-dialog"
d2={d2}
open={translationDlgIsOpen}
onRequestClose={toggleTranslationDialog}
objectToTranslate={{
...dashboard,
modelDefinition: { name: 'dashboard' },
}}
fieldsToTranslate={['name', 'description']}
onTranslationError={(err) =>
console.log('translation update error', err)
}
onClose={toggleTranslationDialog}
objectToTranslate={dashboard}
fieldsToTranslate={fieldsToTranslate}
onTranslationSaved={Function.prototype}
insertTheme={true}
isOnline={online}
/>
) : null

Expand Down
2 changes: 1 addition & 1 deletion src/pages/edit/LayoutModal.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { OfflineTooltip } from '@dhis2/analytics'
import { useOnlineStatus } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import {
Expand All @@ -13,7 +14,6 @@ import {
import cx from 'classnames'
import PropTypes from 'prop-types'
import React, { useEffect, useState } from 'react'
import OfflineTooltip from '../../components/OfflineTooltip.js'
import { GRID_COLUMNS } from '../../modules/gridUtil.js'
import { LayoutFixedIcon } from './assets/LayoutFixed.js'
import { LayoutFreeflowIcon } from './assets/LayoutFreeflow.js'
Expand Down
2 changes: 1 addition & 1 deletion src/pages/edit/TitleBar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { OfflineTooltip } from '@dhis2/analytics'
import { useOnlineStatus } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import { InputField, TextAreaField, Radio, Button } from '@dhis2/ui'
Expand All @@ -12,7 +13,6 @@ import {
acSetItemConfigInsertPosition,
acSetDashboardCode,
} from '../../actions/editDashboard.js'
import OfflineTooltip from '../../components/OfflineTooltip.js'
import { orObject } from '../../modules/util.js'
import {
sGetEditDashboardRoot,
Expand Down
24 changes: 10 additions & 14 deletions src/pages/edit/__tests__/ActionsBar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,17 @@ jest.mock('@dhis2/ui', () => {
/* eslint-enable react/prop-types */

/* eslint-disable react/prop-types */
jest.mock(
'../../../components/OfflineTooltip.js',
() =>
function Mock({ children }) {
jest.mock('@dhis2/analytics', () => {
const originalModule = jest.requireActual('@dhis2/analytics')

return {
__esModule: true,
...originalModule,
OfflineTooltip: function Mock({ children }) {
return <div className="OfflineTooltip">{children}</div>
}
)
},
}
})
/* eslint-enable react/prop-types */

jest.mock(
Expand All @@ -46,14 +50,6 @@ jest.mock(
}
)

jest.mock(
'@dhis2/d2-ui-translation-dialog',
() =>
function Mock() {
return <div className="mock-translation-dialog" />
}
)

/* eslint-disable react/prop-types */
jest.mock(
'../../../components/ConfirmActionDialog',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@ exports[`renders Translate, Delete, and Discard buttons when delete access 1`] =
<div
class="mock-filter-settings-dialog"
/>
<div
class="mock-translation-dialog"
/>
</div>
`;

Expand Down Expand Up @@ -209,8 +206,5 @@ exports[`renders the ActionsBar without Delete when no delete access 1`] = `
<div
class="mock-filter-settings-dialog"
/>
<div
class="mock-translation-dialog"
/>
</div>
`;
Loading

0 comments on commit ce58d7f

Please sign in to comment.