From 0516fb98547bcfa7c88c76fc234abd72f1fdca34 Mon Sep 17 00:00:00 2001 From: Kumar McMillan Date: Tue, 16 Aug 2016 16:46:44 -0500 Subject: [PATCH 1/2] Move InstallButton into core --- src/amo/components/AddonDetail.js | 2 +- .../InstallButton}/InstallButton.scss | 2 +- .../components/InstallButton}/img/tick.svg | 0 .../components/InstallButton/index.js} | 4 +- src/core/constants.js | 89 +++++++++++++++++++ src/core/reducers/addons.js | 2 +- src/disco/addonManager.js | 4 +- src/disco/components/Addon.js | 14 +-- src/disco/constants.js | 83 +---------------- src/disco/containers/DiscoPane.js | 2 +- src/disco/reducers/installations.js | 2 +- src/disco/themePreview.js | 2 +- .../client/amo/components/TestAddonDetail.js | 2 +- .../components/TestInstallButton.js | 4 +- tests/client/core/reducers/test_addons.js | 2 +- tests/client/disco/TestAddonManager.js | 2 +- tests/client/disco/TestThemePreview.js | 2 +- tests/client/disco/components/TestAddon.js | 10 ++- .../client/disco/containers/TestDiscoPane.js | 2 + .../disco/reducers/test_installations.js | 2 +- tests/client/helpers.js | 2 +- 21 files changed, 126 insertions(+), 108 deletions(-) rename src/{disco/css => core/components/InstallButton}/InstallButton.scss (98%) rename src/{disco => core/components/InstallButton}/img/tick.svg (100%) rename src/{disco/components/InstallButton.js => core/components/InstallButton/index.js} (98%) create mode 100644 src/core/constants.js rename tests/client/{disco => core}/components/TestInstallButton.js (99%) diff --git a/src/amo/components/AddonDetail.js b/src/amo/components/AddonDetail.js index 2fd2df427f9..bb476916fee 100644 --- a/src/amo/components/AddonDetail.js +++ b/src/amo/components/AddonDetail.js @@ -1,7 +1,7 @@ import React, { PropTypes } from 'react'; import AddonMeta from 'amo/components/AddonMeta'; -import InstallButton from 'disco/components/InstallButton'; +import InstallButton from 'core/components/InstallButton'; import LikeButton from 'amo/components/LikeButton'; import ScreenShots from 'amo/components/ScreenShots'; import SearchBox from 'amo/components/SearchBox'; diff --git a/src/disco/css/InstallButton.scss b/src/core/components/InstallButton/InstallButton.scss similarity index 98% rename from src/disco/css/InstallButton.scss rename to src/core/components/InstallButton/InstallButton.scss index 0380b11112f..8cf1951da43 100644 --- a/src/disco/css/InstallButton.scss +++ b/src/core/components/InstallButton/InstallButton.scss @@ -220,7 +220,7 @@ $installStripeColor2: #00c42e; &.enabled, &.installed { input + label::before { - background: $switchBackgroundOn url('../img/tick.svg') no-repeat 35% 50%; + background: $switchBackgroundOn url('./img/tick.svg') no-repeat 35% 50%; [dir=rtl] & { background-position: 65% 50%; diff --git a/src/disco/img/tick.svg b/src/core/components/InstallButton/img/tick.svg similarity index 100% rename from src/disco/img/tick.svg rename to src/core/components/InstallButton/img/tick.svg diff --git a/src/disco/components/InstallButton.js b/src/core/components/InstallButton/index.js similarity index 98% rename from src/disco/components/InstallButton.js rename to src/core/components/InstallButton/index.js index ef070bc4f16..4645793f01f 100644 --- a/src/disco/components/InstallButton.js +++ b/src/core/components/InstallButton/index.js @@ -14,10 +14,10 @@ import { UNKNOWN, validAddonTypes, validInstallStates as validStates, -} from 'disco/constants'; +} from 'core/constants'; import { getThemeData } from 'disco/themePreview'; -import 'disco/css/InstallButton.scss'; +import './InstallButton.scss'; export class InstallButton extends React.Component { static propTypes = { diff --git a/src/core/constants.js b/src/core/constants.js new file mode 100644 index 00000000000..bffbeb2f522 --- /dev/null +++ b/src/core/constants.js @@ -0,0 +1,89 @@ +// Addon States. +export const DISABLED = 'DISABLED'; +export const DISABLING = 'DISABLING'; +export const DOWNLOADING = 'DOWNLOADING'; +export const ENABLED = 'ENABLED'; +export const ENABLING = 'ENABLING'; +export const ERROR = 'ERROR'; +export const INSTALLED = 'INSTALLED'; +export const INSTALLING = 'INSTALLING'; +export const UNINSTALLED = 'UNINSTALLED'; +export const UNINSTALLING = 'UNINSTALLING'; +export const UNKNOWN = 'UNKNOWN'; +export const validInstallStates = [ + DISABLED, + DISABLING, + ENABLED, + ENABLING, + DOWNLOADING, + ENABLED, + ERROR, + INSTALLED, + INSTALLING, + UNINSTALLED, + UNINSTALLING, + UNKNOWN, +]; + +// Add-on error states. +export const DOWNLOAD_FAILED = 'DOWNLOAD_FAILED'; +export const INSTALL_FAILED = 'INSTALL_FAILED'; + +// Unrecoverable errors. +export const FATAL_INSTALL_ERROR = 'FATAL_INSTALL_ERROR'; +export const FATAL_UNINSTALL_ERROR = 'FATAL_UNINSTALL_ERROR'; +export const FATAL_ERROR = 'FATAL_ERROR'; + +// Add-on types. +export const API_THEME_TYPE = 'persona'; +export const EXTENSION_TYPE = 'extension'; +export const THEME_TYPE = 'theme'; +// These types are not used. +// export const DICT_TYPE = 'dictionary'; +// export const SEARCH_TYPE = 'search'; +// export const LPAPP_TYPE = 'language'; +// export const PERSONA_TYPE = 'persona'; +export const validAddonTypes = [ + EXTENSION_TYPE, + THEME_TYPE, +]; + +// Theme preview actions. +export const THEME_INSTALL = 'InstallBrowserTheme'; +export const THEME_PREVIEW = 'PreviewBrowserTheme'; +export const THEME_RESET_PREVIEW = 'ResetBrowserThemePreview'; +export const validThemeActions = [ + THEME_INSTALL, + THEME_PREVIEW, + THEME_RESET_PREVIEW, +]; + +export const installEventList = [ + 'onDownloadStarted', + 'onDownloadProgress', + 'onDownloadEnded', + 'onDownloadCancelled', + 'onDownloadFailed', + 'onInstallStarted', + 'onInstallProgress', + 'onInstallEnded', + 'onInstallCancelled', + 'onInstallFailed', +]; + +// Install Types +export const INSTALL_STATE = 'INSTALL_STATE'; +export const START_DOWNLOAD = 'START_DOWNLOAD'; +export const DOWNLOAD_PROGRESS = 'DOWNLOAD_PROGRESS'; +export const INSTALL_COMPLETE = 'INSTALL_COMPLETE'; +export const UNINSTALL_COMPLETE = 'UNINSTALL_COMPLETE'; +export const INSTALL_ERROR = 'INSTALL_ERROR'; + +export const acceptedInstallTypes = [ + INSTALL_STATE, + START_DOWNLOAD, + DOWNLOAD_PROGRESS, + INSTALL_COMPLETE, + UNINSTALL_COMPLETE, + INSTALL_ERROR, +]; diff --git a/src/core/reducers/addons.js b/src/core/reducers/addons.js index 1757a3ce2f0..c896ef22eee 100644 --- a/src/core/reducers/addons.js +++ b/src/core/reducers/addons.js @@ -1,4 +1,4 @@ -import { API_THEME_TYPE, THEME_TYPE } from 'disco/constants'; +import { API_THEME_TYPE, THEME_TYPE } from 'core/constants'; const initialState = {}; diff --git a/src/disco/addonManager.js b/src/disco/addonManager.js index 06e60c23819..7bb4c200c32 100644 --- a/src/disco/addonManager.js +++ b/src/disco/addonManager.js @@ -3,9 +3,11 @@ import log from 'core/logger'; import { globalEvents, globalEventStatusMap, - installEventList, SET_ENABLE_NOT_AVAILABLE, } from 'disco/constants'; +import { + installEventList, +} from 'core/constants'; export function getAddon(guid, { _mozAddonManager = window.navigator.mozAddonManager } = {}) { diff --git a/src/disco/components/Addon.js b/src/disco/components/Addon.js index 975789dfbc0..f8b14ed1672 100644 --- a/src/disco/components/Addon.js +++ b/src/disco/components/Addon.js @@ -12,9 +12,8 @@ import tracking from 'core/tracking'; import * as addonManager from 'disco/addonManager'; import log from 'core/logger'; -import InstallButton from 'disco/components/InstallButton'; +import InstallButton from 'core/components/InstallButton'; import { - CLOSE_INFO, DISABLED, DOWNLOAD_FAILED, DOWNLOAD_PROGRESS, @@ -24,12 +23,9 @@ import { FATAL_ERROR, FATAL_INSTALL_ERROR, FATAL_UNINSTALL_ERROR, - INSTALL_CATEGORY, INSTALL_ERROR, INSTALL_FAILED, INSTALL_STATE, - SET_ENABLE_NOT_AVAILABLE, - SHOW_INFO, START_DOWNLOAD, THEME_INSTALL, THEME_PREVIEW, @@ -37,9 +33,15 @@ import { THEME_TYPE, UNINSTALLED, UNINSTALLING, - UNINSTALL_CATEGORY, validAddonTypes, validInstallStates, +} from 'core/constants'; +import { + CLOSE_INFO, + INSTALL_CATEGORY, + SET_ENABLE_NOT_AVAILABLE, + SHOW_INFO, + UNINSTALL_CATEGORY, } from 'disco/constants'; import 'disco/css/Addon.scss'; diff --git a/src/disco/constants.js b/src/disco/constants.js index f4547ca38fb..d307fd29c7c 100644 --- a/src/disco/constants.js +++ b/src/disco/constants.js @@ -1,98 +1,19 @@ -// Addon States. -export const DISABLED = 'DISABLED'; -export const DISABLING = 'DISABLING'; -export const DOWNLOADING = 'DOWNLOADING'; -export const ENABLED = 'ENABLED'; -export const ENABLING = 'ENABLING'; -export const ERROR = 'ERROR'; -export const INSTALLED = 'INSTALLED'; -export const INSTALLING = 'INSTALLING'; -export const UNINSTALLED = 'UNINSTALLED'; -export const UNINSTALLING = 'UNINSTALLING'; -export const UNKNOWN = 'UNKNOWN'; -export const validInstallStates = [ +import { DISABLED, DISABLING, ENABLED, ENABLING, - DOWNLOADING, - ENABLED, - ERROR, INSTALLED, INSTALLING, UNINSTALLED, UNINSTALLING, - UNKNOWN, -]; - -// Add-on error states. -export const DOWNLOAD_FAILED = 'DOWNLOAD_FAILED'; -export const INSTALL_FAILED = 'INSTALL_FAILED'; - -// Unrecoverable errors. -export const FATAL_INSTALL_ERROR = 'FATAL_INSTALL_ERROR'; -export const FATAL_UNINSTALL_ERROR = 'FATAL_UNINSTALL_ERROR'; -export const FATAL_ERROR = 'FATAL_ERROR'; - -// Add-on types. -export const API_THEME_TYPE = 'persona'; -export const EXTENSION_TYPE = 'extension'; -export const THEME_TYPE = 'theme'; -// These types are not used. -// export const DICT_TYPE = 'dictionary'; -// export const SEARCH_TYPE = 'search'; -// export const LPAPP_TYPE = 'language'; -// export const PERSONA_TYPE = 'persona'; -export const validAddonTypes = [ - EXTENSION_TYPE, - THEME_TYPE, -]; - -// Theme preview actions. -export const THEME_INSTALL = 'InstallBrowserTheme'; -export const THEME_PREVIEW = 'PreviewBrowserTheme'; -export const THEME_RESET_PREVIEW = 'ResetBrowserThemePreview'; -export const validThemeActions = [ - THEME_INSTALL, - THEME_PREVIEW, - THEME_RESET_PREVIEW, -]; - -export const installEventList = [ - 'onDownloadStarted', - 'onDownloadProgress', - 'onDownloadEnded', - 'onDownloadCancelled', - 'onDownloadFailed', - 'onInstallStarted', - 'onInstallProgress', - 'onInstallEnded', - 'onInstallCancelled', - 'onInstallFailed', -]; +} from 'core/constants'; export const INSTALL_CATEGORY = 'AMO Addon / Theme Installs'; export const UNINSTALL_CATEGORY = 'AMO Addon / Theme Uninstalls'; export const VIDEO_CATEGORY = 'Discovery Video'; export const NAVIGATION_CATEGORY = 'Discovery Navigation'; -// Install Types -export const INSTALL_STATE = 'INSTALL_STATE'; -export const START_DOWNLOAD = 'START_DOWNLOAD'; -export const DOWNLOAD_PROGRESS = 'DOWNLOAD_PROGRESS'; -export const INSTALL_COMPLETE = 'INSTALL_COMPLETE'; -export const UNINSTALL_COMPLETE = 'UNINSTALL_COMPLETE'; -export const INSTALL_ERROR = 'INSTALL_ERROR'; - -export const acceptedInstallTypes = [ - INSTALL_STATE, - START_DOWNLOAD, - DOWNLOAD_PROGRESS, - INSTALL_COMPLETE, - UNINSTALL_COMPLETE, - INSTALL_ERROR, -]; - export const globalEventStatusMap = { onDisabled: DISABLED, onEnabled: ENABLED, diff --git a/src/disco/containers/DiscoPane.js b/src/disco/containers/DiscoPane.js index ee1beb15b82..9eb84b8a520 100644 --- a/src/disco/containers/DiscoPane.js +++ b/src/disco/containers/DiscoPane.js @@ -11,10 +11,10 @@ import { discoResults } from 'disco/actions'; import { loadEntities } from 'core/actions'; import { addChangeListeners } from 'disco/addonManager'; import { - INSTALL_STATE, NAVIGATION_CATEGORY, VIDEO_CATEGORY, } from 'disco/constants'; +import { INSTALL_STATE } from 'core/constants'; import Addon from 'disco/components/Addon'; import InfoDialog from 'disco/components/InfoDialog'; diff --git a/src/disco/reducers/installations.js b/src/disco/reducers/installations.js index b8c901a1886..413d58acbdb 100644 --- a/src/disco/reducers/installations.js +++ b/src/disco/reducers/installations.js @@ -10,7 +10,7 @@ import { UNINSTALLED, UNINSTALL_COMPLETE, acceptedInstallTypes, -} from 'disco/constants'; +} from 'core/constants'; export default function installations(state = {}, { type, payload }) { diff --git a/src/disco/themePreview.js b/src/disco/themePreview.js index 297b7008341..a8296b083d5 100644 --- a/src/disco/themePreview.js +++ b/src/disco/themePreview.js @@ -1,4 +1,4 @@ -import { validThemeActions } from 'disco/constants'; +import { validThemeActions } from 'core/constants'; export default function themeAction(node, action, _doc = document) { if (!validThemeActions.includes(action)) { diff --git a/tests/client/amo/components/TestAddonDetail.js b/tests/client/amo/components/TestAddonDetail.js index 68c2b41d424..7457c14e5df 100644 --- a/tests/client/amo/components/TestAddonDetail.js +++ b/tests/client/amo/components/TestAddonDetail.js @@ -8,7 +8,7 @@ import { import AddonDetail, { allowedDescriptionTags } from 'amo/components/AddonDetail'; import I18nProvider from 'core/i18n/Provider'; -import InstallButton from 'disco/components/InstallButton'; +import InstallButton from 'core/components/InstallButton'; import { getFakeI18nInst } from 'tests/client/helpers'; diff --git a/tests/client/disco/components/TestInstallButton.js b/tests/client/core/components/TestInstallButton.js similarity index 99% rename from tests/client/disco/components/TestInstallButton.js rename to tests/client/core/components/TestInstallButton.js index 2a977427219..fe1d41fefb8 100644 --- a/tests/client/disco/components/TestInstallButton.js +++ b/tests/client/core/components/TestInstallButton.js @@ -4,7 +4,7 @@ import { findDOMNode } from 'react-dom'; import { InstallButton, -} from 'disco/components/InstallButton'; +} from 'core/components/InstallButton'; import { DISABLED, DISABLING, @@ -17,7 +17,7 @@ import { UNINSTALLED, UNINSTALLING, UNKNOWN, -} from 'disco/constants'; +} from 'core/constants'; import { getFakeI18nInst } from 'tests/client/helpers'; diff --git a/tests/client/core/reducers/test_addons.js b/tests/client/core/reducers/test_addons.js index 2272c9a82af..de800e35856 100644 --- a/tests/client/core/reducers/test_addons.js +++ b/tests/client/core/reducers/test_addons.js @@ -1,5 +1,5 @@ import addons from 'core/reducers/addons'; -import { API_THEME_TYPE, THEME_TYPE } from 'disco/constants'; +import { API_THEME_TYPE, THEME_TYPE } from 'core/constants'; describe('addon reducer', () => { let originalState; diff --git a/tests/client/disco/TestAddonManager.js b/tests/client/disco/TestAddonManager.js index def8fc1d355..689329c11ab 100644 --- a/tests/client/disco/TestAddonManager.js +++ b/tests/client/disco/TestAddonManager.js @@ -1,8 +1,8 @@ import * as addonManager from 'disco/addonManager'; import { unexpectedSuccess } from 'tests/client/helpers'; +import { installEventList } from 'core/constants'; import { globalEventStatusMap, - installEventList, SET_ENABLE_NOT_AVAILABLE, } from 'disco/constants'; diff --git a/tests/client/disco/TestThemePreview.js b/tests/client/disco/TestThemePreview.js index 4d8f6c99be2..c41ac069c7b 100644 --- a/tests/client/disco/TestThemePreview.js +++ b/tests/client/disco/TestThemePreview.js @@ -1,5 +1,5 @@ import themeAction from 'disco/themePreview'; -import { THEME_PREVIEW } from 'disco/constants'; +import { THEME_PREVIEW } from 'core/constants'; describe('Theme Preview Lib', () => { diff --git a/tests/client/disco/components/TestAddon.js b/tests/client/disco/components/TestAddon.js index cbb0e1c9f4d..b33e9ee82c0 100644 --- a/tests/client/disco/components/TestAddon.js +++ b/tests/client/disco/components/TestAddon.js @@ -13,7 +13,6 @@ import { mapStateToProps, } from 'disco/components/Addon'; import { - CLOSE_INFO, DISABLED, DOWNLOAD_FAILED, DOWNLOAD_PROGRESS, @@ -24,11 +23,8 @@ import { FATAL_INSTALL_ERROR, FATAL_UNINSTALL_ERROR, INSTALLED, - INSTALL_CATEGORY, INSTALL_FAILED, INSTALL_STATE, - SET_ENABLE_NOT_AVAILABLE, - SHOW_INFO, START_DOWNLOAD, THEME_INSTALL, THEME_PREVIEW, @@ -36,6 +32,12 @@ import { THEME_TYPE, UNINSTALLED, UNINSTALLING, +} from 'core/constants'; +import { + CLOSE_INFO, + INSTALL_CATEGORY, + SET_ENABLE_NOT_AVAILABLE, + SHOW_INFO, UNINSTALL_CATEGORY, } from 'disco/constants'; import { getFakeAddonManagerWrapper, getFakeI18nInst } from 'tests/client/helpers'; diff --git a/tests/client/disco/containers/TestDiscoPane.js b/tests/client/disco/containers/TestDiscoPane.js index 25c85c8121a..727d09955ef 100644 --- a/tests/client/disco/containers/TestDiscoPane.js +++ b/tests/client/disco/containers/TestDiscoPane.js @@ -8,6 +8,8 @@ import createStore from 'disco/store'; import { EXTENSION_TYPE, INSTALL_STATE, +} from 'core/constants'; +import { NAVIGATION_CATEGORY, VIDEO_CATEGORY, globalEvents, diff --git a/tests/client/disco/reducers/test_installations.js b/tests/client/disco/reducers/test_installations.js index d8a84561dca..1280f96f8b3 100644 --- a/tests/client/disco/reducers/test_installations.js +++ b/tests/client/disco/reducers/test_installations.js @@ -13,7 +13,7 @@ import { UNINSTALL_COMPLETE, UNINSTALLED, UNINSTALLING, -} from 'disco/constants'; +} from 'core/constants'; import installations from 'disco/reducers/installations'; describe('installations reducer', () => { diff --git a/tests/client/helpers.js b/tests/client/helpers.js index 32a2c00777d..6077734243e 100644 --- a/tests/client/helpers.js +++ b/tests/client/helpers.js @@ -1,6 +1,6 @@ import React from 'react'; import { createRenderer } from 'react-addons-test-utils'; -import { EXTENSION_TYPE } from 'disco/constants'; +import { EXTENSION_TYPE } from 'core/constants'; import { sprintf } from 'jed'; export function shallowRender(stuff) { From 0e450a63001b3154c50cb47d7cc6d14e7d189b71 Mon Sep 17 00:00:00 2001 From: Kumar McMillan Date: Wed, 17 Aug 2016 09:38:28 -0500 Subject: [PATCH 2/2] remove unused types --- src/core/constants.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/core/constants.js b/src/core/constants.js index bffbeb2f522..7a87cbb545b 100644 --- a/src/core/constants.js +++ b/src/core/constants.js @@ -38,11 +38,6 @@ export const FATAL_ERROR = 'FATAL_ERROR'; export const API_THEME_TYPE = 'persona'; export const EXTENSION_TYPE = 'extension'; export const THEME_TYPE = 'theme'; -// These types are not used. -// export const DICT_TYPE = 'dictionary'; -// export const SEARCH_TYPE = 'search'; -// export const LPAPP_TYPE = 'language'; -// export const PERSONA_TYPE = 'persona'; export const validAddonTypes = [ EXTENSION_TYPE, THEME_TYPE,