-
Notifications
You must be signed in to change notification settings - Fork 36
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: ou item filter on App items was crashing Dashboards [DHIS2-9725] #1183
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { render } from '@testing-library/react' | ||
import { Provider } from 'react-redux' | ||
import configureMockStore from 'redux-mock-store' | ||
|
||
import Item from '../Item' | ||
|
||
const mockStore = configureMockStore() | ||
|
||
const item = { | ||
appKey: 'scorecard', | ||
id: 'rainbowdash', | ||
shortened: false, | ||
} | ||
|
||
test('renders a valid App item in view mode', () => { | ||
const store = { | ||
itemFilters: {}, | ||
} | ||
const { container } = render( | ||
<Provider store={mockStore(store)}> | ||
<D2Provider> | ||
<Item item={item} dashboardMode={'view'} /> | ||
</D2Provider> | ||
</Provider> | ||
) | ||
expect(container).toMatchSnapshot() | ||
}) | ||
|
||
test('renders a valid App item with filter in view mode', () => { | ||
const store = { | ||
itemFilters: { | ||
ou: [{ path: '/rainbow' }], | ||
}, | ||
} | ||
|
||
const { container } = render( | ||
<Provider store={mockStore(store)}> | ||
<D2Provider> | ||
<Item item={item} dashboardMode={'view'} /> | ||
</D2Provider> | ||
</Provider> | ||
) | ||
expect(container).toMatchSnapshot() | ||
}) | ||
|
||
test('renders a valid App item with filter in edit mode', () => { | ||
const store = { | ||
itemFilters: { | ||
ou: [{ path: '/rainbow' }], | ||
}, | ||
} | ||
|
||
const { container } = render( | ||
<Provider store={mockStore(store)}> | ||
<D2Provider> | ||
<Item item={item} dashboardMode={'edit'} /> | ||
</D2Provider> | ||
</Provider> | ||
) | ||
expect(container).toMatchSnapshot() | ||
}) | ||
|
||
test('renders an invalid App item', () => { | ||
const store = { | ||
itemFilters: { | ||
ou: [{ path: '/rainbow' }], | ||
}, | ||
} | ||
|
||
const invalidItem = { | ||
appKey: 'unknownApp', | ||
id: 'unknown', | ||
shortened: false, | ||
} | ||
|
||
const { container } = render( | ||
<Provider store={mockStore(store)}> | ||
<D2Provider> | ||
<Item item={invalidItem} dashboardMode={'edit'} /> | ||
</D2Provider> | ||
</Provider> | ||
) | ||
expect(container).toMatchSnapshot() | ||
}) | ||
|
||
// Mock context provider | ||
class D2Provider extends React.Component { | ||
getChildContext() { | ||
return { | ||
d2: { | ||
system: { | ||
installedApps: [ | ||
{ | ||
key: 'scorecard', | ||
name: 'Scorecard', | ||
launchUrl: 'launchurl', | ||
}, | ||
], | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
render() { | ||
return this.props.children | ||
} | ||
} | ||
|
||
D2Provider.childContextTypes = { | ||
d2: PropTypes.object, | ||
} | ||
|
||
D2Provider.propTypes = { | ||
children: PropTypes.node, | ||
} |
124 changes: 124 additions & 0 deletions
124
src/components/Item/AppItem/__tests__/__snapshots__/Item.spec.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`renders a valid App item in view mode 1`] = ` | ||
<div> | ||
<div | ||
class="itemHeaderWrap" | ||
> | ||
<p | ||
class="itemTitle" | ||
> | ||
Scorecard | ||
</p> | ||
</div> | ||
<hr | ||
style="background-color: rgb(243, 245, 247); height: 1px; margin: 0px 0px 5px 0px;" | ||
/> | ||
<iframe | ||
class="dashboard-item-content" | ||
src="launchurl?dashboardItemId=rainbowdash" | ||
title="Scorecard" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`renders a valid App item with filter in edit mode 1`] = ` | ||
<div> | ||
<div | ||
class="itemHeaderWrap" | ||
> | ||
<p | ||
class="itemTitle" | ||
> | ||
Scorecard | ||
</p> | ||
<div | ||
class="itemActionsWrap" | ||
> | ||
<button | ||
class="deleteItemButton" | ||
title="Delete item" | ||
type="button" | ||
> | ||
<svg | ||
aria-hidden="true" | ||
class="MuiSvgIcon-root-1" | ||
focusable="false" | ||
role="presentation" | ||
style="fill: #d32f2f;" | ||
viewBox="0 0 24 24" | ||
> | ||
<path | ||
d="M6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM19 4h-3.5l-1-1h-5l-1 1H5v2h14V4z" | ||
/> | ||
</svg> | ||
</button> | ||
</div> | ||
</div> | ||
<hr | ||
style="background-color: rgb(243, 245, 247); height: 1px; margin: 0px 0px 5px 0px;" | ||
/> | ||
<iframe | ||
class="dashboard-item-content" | ||
src="launchurl?dashboardItemId=rainbowdash" | ||
title="Scorecard" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`renders a valid App item with filter in view mode 1`] = ` | ||
<div> | ||
<div | ||
class="itemHeaderWrap" | ||
> | ||
<p | ||
class="itemTitle" | ||
> | ||
Scorecard | ||
</p> | ||
</div> | ||
<hr | ||
style="background-color: rgb(243, 245, 247); height: 1px; margin: 0px 0px 5px 0px;" | ||
/> | ||
<iframe | ||
class="dashboard-item-content" | ||
src="launchurl?dashboardItemId=rainbowdash&userOrgUnit=rainbow" | ||
title="Scorecard" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`renders an invalid App item 1`] = ` | ||
<div> | ||
<div | ||
class="itemHeaderWrap" | ||
> | ||
<p | ||
class="itemTitle" | ||
> | ||
unknownApp app not found | ||
</p> | ||
</div> | ||
<hr | ||
style="background-color: rgb(243, 245, 247); height: 1px; margin: 0px 0px 5px 0px;" | ||
/> | ||
<div | ||
class="dashboard-item-content" | ||
style="display: flex; justify-content: center; align-items: center; height: 90%;" | ||
> | ||
<svg | ||
aria-hidden="true" | ||
class="MuiSvgIcon-root-10 MuiSvgIcon-colorDisabled-15" | ||
disabled="" | ||
focusable="false" | ||
role="presentation" | ||
style="width: 100px; height: 100px;" | ||
viewBox="0 0 24 24" | ||
> | ||
<path | ||
d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.42 0-8-3.58-8-8 0-1.85.63-3.55 1.69-4.9L16.9 18.31C15.55 19.37 13.85 20 12 20zm6.31-3.1L7.1 5.69C8.45 4.63 10.15 4 12 4c4.42 0 8 3.58 8 8 0 1.85-.63 3.55-1.69 4.9z" | ||
/> | ||
</svg> | ||
</div> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix looks good.
It's been a while, but I think the original idea here was to pass all the filters in
itemFilters
and pass them to the iframe URL.Apparently only the ou one was implemented, but I'm wondering if we should keep
itemFilters
for when other filters need to be passed in (like period).Perhaps all filters should already be passed?
Probably not all AppItem widgets support all of them but wouldn't it be more correct to pass all (not sure about the URL query parameters naming)?