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

feat: add DHIS2 Sharing Dialog (TECH-274) #24

Merged
merged 50 commits into from
Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
758bb10
feat: Add DHIS2 Sharing Dialog
amcgee Apr 16, 2020
4d67257
chore: add PropTypes and mark translatable strings
edoardo Apr 22, 2020
91f6737
fix: fix imports after merging alpha
edoardo May 7, 2020
5fd447c
feat: search as you type for user/groups
edoardo May 7, 2020
2d8ceb8
fix: pass label for the search input
edoardo Oct 12, 2020
dc9fcc1
refactor: use ui components, make it fully reusable
edoardo Oct 12, 2020
f3f5040
fix: implement latest design
edoardo Oct 12, 2020
c2149d9
fix: add remove for user/groups
edoardo Oct 12, 2020
4938603
fix: implement disabled access select (external/public)
edoardo Oct 12, 2020
1e16f85
refactor: conversion from server response to internal object
edoardo Oct 12, 2020
ca0e459
chore: remove debug console logs
edoardo Oct 12, 2020
f4fdf0a
chore: cleanup styles
edoardo Oct 12, 2020
d3625e6
refactor: implement CRUD operations
edoardo Oct 12, 2020
66d9c78
docs: added more stories for Storybook
edoardo Oct 12, 2020
30ba950
refactor: replace Table components with divs and fix styling
edoardo Oct 13, 2020
3f37669
refactor: use name initials icon for users
edoardo Oct 14, 2020
7cb1297
refactor: use same prop types import for consistency
edoardo Oct 14, 2020
15550cc
fix: use the callback format for error handling
edoardo Oct 28, 2020
fcbf226
chore: update deps for using useAlert hook
edoardo Nov 19, 2020
f9ca3e5
fix: fix crash when an access string contains data settings
edoardo Nov 19, 2020
6ec315a
refactor: add error handling using useAlert hook
edoardo Nov 19, 2020
1b63d1a
chore: remove unused icon
edoardo Nov 20, 2020
bcf4c22
fix: fix icons while waiting for ui-icons to be released
edoardo Nov 20, 2020
bf02805
fix: fix i18n.t usage
edoardo Nov 23, 2020
4df6838
test: add basic tests for SharingDialog widget/components
edoardo Dec 10, 2020
2f8d490
chore: fix lint/prettier
edoardo Dec 11, 2020
e048b35
chore: remove unused file
edoardo Dec 11, 2020
725b6f9
fix: fix imports
edoardo Dec 11, 2020
da68680
fix: prevent access-before-initialisation storybook errors (#414)
HendrikThePendric Dec 16, 2020
3459e65
refactor: use icons from @dhis2/ui-icons
edoardo Jan 13, 2021
3eb8e7b
chore: fix linting errors
edoardo Jan 14, 2021
1b0ada7
fix: make clear the type of access as per latest design
edoardo Jan 15, 2021
919a287
fix: fix wrong boolean default for view and edit access
edoardo Mar 24, 2021
752b641
fix: fix i18n string interpolation
edoardo Mar 24, 2021
82737f2
refactor: improve proptype definition
edoardo Mar 24, 2021
da9f35e
fix: fix import
edoardo Apr 7, 2021
2aa4e6c
refactor: move SharingDialog to the new folder structure
edoardo Jul 12, 2021
6d89ba4
fix: use fixed version for @dhis2-ui dependencies
edoardo Jul 12, 2021
4f81b75
refactor: debounce user/group data fetch
edoardo Jul 15, 2021
a00b1ea
fix: fix prop types
edoardo Jul 16, 2021
efff245
feat: implement cascading sharing for dashboards
edoardo Jul 16, 2021
e4251fe
fix: add stories for dashboard cascading sharing
edoardo Jul 16, 2021
374ca57
fix: fix prop types
edoardo Jul 16, 2021
9d91931
fix: minor text correction
edoardo Aug 9, 2021
b1f7fcd
feat: implement cascade sharing for dashboard TECH-274
edoardo Aug 18, 2021
1183a5d
test: add stories for dashboard cascade sharing dialog
edoardo Aug 18, 2021
048f44a
chore: update dependencies
edoardo Aug 18, 2021
da61dac
chore(deps): dedupe dependencies
varl Aug 23, 2021
122d4e9
test: fix failing test after changes for dashboard cascading sharing
edoardo Aug 24, 2021
70f2196
chore: use the same import format everywhere
edoardo Aug 24, 2021
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
1 change: 1 addition & 0 deletions collections/widgets/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ export {
DataTableRow,
DataTableToolbar,
} from '@dhis2-ui/table'
// TODO export { SharingDialog } from '@dhis2-ui/sharing-dialog'
Copy link
Contributor

Choose a reason for hiding this comment

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

Once ready, this line should be added to the @dhis2/ui package, but we can release it in alpha without exposing it.

Suggested change
// TODO export { SharingDialog } from '@dhis2-ui/sharing-dialog'

6 changes: 6 additions & 0 deletions components/sharing-dialog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
> :warning:
> This is currently considered internal, please use `@dhis2/ui`.
>
> See the [Getting started
> guide](https://github.com/dhis2/ui/blob/master/docs/getting-started.md)
> for more information.
6 changes: 6 additions & 0 deletions components/sharing-dialog/d2.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
type: 'lib',
entryPoints: {
lib: 'src/index.js',
},
}
140 changes: 140 additions & 0 deletions components/sharing-dialog/i18n/en.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
msgid ""
msgstr ""
"Project-Id-Version: i18next-conv\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2021-08-17T10:24:25.305Z\n"
"PO-Revision-Date: 2021-08-17T10:24:25.305Z\n"

msgid "Remove access"
msgstr "Remove access"

msgid "Apply dashboard sharing settings to dashboard items"
msgstr "Apply dashboard sharing settings to dashboard items"

msgid ""
"All dashboard items will be updated. Users and groups with access to this "
"dashboard will have the same access level for all dashboard items. Public "
"sharing will not be applied to dashboard items. Applying sharing can not be "
"undone, and needs to be performed each time you update a dashboard's "
"sharing settings or items."
msgstr ""
"All dashboard items will be updated. Users and groups with access to this "
"dashboard will have the same access level for all dashboard items. Public "
"sharing will not be applied to dashboard items. Applying sharing can not be "
"undone, and needs to be performed each time you update a dashboard's "
"sharing settings or items."

msgid ""
"\n"
" {{dashboardItemsCount}} dashboard items will be updated with "
"sharing settings\n"
" from {{usersGroupsCount}} users and groups. Public "
"access is not affected."
msgstr ""
"\n"
" {{dashboardItemsCount}} dashboard items will be updated with "
"sharing settings\n"
" from {{usersGroupsCount}} users and groups. Public "
"access is not affected."

msgid ""
"There aren't any sharing settings to apply to dashboard items. Public "
"access cannot be applied to items."
msgstr ""
"There aren't any sharing settings to apply to dashboard items. Public "
"access cannot be applied to items."

msgid "Apply sharing to dashboard items"
msgstr "Apply sharing to dashboard items"

msgid "Updating sharing settings..."
msgstr "Updating sharing settings..."

msgid ""
"There was a problem updating dashboard items. No dashboard items were "
"updated. Try again, or contact a system administrator"
msgstr ""
"There was a problem updating dashboard items. No dashboard items were "
"updated. Try again, or contact a system administrator"

msgid ""
"{{updatedDashboardItemsCount}} dashboard items were updated, but "
"{{ignoredDashboardItemsCount}} could not be updated. Check that you have "
"permission to change sharing for all items."
msgstr ""
"{{updatedDashboardItemsCount}} dashboard items were updated, but "
"{{ignoredDashboardItemsCount}} could not be updated. Check that you have "
"permission to change sharing for all items."

msgid ""
"Successfully updated sharing for {{updatedDashboardItemsCount}} dashboard "
"items"
msgstr ""
"Successfully updated sharing for {{updatedDashboardItemsCount}} dashboard "
"items"

msgid "Dashboard sharing"
msgstr "Dashboard sharing"

msgid "Give access to a user, group or role"
msgstr "Give access to a user, group or role"

msgid "Search"
msgstr "Search"

msgid "User, group or role"
msgstr "User, group or role"

msgid "Access level"
msgstr "Access level"

msgid "Select a level"
msgstr "Select a level"

msgid "Give access"
msgstr "Give access"

msgid "No access"
msgstr "No access"

msgid "Anyone logged in can view"
msgstr "Anyone logged in can view"

msgid "Can view"
msgstr "Can view"

msgid "View only"
msgstr "View only"

msgid "Anyone logged in can view and edit"
msgstr "Anyone logged in can view and edit"

msgid "Can view and edit"
msgstr "Can view and edit"

msgid "View and edit"
msgstr "View and edit"

msgid "Sharing & Access"
msgstr "Sharing & Access"

msgid "Close"
msgstr "Close"

msgid "Metadata"
msgstr "Metadata"

msgid "Users, groups and roles that currently have access"
msgstr "Users, groups and roles that currently have access"

msgid "User / Group / Role"
msgstr "User / Group / Role"

msgid "External users"
msgstr "External users"

msgid "All users"
msgstr "All users"
63 changes: 63 additions & 0 deletions components/sharing-dialog/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "@dhis2-ui/sharing-dialog",
"version": "6.16.0",
"description": "UI SharingDialog",
"repository": {
"type": "git",
"url": "https://github.com/dhis2/ui.git",
"directory": "components/sharing-dialog"
},
"homepage": "https://github.com/dhis2/ui#readme",
"license": "BSD-3-Clause",
"private": false,
"main": "./build/cjs/index.js",
"module": "./build/es/index.js",
"exports": {
"import": "./build/es/index.js",
"require": "./build/cjs/index.js"
},
"sideEffects": false,
"publishConfig": {
"access": "public"
},
"scripts": {
"start": "start-storybook -c ../../storybook/config --port 5000",
"build": "d2-app-scripts build"
},
"peerDependencies": {
"@dhis2/app-runtime": "^2",
"@dhis2/d2-i18n": "^1",
"react": "^16.8",
"react-dom": "^16.8",
"styled-jsx": "^3.2"
},
"dependencies": {
"@dhis2-ui/button": "6.16.0",
"@dhis2-ui/card": "6.16.0",
"@dhis2-ui/divider": "6.16.0",
"@dhis2-ui/input": "6.16.0",
"@dhis2-ui/layer": "6.16.0",
"@dhis2-ui/loader": "6.16.0",
"@dhis2-ui/menu": "6.16.0",
"@dhis2-ui/modal": "6.16.0",
"@dhis2-ui/notice-box": "6.16.0",
"@dhis2-ui/popper": "6.16.0",
"@dhis2-ui/select": "6.16.0",
"@dhis2-ui/tab": "6.16.0",
"@dhis2/prop-types": "^1.6.4",
"@dhis2/ui-constants": "6.16.0",
"@dhis2/ui-icons": "6.16.0",
"classnames": "^2.3.1",
"prop-types": "^15.7.2"
},
"files": [
"build"
],
"devDependencies": {
"@dhis2/app-runtime": "^2.7.1",
"@dhis2/d2-i18n": "^1.1.0",
"react": "16.13",
"react-dom": "16.13",
"styled-jsx": "^3.4.4"
}
}
40 changes: 40 additions & 0 deletions components/sharing-dialog/src/__tests__/AccessSelect.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { SingleSelectField } from '@dhis2-ui/select'
import { shallow } from 'enzyme'
import React from 'react'
import { AccessSelect } from '../access-select.js'
import { ACCESS_VIEW_ONLY, ACCESS_VIEW_AND_EDIT } from '../sharing-constants.js'

