Просмотр исходного кода

impl GrantSelector.retrieveUserGroupRelations

Yuki Takei 7 лет назад
Родитель
Сommit
6c84eaaeaf
1 измененных файлов с 18 добавлено и 1 удалено
  1. 18 1
      resource/js/components/PageEditor/GrantSelector.js

+ 18 - 1
resource/js/components/PageEditor/GrantSelector.js

@@ -59,6 +59,7 @@ class GrantSelector extends React.Component {
   }
 
   showSelectGroupModal() {
+    this.retrieveUserGroupRelations();
     this.setState({ isSelectGroupModalShown: true });
   }
   hideSelectGroupModal() {
@@ -70,6 +71,22 @@ class GrantSelector extends React.Component {
     return pageGrantGroup ? pageGrantGroup.name : '';
   }
 
+  /**
+   * Retrieve user-group-relations data from backend
+   */
+  retrieveUserGroupRelations() {
+    this.props.crowi.apiGet('/me/user-group-relations')
+      .then(res => {
+        return res.userGroupRelations;
+      })
+      .then(userGroupRelations => {
+        const userRelatedGroups = userGroupRelations.map(relation => {
+          return relation.relatedGroup;
+        });
+        this.setState({userRelatedGroups});
+      });
+  }
+
   /**
    * change event handler for pageGrant selector
    */
@@ -181,7 +198,7 @@ class GrantSelector extends React.Component {
    */
   renderSelectGroupModal() {
     const generateGroupListItems = () => {
-      this.state.userRelatedGroups.map((group) => {
+      return this.state.userRelatedGroups.map((group) => {
         return <ListGroupItem key={group._id} header={group.name} onClick={() => { this.groupListItemClickHandler(group) }}>
             (TBD) List group members
           </ListGroupItem>;