From 8e4fdfb5a554724c7dfc4af94d46ea8d2175c6c0 Mon Sep 17 00:00:00 2001 From: Grégoire Aubert Date: Thu, 13 Apr 2017 15:36:08 +0200 Subject: SONAR-6911 Improve the display of default groups --- .../src/main/js/apps/groups/list-item-view.js | 12 +++++++++--- .../js/apps/groups/templates/groups-list-item.hbs | 15 +++++++++++---- .../components/OrganizationGroupCheckbox.js | 13 +++++++++---- .../__tests__/OrganizationGroupCheckbox-test.js | 17 ++++++++++++++++- .../OrganizationGroupCheckbox-test.js.snap | 19 +++++++++++++++++++ .../sonar-web/src/main/js/store/organizations/duck.js | 5 +++-- server/sonar-web/src/main/less/init/lists.less | 9 +++++++++ 7 files changed, 76 insertions(+), 14 deletions(-) (limited to 'server/sonar-web/src') diff --git a/server/sonar-web/src/main/js/apps/groups/list-item-view.js b/server/sonar-web/src/main/js/apps/groups/list-item-view.js index 58ac7ef50b1..ea6a0824950 100644 --- a/server/sonar-web/src/main/js/apps/groups/list-item-view.js +++ b/server/sonar-web/src/main/js/apps/groups/list-item-view.js @@ -46,18 +46,24 @@ export default Marionette.ItemView.extend({ onUpdateClick(e) { e.preventDefault(); - this.updateGroup(); + if (!this.model.get('default')) { + this.updateGroup(); + } }, onDeleteClick(e) { e.preventDefault(); - this.deleteGroup(); + if (!this.model.get('default')) { + this.deleteGroup(); + } }, onUsersClick(e) { e.preventDefault(); $('.tooltip').remove(); - this.showUsers(); + if (!this.model.get('default')) { + this.showUsers(); + } }, updateGroup() { diff --git a/server/sonar-web/src/main/js/apps/groups/templates/groups-list-item.hbs b/server/sonar-web/src/main/js/apps/groups/templates/groups-list-item.hbs index 809a41b624b..85306c7f827 100644 --- a/server/sonar-web/src/main/js/apps/groups/templates/groups-list-item.hbs +++ b/server/sonar-web/src/main/js/apps/groups/templates/groups-list-item.hbs @@ -1,19 +1,26 @@
- - + {{#unless default}} + + + {{/unless}}
{{name}} + {{#if default}} + ({{t 'default'}}) + {{/if}}
- Members + {{t 'members'}}
{{membersCount}} - + {{#unless default}} + + {{/unless}}
diff --git a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationGroupCheckbox.js b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationGroupCheckbox.js index 3324cc4ec77..b8afa70b90d 100644 --- a/server/sonar-web/src/main/js/apps/organizations/components/OrganizationGroupCheckbox.js +++ b/server/sonar-web/src/main/js/apps/organizations/components/OrganizationGroupCheckbox.js @@ -32,22 +32,27 @@ export default class OrganizationGroupCheckbox extends React.PureComponent { props: Props; onCheck = (checked: boolean) => { - this.props.onCheck(this.props.group.name, checked); + const { group } = this.props; + if (!group.default) { + this.props.onCheck(group.name, checked); + } }; toggleCheck = () => { - this.props.onCheck(this.props.group.name, !this.props.checked); + this.onCheck(!this.props.checked); }; render() { + const { group } = this.props; return (
  • + role="listitem" + disabled={group.default}> - {' '}{this.props.group.name} + {' '}{group.name}
  • ); } diff --git a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationGroupCheckbox-test.js b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationGroupCheckbox-test.js index 146e8aacba1..cb68211b8e4 100644 --- a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationGroupCheckbox-test.js +++ b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/OrganizationGroupCheckbox-test.js @@ -25,7 +25,8 @@ const group = { id: '7', name: 'professionals', description: '', - membersCount: 12 + membersCount: 12, + default: false }; it('should render unchecked', () => { @@ -45,3 +46,17 @@ it('should be able to toggle check', () => { expect(onCheck.mock.calls).toMatchSnapshot(); expect(wrapper).toMatchSnapshot(); }); + +it('should disabled default groups', () => { + const onCheck = jest.fn((group, checked) => wrapper.setProps({ checked })); + const wrapper = shallow( + + ); + expect(wrapper).toMatchSnapshot(); + wrapper.instance().toggleCheck(); + expect(onCheck.mock.calls.length).toBe(0); +}); diff --git a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationGroupCheckbox-test.js.snap b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationGroupCheckbox-test.js.snap index 5ee947cf614..00ac21f63b3 100644 --- a/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationGroupCheckbox-test.js.snap +++ b/server/sonar-web/src/main/js/apps/organizations/components/__tests__/__snapshots__/OrganizationGroupCheckbox-test.js.snap @@ -1,6 +1,7 @@ exports[`test should be able to toggle check 1`] = `
  • @@ -25,6 +26,7 @@ Array [ exports[`test should be able to toggle check 3`] = `
  • @@ -37,9 +39,26 @@ exports[`test should be able to toggle check 3`] = `
  • `; +exports[`test should disabled default groups 1`] = ` +
  • + + + professionals +
  • +`; + exports[`test should render unchecked 1`] = `
  • diff --git a/server/sonar-web/src/main/js/store/organizations/duck.js b/server/sonar-web/src/main/js/store/organizations/duck.js index b897af7845c..89cb815c7a6 100644 --- a/server/sonar-web/src/main/js/store/organizations/duck.js +++ b/server/sonar-web/src/main/js/store/organizations/duck.js @@ -36,9 +36,10 @@ export type Organization = { export type OrgGroup = { id: string, - name: string, + default: boolean, description: string, - membersCount: number + membersCount: number, + name: string }; type ReceiveOrganizationsAction = { diff --git a/server/sonar-web/src/main/less/init/lists.less b/server/sonar-web/src/main/less/init/lists.less index 193e2f2d301..e0006f22a3f 100644 --- a/server/sonar-web/src/main/less/init/lists.less +++ b/server/sonar-web/src/main/less/init/lists.less @@ -69,6 +69,15 @@ ol, ul { &:focus { outline: none; } + + &[disabled] { + opacity: 0.7; + + a::before { + background-color: @darkGrey; + border-color: @darkGrey; + } + } } -- cgit v1.2.3