describe('SharingDialog widget - AccessSelect component', () => {
let shallowAccessSelectComponent
let props

const onChange = jest.fn()

const getAccessSelectComponent = props => {
if (!shallowAccessSelectComponent) {
shallowAccessSelectComponent = shallow(<AccessSelect {...props} />)
}

return shallowAccessSelectComponent
}

beforeEach(() => {
shallowAccessSelectComponent = undefined
props = {
access: ACCESS_VIEW_ONLY,
accessOptions: [ACCESS_VIEW_ONLY, ACCESS_VIEW_AND_EDIT],
disabled: false,
label: 'Label',
placeholder: 'Placeholder',
prefix: 'Prefix',
showRemoveOption: false,
onChange,
}
})

it('renders a SingleSelectField component ', () => {
expect(
getAccessSelectComponent(props).find(SingleSelectField)
).toHaveLength(1)
})
})
45 changes: 45 additions & 0 deletions components/sharing-dialog/src/__tests__/ShareBlock.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Button } from '@dhis2-ui/button'
import { shallow } from 'enzyme'
import React from 'react'
import { AccessSelect } from '../access-select.js'
import { Autocomplete } from '../autocomplete/autocomplete.js'
import { ShareBlock } from '../share-block.js'

describe('SharingDialog widget - ShareBlock component', () => {
let shallowShareBlockComponent
let props

const onAdd = jest.fn()

const getShareBlockComponent = props => {
if (!shallowShareBlockComponent) {
shallowShareBlockComponent = shallow(<ShareBlock {...props} />)
}

return shallowShareBlockComponent
}

beforeEach(() => {
shallowShareBlockComponent = undefined
props = {
onAdd,
}
})

it('renders the Autocomplete component ', () =>
expect(getShareBlockComponent(props).find(Autocomplete)).toHaveLength(
1
))

it('renders the AccessSelect component', () =>
expect(getShareBlockComponent(props).find(AccessSelect)).toHaveLength(
1
))

it('renders the Give access button', () => {
const button = getShareBlockComponent(props).find(Button)

expect(button).toHaveLength(1)
expect(button.html()).toMatch('Give access')
})
})
77 changes: 77 additions & 0 deletions components/sharing-dialog/src/__tests__/SharingDialog.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { Button } from '@dhis2-ui/button'
import { Modal, ModalTitle } from '@dhis2-ui/modal'
import { shallow } from 'enzyme'
import React from 'react'
import { DashboardSharingContent } from '../dashboard-sharing-content.js'
import { DefaultSharingContent } from '../default-sharing-content.js'
import { defaultSharingSettings } from '../sharing-constants.js'
import { SharingDialog } from '../sharing-dialog.js'

