This repository has been archived by the owner on Apr 17, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1348 from vitoravelino/teams-refactoring
js: team module refactoring
- Loading branch information
Showing
20 changed files
with
402 additions
and
197 deletions.
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
22 changes: 22 additions & 0 deletions
22
app/assets/javascripts/modules/teams/components/edit-team-form.js
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,22 @@ | ||
import BaseComponent from '~/base/component'; | ||
|
||
const TEAM_FORM_FIELDS = 'input.form-control, textarea'; | ||
|
||
// EditTeamForm component refers to the team form | ||
class EditTeamForm extends BaseComponent { | ||
elements() { | ||
this.$fields = this.$el.find(TEAM_FORM_FIELDS); | ||
} | ||
|
||
toggle() { | ||
this.$el.toggle(); | ||
|
||
const visible = this.$el.is(':visible'); | ||
|
||
if (visible) { | ||
this.$fields.first().focus(); | ||
} | ||
} | ||
} | ||
|
||
export default EditTeamForm; |
25 changes: 25 additions & 0 deletions
25
app/assets/javascripts/modules/teams/components/new-team-form.js
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,25 @@ | ||
import BaseComponent from '~/base/component'; | ||
|
||
const TEAM_FORM_FIELDS = 'input.form-control, textarea'; | ||
|
||
// NewTeamForm component refers to the new team form | ||
class NewTeamForm extends BaseComponent { | ||
elements() { | ||
this.$fields = this.$el.find(TEAM_FORM_FIELDS); | ||
} | ||
|
||
toggle() { | ||
this.$el.toggle(400, 'swing', () => { | ||
const visible = this.$el.is(':visible'); | ||
|
||
if (visible) { | ||
this.$fields.first().focus(); | ||
} | ||
|
||
this.$fields.val(''); | ||
layout_resizer(); | ||
}); | ||
} | ||
} | ||
|
||
export default NewTeamForm; |
35 changes: 35 additions & 0 deletions
35
app/assets/javascripts/modules/teams/components/new-team-user-form.js
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,35 @@ | ||
import BaseComponent from '~/base/component'; | ||
|
||
import { setTypeahead } from '~/utils/typeahead'; | ||
|
||
const TYPEAHEAD_INPUT = '.remote .typeahead'; | ||
const WEBHOOK_FORM_FIELDS = '.form-control'; | ||
|
||
// NewTeamUserForm component refers to the new team member form | ||
class NewTeamUserForm extends BaseComponent { | ||
elements() { | ||
this.$fields = this.$el.find(WEBHOOK_FORM_FIELDS); | ||
} | ||
|
||
mounted() { | ||
const teamId = this.$el.find(TYPEAHEAD_INPUT).data('teamId'); | ||
|
||
setTypeahead(TYPEAHEAD_INPUT, teamId + '/typeahead/%QUERY'); | ||
} | ||
|
||
toggle() { | ||
this.$el.toggle(400, 'swing', () => { | ||
const visible = this.$el.is(':visible'); | ||
|
||
if (visible) { | ||
this.$fields.last().focus(); | ||
} | ||
|
||
this.$fields.last().val(''); | ||
this.$fields.first().val('viewer'); | ||
layout_resizer(); | ||
}); | ||
} | ||
} | ||
|
||
export default NewTeamUserForm; |
34 changes: 34 additions & 0 deletions
34
app/assets/javascripts/modules/teams/components/team-details.js
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,34 @@ | ||
import BaseComponent from '~/base/component'; | ||
|
||
import EditTeamForm from './edit-team-form'; | ||
|
||
const TOGGLE_LINK = '.edit-team-link'; | ||
const EDIT_TEAM_FORM = '.edit-team-form'; | ||
const TEAM_INFORMATION = '.team_information'; | ||
|
||
// TeamDetails component handles details panel | ||
// and edit team form | ||
class TeamDetails extends BaseComponent { | ||
elements() { | ||
this.$toggle = this.$el.find(TOGGLE_LINK); | ||
this.$form = this.$el.find(EDIT_TEAM_FORM); | ||
this.$teamInformation = this.$el.find(TEAM_INFORMATION); | ||
} | ||
|
||
events() { | ||
this.$toggle.on('click', () => this.onEditClick()); | ||
} | ||
|
||
mount() { | ||
this.form = new EditTeamForm(this.$form); | ||
} | ||
|
||
onEditClick() { | ||
this.$teamInformation.toggle(); | ||
this.form.toggle(); | ||
|
||
layout_resizer(); | ||
} | ||
} | ||
|
||
export default TeamDetails; |
39 changes: 39 additions & 0 deletions
39
app/assets/javascripts/modules/teams/components/team-users-panel.js
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,39 @@ | ||
import BaseComponent from '~/base/component'; | ||
|
||
import NewTeamUserForm from './new-team-user-form'; | ||
import TeamUsersTable from './team-users-table'; | ||
|
||
const TOGGLE_LINK = '#add_team_user_btn'; | ||
const TOGGLE_LINK_ICON = `${TOGGLE_LINK} i`; | ||
const NEW_TEAM_USER_FORM = '#add_team_user_form'; | ||
const TEAM_USERS_TABLE = '.table'; | ||
|
||
// TeamUsersPanel component that lists team users | ||
// and contains new team member form. | ||
class TeamUsersPanel extends BaseComponent { | ||
elements() { | ||
this.$toggle = this.$el.find(TOGGLE_LINK); | ||
this.$toggleIcon = this.$el.find(TOGGLE_LINK_ICON); | ||
this.$form = this.$el.find(NEW_TEAM_USER_FORM); | ||
this.$table = this.$el.find(TEAM_USERS_TABLE); | ||
} | ||
|
||
events() { | ||
this.$el.on('click', TOGGLE_LINK, e => this.onToggleLinkClick(e)); | ||
} | ||
|
||
mount() { | ||
this.table = new TeamUsersTable(this.$table); | ||
this.newForm = new NewTeamUserForm(this.$form); | ||
} | ||
|
||
onToggleLinkClick() { | ||
const wasVisible = this.$form.is(':visible'); | ||
|
||
this.newForm.toggle(); | ||
this.$toggleIcon.toggleClass('fa-user-times', !wasVisible); | ||
this.$toggleIcon.toggleClass('fa-user-plus', wasVisible); | ||
} | ||
} | ||
|
||
export default TeamUsersPanel; |
25 changes: 25 additions & 0 deletions
25
app/assets/javascripts/modules/teams/components/team-users-table.js
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,25 @@ | ||
import BaseComponent from '~/base/component'; | ||
|
||
import { openCloseIcon } from '~/utils/effects'; | ||
|
||
const TEAM_USER_EDIT_BTN = '.edit-team-user-btn'; | ||
|
||
// TeamUsersTable component refers to the | ||
// team users table | ||
class TeamUsersTable extends BaseComponent { | ||
events() { | ||
this.$el.on('click', TEAM_USER_EDIT_BTN, e => this.onToggleEdit(e)); | ||
} | ||
|
||
// eslint-disable-next-line class-methods-use-this | ||
onToggleEdit(e) { | ||
const $btn = $(e.currentTarget); | ||
const teamUserId = $btn.data('teamUserId'); | ||
|
||
openCloseIcon($btn.find('.fa')); | ||
$(`#team_user_${teamUserId} td .role`).toggle(); | ||
$(`#change_role_team_user_${teamUserId}`).toggle(); | ||
} | ||
} | ||
|
||
export default TeamUsersTable; |
35 changes: 35 additions & 0 deletions
35
app/assets/javascripts/modules/teams/components/teams-panel.js
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,35 @@ | ||
import BaseComponent from '~/base/component'; | ||
|
||
import NewTeamForm from './new-team-form'; | ||
|
||
const TOGGLE_LINK = '#add_team_btn'; | ||
const TOGGLE_LINK_ICON = `${TOGGLE_LINK} i`; | ||
const NEW_TEAM_FORM = '#add_team_form'; | ||
|
||
// TeamsPanel component that lists teams | ||
// and contains new team form. | ||
class TeamsPanel extends BaseComponent { | ||
elements() { | ||
this.$toggle = this.$el.find(TOGGLE_LINK); | ||
this.$toggleIcon = this.$el.find(TOGGLE_LINK_ICON); | ||
this.$form = this.$el.find(NEW_TEAM_FORM); | ||
} | ||
|
||
events() { | ||
this.$el.on('click', TOGGLE_LINK, e => this.onToggleLinkClick(e)); | ||
} | ||
|
||
mount() { | ||
this.newForm = new NewTeamForm(this.$form); | ||
} | ||
|
||
onToggleLinkClick() { | ||
const wasVisible = this.$form.is(':visible'); | ||
|
||
this.newForm.toggle(); | ||
this.$toggleIcon.toggleClass('fa-minus-circle', !wasVisible); | ||
this.$toggleIcon.toggleClass('fa-plus-circle', wasVisible); | ||
} | ||
} | ||
|
||
export default TeamsPanel; |
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,19 @@ | ||
import BaseComponent from '~/base/component'; | ||
|
||
import TeamsPanel from '../components/teams-panel'; | ||
|
||
const TEAMS_PANEL = '.teams-wrapper'; | ||
|
||
// TeamsIndexPage component responsible to instantiate | ||
// the teams index page components and handle interactions. | ||
class TeamsIndexPage extends BaseComponent { | ||
elements() { | ||
this.$teamsPanel = this.$el.find(TEAMS_PANEL); | ||
} | ||
|
||
mount() { | ||
this.teamsPanel = new TeamsPanel(this.$teamsPanel); | ||
} | ||
} | ||
|
||
export default TeamsIndexPage; |
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.