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

fix: save default dashboard title if user does not provide a title [DHIS2-9234] #1022

Merged
merged 3 commits into from
Aug 26, 2020
Merged
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
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: 2020-08-25T05:26:00.043Z\n"
"PO-Revision-Date: 2020-08-25T05:26:00.043Z\n"
"POT-Creation-Date: 2020-08-26T05:58:25.332Z\n"
"PO-Revision-Date: 2020-08-26T05:58:25.332Z\n"

msgid "Cancel"
msgstr ""
Expand Down Expand Up @@ -177,6 +177,9 @@ msgstr ""
msgid "Dashboard title"
msgstr ""

msgid "Untitled dashboard"
msgstr ""

msgid "Dashboard description"
msgstr ""

Expand Down
2 changes: 2 additions & 0 deletions src/actions/editDashboard.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { generateUid } from 'd2/uid'
import i18n from '@dhis2/d2-i18n'

import {
RECEIVED_EDIT_DASHBOARD,
Expand Down Expand Up @@ -125,6 +126,7 @@ export const tSaveDashboard = () => async (dispatch, getState) => {
const dashboardToSave = {
...dashboard,
dashboardItems: convertUiItemsToBackend(dashboard.dashboardItems),
name: dashboard.name || i18n.t('Untitled dashboard'),
}

try {
Expand Down
1 change: 1 addition & 0 deletions src/components/TitleBar/EditTitleBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const EditTitleBar = ({
type="text"
onChange={updateTitle}
value={name}
placeholder={i18n.t('Untitled dashboard')}
/>
<TextAreaField
className={classes.description}
Expand Down
13 changes: 6 additions & 7 deletions src/components/TitleBar/__tests__/EditTitleBar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { shallow } from 'enzyme'
import toJson from 'enzyme-to-json'
import { EditTitleBar } from '../EditTitleBar'

jest.mock('@dhis2/d2-ui-core/text-field/TextField', () => 'textfield')
jest.mock('../../ItemSelector/ItemSelector', () => 'itemselector')
jest.mock('@dhis2/d2-ui-core/text-field/TextField', () => 'TextField')
jest.mock('../../ItemSelector/ItemSelector', () => 'ItemSelector')

describe('EditTitleBar', () => {
const props = {
Expand All @@ -23,15 +23,14 @@ describe('EditTitleBar', () => {
},
}

it('renders correctly when displayName not provided', () => {
it('renders correctly', () => {
const tree = shallow(<EditTitleBar {...props} />)
expect(toJson(tree)).toMatchSnapshot()
})

it('renders correctly when displayName is provided', () => {
const tree = shallow(
<EditTitleBar displayName="Regnbue Dash" {...props} />
)
it('renders correctly when no name', () => {
props.name = ''
const tree = shallow(<EditTitleBar {...props} />)
expect(toJson(tree)).toMatchSnapshot()
})
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EditTitleBar renders correctly when displayName is provided 1`] = `
exports[`EditTitleBar renders correctly 1`] = `
<section
className="section"
>
Expand All @@ -13,6 +13,7 @@ exports[`EditTitleBar renders correctly when displayName is provided 1`] = `
label="Dashboard title"
name="Dashboard title input"
onChange={[Function]}
placeholder="Untitled dashboard"
type="text"
value="Rainbow Dash"
/>
Expand All @@ -31,12 +32,12 @@ exports[`EditTitleBar renders correctly when displayName is provided 1`] = `
<div
className="itemSelector"
>
<itemselector />
<ItemSelector />
</div>
</section>
`;

exports[`EditTitleBar renders correctly when displayName not provided 1`] = `
exports[`EditTitleBar renders correctly when no name 1`] = `
<section
className="section"
>
Expand All @@ -49,8 +50,9 @@ exports[`EditTitleBar renders correctly when displayName not provided 1`] = `
label="Dashboard title"
name="Dashboard title input"
onChange={[Function]}
placeholder="Untitled dashboard"
type="text"
value="Rainbow Dash"
value=""
/>
<TextAreaField
className="description"
Expand All @@ -67,7 +69,7 @@ exports[`EditTitleBar renders correctly when displayName not provided 1`] = `
<div
className="itemSelector"
>
<itemselector />
<ItemSelector />
</div>
</section>
`;