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

render SlackNotification component only when slack configurations are setup

Yuki Takei 7 лет назад
Родитель
Сommit
b8715d68bf
3 измененных файлов с 17 добавлено и 16 удалено
  1. 15 10
      src/client/js/components/SavePageControls.jsx
  2. 1 4
      src/server/crowi/index.js
  3. 1 2
      src/server/routes/page.js

+ 15 - 10
src/client/js/components/SavePageControls.jsx

@@ -52,22 +52,27 @@ class SavePageControls extends React.PureComponent {
     const { t } = this.props;
 
     const config = this.props.crowi.getConfig();
+    const hasSlackConfig = config.hasSlackConfig;
     const isAclEnabled = config.isAclEnabled;
     const labelSubmitButton = this.state.pageId == null ? t('Create') : t('Update');
     const labelOverwriteScopes = t('page_edit.overwrite_scopes', { operation: labelSubmitButton });
 
     return (
       <div className="d-flex align-items-center form-inline">
-        <div className="mr-2">
-          <SlackNotification
-            ref={(c) => { this.slackNotification = c }}
-            crowi={this.props.crowi}
-            pageId={this.props.pageId}
-            pagePath={this.props.pagePath}
-            isSlackEnabled={false}
-            slackChannels={this.props.slackChannels}
-          />
-        </div>
+        {hasSlackConfig
+          && (
+          <div className="mr-2">
+            <SlackNotification
+              ref={(c) => { this.slackNotification = c }}
+              crowi={this.props.crowi}
+              pageId={this.props.pageId}
+              pagePath={this.props.pagePath}
+              isSlackEnabled={false}
+              slackChannels={this.props.slackChannels}
+            />
+          </div>
+          )
+        }
 
         {isAclEnabled
           && (

+ 1 - 4
src/server/crowi/index.js

@@ -315,10 +315,7 @@ Crowi.prototype.setupSlack = function() {
   const Config = this.model('Config');
 
   return new Promise(((resolve, reject) => {
-    if (!Config.hasSlackConfig(config)) {
-      self.slack = {};
-    }
-    else {
+    if (Config.hasSlackConfig(config)) {
       self.slack = require('../util/slack')(self);
     }
 

+ 1 - 2
src/server/routes/page.js

@@ -93,9 +93,8 @@ module.exports = function(crowi, app) {
         logger.error('Error occured in updating slack channels: ', err);
       });
 
-    if (crowi.slack) {
+    if (Config.hasSlackConfig(config)) {
       const promises = slackChannels.split(',').map((chan) => {
-        logger.debug('crowi.slack is exist', crowi.slack);
         return crowi.slack.postPage(page, user, chan, updateOrCreate, previousRevision);
       });