describe('SharingDialog widget', () => {
const onClose = jest.fn()
const onSave = jest.fn()
const onError = jest.fn()

let shallowSharingDialog
let props

const getSharingDialogWidget = props => {
if (!shallowSharingDialog) {
shallowSharingDialog = shallow(<SharingDialog {...props} />)
}

return shallowSharingDialog
}

beforeEach(() => {
shallowSharingDialog = undefined
props = {
type: 'visualization',
onClose,
onError,
onSave,
}
})

it('renders a Modal', () =>
expect(getSharingDialogWidget(props).find(Modal)).toHaveLength(1))

it('renders the ModalTitle with the name of the AO if passed in props', () => {
props.initialSharingSettings = {
...defaultSharingSettings,
name: 'test object',
}

expect(getSharingDialogWidget(props).find(ModalTitle).html()).toMatch(
props.initialSharingSettings.name
)
})

it('renders a Close button', () => {
const button = getSharingDialogWidget(props).find(Button)

expect(button).toHaveLength(1)
expect(button.html()).toMatch('Close')
})

it('calls the Close callback when the Close button is clicked', () => {
const button = getSharingDialogWidget(props).find(Button)

button.simulate('click')

expect(onClose).toHaveBeenCalled()
})

it('renders a DefaultSharingContent component when the type is not dashboard', () =>
expect(
getSharingDialogWidget(props).find(DefaultSharingContent)
).toHaveLength(1))

it('renders a DashboardSharingContent component when the type is dashboard', () => {
props.type = 'dashboard'

expect(
getSharingDialogWidget(props).find(DashboardSharingContent)
).toHaveLength(1)
})
})
Loading