# All files / src/components/preferences preferences.jsx

73.96% Statements 71/96
63.41% Branches 26/41
68.18% Functions 15/22
72.37% Lines 55/76

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236

    1x

    1x

    11x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    5x

    18x

    18x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x

    1x
    1x

    18x

    18x

    1x

    36x

    18x
    9x

    18x
    9x

     import React, { Component } from 'react';
    import PropTypes from 'prop-types';
    import classnames from 'classnames';
    import { Item } from 'components/item';
    import Actions from 'actions';
    import { shell } from 'electron';

    import styles from './preferences.less';IEE

    /**
     * The community product name.
     */
    const COMMUNITY = 'mongodb-compass-community';

    /**
     * The title.
     */
    const TITLE = 'Privacy Settings';

    /**
     * The modal description.
     */
    const DESCRIPTION = 'To enhance the user experience, Compass can integrate with 3rd party services,' +
      'which requires external network requests. Please choose from the settings below:';

    /**
     * Feedback description.
     */
    const FEEDBACK = 'Enables a tool for sending feedback or talking to our Product' +
      'and Development teams directly from Compass.';

    /**
     * Maps description.
     */
    const MAPS = 'Allow Compass to make requests to a 3rd party mapping service.';
    I
    /**
     * Errors description.I
     */
    const ERRORS = 'Allow Compass to send crashI reports containing stack traces and unhandled exceptions.';E

    /**
     * Usage description.
     */
    const USAGE = 'Allow Compass to send anonymous usage statistics.';

    /**
     * Updates description.
     */
    const UPDATES = 'Allow Compass to periodically check for new updates.';

    /**
     * The notice message.
     */
    const NOTICE = 'With any of these options, none of your personal information or ' +
      'stored data will be submitted.';

    /**
     * The preferences component.
     */
    class Preferences extends Component {
      static displayName = 'PreferencesComponent';

      static propTypes = {
        isVisible: PropTypes.bool,
        productName: PropTypes.string
      };

      /**
       * Closes the modal.
       */
      onCloseClick() {
        Actions.closePreferences();
      }

      /**
       * Handle enable feedback clicking.
       *
       * @param {Event} evt - The event.
       */
      onFeedbackClick(evt) {
        Actions.enableFeedbackPanel(evt.target.checked);
      }

      /**
       * Handle enable maps clicking.
       *
       * @param {Event} evt - The event.
       */
      onMapsClick(evt) {
        Actions.enableMaps(evt.target.checked);
      }

      /**
       * Handle track errors clicking.
       *
       * @param {Event} evt - The event.
       */
      onErrorsClick(evt) {
        Actions.trackErrors(evt.target.checked);
      }

      /**
       * Handle usage statistics clicking.
       *
       * @param {Event} evt - The event.
       */
      onUsageClick(evt) {
        Actions.trackUsageStatistics(evt.target.checked);
      }

      /**
       * Handle auto updates clicking.
       *
       * @param {Event} evt - The event.
       */
      onUpdatesClick(evt) {
        Actions.autoUpdates(evt.target.checked);
      }

      /**
       * Handle clicking the privacy policy link.
       *
       * @param {Event} evt - The event.
       */
      onPrivacyClick(evt) {
        evt.preventDefault();
        evt.stopPropagation();
        shell.openExternal('https://www.mongodb.com/legal/privacy-policy');
      }

      /**
       * Is this compass community.
       *
       * @returns {Boolean} If this is compass community.
       */
      isCommunity() {
        return this.props.productName === COMMUNITY;
      }

      /**
       * Render the feedback item.
       *
       * @returns {React.Component} The component.
       */
      renderFeedback() {
        if (!this.isCommunity()) {
          return (
            <Item
              title="Enable Product Feedback Tool"
              description={FEEDBACK}
              dataTestId="product-feedback-checkbox"
              clickHandler={this.onFeedbackClick.bind(this)} />
          );
        }
      }

      /**
       * Render the geo item.
       *
       * @returns {React.Component} The component.
       */
      renderGeo() {
        if (!this.isCommunity()) {
          return (
            <Item
              title="Enable Geographic Visualizations"
              description={MAPS}
              dataTestId="enable-maps-checkbox"
              clickHandler={this.onMapsClick.bind(this)} />
          );
        }
      }

      /**
       * Render Preferences component.
       *
       * @returns {React.Component} The rendered component.
       */
      render() {
        const modalClass = {};
        modalClass[styles.modal] = true;
        modalClass[styles['modal-is-visible']] = this.props.isVisible;
        return (
          <div className={classnames(modalClass)}>
            <div className={classnames(styles.preferences)}>
              <div className={classnames(styles['preferences-content'])}>
                <div className={classnames(styles['preferences-header'])}>
                  <h4 className={classnames(styles['preferences-header-title'])} data-test-id="modal-title">
                    {TITLE}
                  </h4>
                </div>
                <div className={classnames(styles['preferences-body'])}>
                  <p>{DESCRIPTION}</p>
                  {this.renderFeedback()}
                  {this.renderGeo()}
                  <Item
                    title="Enable Crash Reports"
                    description={ERRORS}
                    dataTestId="track-errors-checkbox"
                    clickHandler={this.onErrorsClick.bind(this)} />
                  <Item
                    title="Enable Usage Statistics"
                    description={USAGE}
                    dataTestId="usage-stats-checkbox"
                    clickHandler={this.onUsageClick.bind(this)} />
                  <Item
                    title="Enable Automatic Updates"
                    description={UPDATES}
                    dataTestId="auto-updates-checkbox"
                    clickHandler={this.onUpdatesClick.bind(this)} />
                  <p>{NOTICE}</p>
                  <p>
                    Learn more:
                    <a onClick={this.onPrivacyClick.bind(this)}>MongoDB Privacy Policy</a>
                  </p>
                </div>
                <div className={classnames(styles['preferences-footer'])}>
                  <button
                    type="button"
                    data-test-id="close-privacy-settings-button"
                    className={classnames(styles['preferences-footer-button'])}
                    onClick={this.onCloseClick.bind(this)}>
                    Close
                  </button>
                </div>
              </div>
            </div>
          </div>
        );
      }
    }

    export default Preferences;
    export { Preferences };