[client-app] Fix selecting and creating signatures in preferences

Summary:
This commit fixes 2 issues with signatures in the preferences:
- Creating a signature (via any of the create buttons) would create 2 signatures
- Trying to select accounts to associate with a signature in the preferences would not work (the account would not be selected)

This was a regression introduced in e638e94084 (diff-4f38fd25aa24b48a309354be643165d3R26)

3111c16 made it so we attempt to `activate` any Stores that are registered with
the StoreRegistry. When adding stores to `nylas-exports`, they are
automatically registered in the StoreRegistry. Given that the
`SignatureStore` is in `nylas-exports`, and consequently is registered in
the StoreRegistry, it would be `activate`d upon window boot.

However, we were also manually activating it inside `internal_packages/composer-signatures/lib/main.es6`.
This caused it to register listeners for every action **twice**. For
this reason, 2 signatures would be created when trying to create 1, and
an account would be immediately unselected after being selected int he
signatures dropdown in preferences.

(Other changes in this are just stylistic)

Test Plan: manual

Reviewers: spang, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D4043
This commit is contained in:
Juan Tejada 2017-02-28 09:13:37 -08:00
parent de9484cc52
commit 72613baf5d
3 changed files with 14 additions and 8 deletions

View file

@ -1,4 +1,4 @@
import {PreferencesUIStore, ExtensionRegistry, SignatureStore, ComponentRegistry} from 'nylas-exports';
import {PreferencesUIStore, ExtensionRegistry, ComponentRegistry} from 'nylas-exports';
import SignatureComposerExtension from './signature-composer-extension';
import SignatureComposerDropdown from './signature-composer-dropdown';
@ -13,7 +13,6 @@ export function activate() {
ExtensionRegistry.Composer.register(SignatureComposerExtension);
PreferencesUIStore.registerPreferencesTab(this.preferencesTab);
SignatureStore.activate();
ComponentRegistry.register(SignatureComposerDropdown, {
role: 'Composer:FromFieldComponents',
@ -23,7 +22,6 @@ export function activate() {
export function deactivate() {
ExtensionRegistry.Composer.unregister(SignatureComposerExtension);
PreferencesUIStore.unregisterPreferencesTab(this.preferencesTab.sectionId);
SignatureStore.deactivate();
ComponentRegistry.unregister(SignatureComposerDropdown);
}

View file

@ -101,7 +101,12 @@ export default class PreferencesSignatures extends React.Component {
Default for: {this._renderAccountPicker()}
</div>
<div className="render-mode">
<input type="checkbox" id="render-mode" checked={this.state.editAsHTML} onClick={this._onToggleEditAsHTML} />
<input
type="checkbox"
id="render-mode"
checked={this.state.editAsHTML}
onClick={this._onToggleEditAsHTML}
/>
<label htmlFor="render-mode">Edit raw HTML</label>
</div>
</div>
@ -176,8 +181,11 @@ export default class PreferencesSignatures extends React.Component {
mode={RetinaImg.Mode.ContentDark}
/>
<h2>No signatures</h2>
<button className="btn btn-small btn-create-signature" onMouseDown={this._onCreateButtonClick}>
Create a new signature
<button
className="btn btn-small btn-create-signature"
onClick={this._onCreateButtonClick}
>
Create a new signature
</button>
</div>
);

View file

@ -2,9 +2,9 @@
import ReactTestUtils from 'react-addons-test-utils';
import React from 'react';
import {SignatureStore, Actions} from 'nylas-exports';
import PreferencesSignatures from '../lib/preferences-signatures';
const SIGNATURES = {
'1': {
id: '1',
@ -39,7 +39,7 @@ describe('PreferencesSignatures', function preferencesSignatures() {
this.component = makeComponent()
spyOn(Actions, 'addSignature')
this.button = ReactTestUtils.findRenderedDOMComponentWithClass(this.component, 'btn-create-signature')
ReactTestUtils.Simulate.mouseDown(this.button)
ReactTestUtils.Simulate.click(this.button)
expect(Actions.addSignature).toHaveBeenCalled()
})
})