From 1d95b271a3f37a697f200a5ef0fab232c6243762 Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Thu, 6 Apr 2017 21:18:18 +1000 Subject: [PATCH 1/2] Fix an issue with eslint and rest spreads --- package.json | 2 +- src/modules/ui/components/shortcuts_help.js | 16 ++-- src/modules/ui/configs/handle_routing.js | 2 +- yarn.lock | 100 ++++++++++++++------ 4 files changed, 80 insertions(+), 40 deletions(-) diff --git a/package.json b/package.json index a04ad5d..4c76266 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "babel-preset-stage-0": "^6.5.0", "chai": "^3.5.0", "enzyme": "^2.2.0", - "eslint": "^2.7.0", + "eslint": "^3.19.0", "eslint-config-airbnb": "^7.0.0", "eslint-plugin-babel": "^3.2.0", "eslint-plugin-jsx-a11y": "^0.6.2", diff --git a/src/modules/ui/components/shortcuts_help.js b/src/modules/ui/components/shortcuts_help.js index 94c1d82..44822ae 100755 --- a/src/modules/ui/components/shortcuts_help.js +++ b/src/modules/ui/components/shortcuts_help.js @@ -67,14 +67,14 @@ export const Keys = ({ shortcutKeys }) => { } // if we have multiple key combinations for a shortcut - let keys = shortcutKeys.map((key, index, arr) => { + const keys = shortcutKeys.map((key, index, arr) => { return ( - - {key} - {/* add / & space if it is not a last key combination */} - {((arr.length - 1) !== index) ? /   : ''} - - ); + + {key} + {/* add / & space if it is not a last key combination */} + {((arr.length - 1) !== index) ? /   : ''} + + ); }); return ( @@ -87,7 +87,7 @@ Keys.propTypes = { }; export const Shortcuts = ({ appShortcuts }) => { - let shortcuts = appShortcuts.map((shortcut, index) => { + const shortcuts = appShortcuts.map((shortcut, index) => { return (
diff --git a/src/modules/ui/configs/handle_routing.js b/src/modules/ui/configs/handle_routing.js index 3886d18..5c323d3 100755 --- a/src/modules/ui/configs/handle_routing.js +++ b/src/modules/ui/configs/handle_routing.js @@ -57,7 +57,7 @@ export function updateStore(queryParams, actions) { left = 1, panelRight = 0, downPanel, - ...customQueryParams, + ...customQueryParams } = queryParams; if (selectedKind && selectedStory) { diff --git a/yarn.lock b/yarn.lock index b43eac3..5951fb0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -285,7 +285,7 @@ babel-cli@^6.5.0: optionalDependencies: chokidar "^1.6.1" -babel-code-frame@^6.22.0: +babel-code-frame@^6.16.0, babel-code-frame@^6.22.0: version "6.22.0" resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.22.0.tgz#027620bee567a88c32561574e7fd0801d33118e4" dependencies: @@ -1222,7 +1222,7 @@ concat-map@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" -concat-stream@^1.4.6: +concat-stream@^1.5.2: version "1.6.0" resolved "https://registry.yarnpkg.com/concat-stream/-/concat-stream-1.6.0.tgz#0aac662fd52be78964d5532f694784e70110acf7" dependencies: @@ -1415,9 +1415,9 @@ diff@1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/diff/-/diff-1.4.0.tgz#7f28d2eb9ee7b15a97efd89ce63dcfdaa3ccbabf" -doctrine@^1.2.2: - version "1.5.0" - resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-1.5.0.tgz#379dce730f6166f76cefa4e6707a159b02c5a6fa" +doctrine@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/doctrine/-/doctrine-2.0.0.tgz#c73d8d2909d22291e1a007a395804da8b665fe63" dependencies: esutils "^2.0.2" isarray "^1.0.0" @@ -1645,23 +1645,24 @@ eslint-plugin-react@^4.3.0: version "4.3.0" resolved "https://registry.yarnpkg.com/eslint-plugin-react/-/eslint-plugin-react-4.3.0.tgz#c79aac8069d62de27887c13b8298d592088de378" -eslint@^2.7.0: - version "2.13.1" - resolved "https://registry.yarnpkg.com/eslint/-/eslint-2.13.1.tgz#e4cc8fa0f009fb829aaae23855a29360be1f6c11" +eslint@^3.19.0: + version "3.19.0" + resolved "https://registry.yarnpkg.com/eslint/-/eslint-3.19.0.tgz#c8fc6201c7f40dd08941b87c085767386a679acc" dependencies: + babel-code-frame "^6.16.0" chalk "^1.1.3" - concat-stream "^1.4.6" + concat-stream "^1.5.2" debug "^2.1.1" - doctrine "^1.2.2" - es6-map "^0.1.3" + doctrine "^2.0.0" escope "^3.6.0" - espree "^3.1.6" + espree "^3.4.0" + esquery "^1.0.0" estraverse "^4.2.0" esutils "^2.0.2" - file-entry-cache "^1.1.1" + file-entry-cache "^2.0.0" glob "^7.0.3" - globals "^9.2.0" - ignore "^3.1.2" + globals "^9.14.0" + ignore "^3.2.0" imurmurhash "^0.1.4" inquirer "^0.12.0" is-my-json-valid "^2.10.0" @@ -1671,19 +1672,20 @@ eslint@^2.7.0: levn "^0.3.0" lodash "^4.0.0" mkdirp "^0.5.0" - optionator "^0.8.1" - path-is-absolute "^1.0.0" + natural-compare "^1.4.0" + optionator "^0.8.2" path-is-inside "^1.0.1" pluralize "^1.2.1" progress "^1.1.8" require-uncached "^1.0.2" - shelljs "^0.6.0" - strip-json-comments "~1.0.1" + shelljs "^0.7.5" + strip-bom "^3.0.0" + strip-json-comments "~2.0.1" table "^3.7.8" text-table "~0.2.0" user-home "^2.0.0" -espree@^3.1.6: +espree@^3.4.0: version "3.4.1" resolved "https://registry.yarnpkg.com/espree/-/espree-3.4.1.tgz#28a83ab4aaed71ed8fe0f5efe61b76a05c13c4d2" dependencies: @@ -1698,6 +1700,12 @@ esprima@^3.1.1: version "3.1.3" resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.1.3.tgz#fdca51cee6133895e3c88d535ce49dbff62a4633" +esquery@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/esquery/-/esquery-1.0.0.tgz#cfba8b57d7fba93f17298a8a006a04cda13d80fa" + dependencies: + estraverse "^4.0.0" + esrecurse@^4.1.0: version "4.1.0" resolved "https://registry.yarnpkg.com/esrecurse/-/esrecurse-4.1.0.tgz#4713b6536adf7f2ac4f327d559e7756bff648220" @@ -1709,7 +1717,7 @@ estraverse@^1.9.1: version "1.9.3" resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-1.9.3.tgz#af67f2dc922582415950926091a4005d29c9bb44" -estraverse@^4.1.1, estraverse@^4.2.0: +estraverse@^4.0.0, estraverse@^4.1.1, estraverse@^4.2.0: version "4.2.0" resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.2.0.tgz#0dee3fed31fcd469618ce7342099fc1afa0bdb13" @@ -1826,9 +1834,9 @@ figures@^1.3.5: escape-string-regexp "^1.0.5" object-assign "^4.1.0" -file-entry-cache@^1.1.1: - version "1.3.1" - resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-1.3.1.tgz#44c61ea607ae4be9c1402f41f44270cbfe334ff8" +file-entry-cache@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/file-entry-cache/-/file-entry-cache-2.0.0.tgz#c392990c3e684783d838b8c84a45d8a048458361" dependencies: flat-cache "^1.2.1" object-assign "^4.0.1" @@ -2035,7 +2043,7 @@ glob@^7.0.0, glob@^7.0.3, glob@^7.0.5: once "^1.3.0" path-is-absolute "^1.0.0" -globals@^9.0.0, globals@^9.2.0: +globals@^9.0.0, globals@^9.14.0: version "9.17.0" resolved "https://registry.yarnpkg.com/globals/-/globals-9.17.0.tgz#0c0ca696d9b9bb694d2e5470bd37777caad50286" @@ -2161,7 +2169,7 @@ ieee754@^1.1.4: version "1.1.8" resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.8.tgz#be33d40ac10ef1926701f6f08a2d86fbfd1ad3e4" -ignore@^3.1.2: +ignore@^3.2.0: version "3.2.6" resolved "https://registry.yarnpkg.com/ignore/-/ignore-3.2.6.tgz#26e8da0644be0bb4cb39516f6c79f0e0f4ffe48c" @@ -2218,6 +2226,10 @@ interpret@^0.6.4: version "0.6.6" resolved "https://registry.yarnpkg.com/interpret/-/interpret-0.6.6.tgz#fecd7a18e7ce5ca6abfb953e1f86213a49f1625b" +interpret@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.0.2.tgz#f4f623f0bb7122f15f5717c8e254b8161b5c5b2d" + invariant@2.x.x, invariant@^2.2.0: version "2.2.2" resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.2.tgz#9e1f56ac0acdb6bf303306f338be3b204ae60360" @@ -2757,6 +2769,10 @@ nan@^2.3.0: version "2.5.1" resolved "https://registry.yarnpkg.com/nan/-/nan-2.5.1.tgz#d5b01691253326a97a2bbee9e61c55d8d60351e2" +natural-compare@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" + negotiator@0.6.1: version "0.6.1" resolved "https://registry.yarnpkg.com/negotiator/-/negotiator-0.6.1.tgz#2b327184e8992101177b28563fb5e7102acd0ca9" @@ -2925,7 +2941,7 @@ optimist@~0.6.0: minimist "~0.0.1" wordwrap "~0.0.2" -optionator@^0.8.1: +optionator@^0.8.1, optionator@^0.8.2: version "0.8.2" resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.2.tgz#364c5e409d3f4d6301d6c0b4c05bba50180aeb64" dependencies: @@ -3008,6 +3024,10 @@ path-is-inside@^1.0.1: version "1.0.2" resolved "https://registry.yarnpkg.com/path-is-inside/-/path-is-inside-1.0.2.tgz#365417dede44430d1c11af61027facf074bdfc53" +path-parse@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.5.tgz#3c1adf871ea9cd6c9431b6ea2bd74a0ff055c4c1" + path-to-regexp@0.1.7: version "0.1.7" resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c" @@ -3248,6 +3268,12 @@ readline2@^1.0.1: is-fullwidth-code-point "^1.0.0" mute-stream "0.0.5" +rechoir@^0.6.2: + version "0.6.2" + resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384" + dependencies: + resolve "^1.1.6" + redbox-react@^1.2.2: version "1.3.4" resolved "https://registry.yarnpkg.com/redbox-react/-/redbox-react-1.3.4.tgz#3d882bb62cc7c8f6256279d12f05c6a5a96d24c6" @@ -3361,6 +3387,12 @@ resolve-from@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-1.0.1.tgz#26cbfe935d1aeeeabb29bc3fe5aeb01e93d44226" +resolve@^1.1.6: + version "1.3.2" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.3.2.tgz#1f0442c9e0cbb8136e87b9305f932f46c7f28235" + dependencies: + path-parse "^1.0.5" + restore-cursor@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/restore-cursor/-/restore-cursor-1.0.1.tgz#34661f46886327fed2991479152252df92daa541" @@ -3467,6 +3499,14 @@ shelljs@^0.6.0: version "0.6.1" resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.6.1.tgz#ec6211bed1920442088fe0f70b2837232ed2c8a8" +shelljs@^0.7.5: + version "0.7.7" + resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.7.7.tgz#b2f5c77ef97148f4b4f6e22682e10bba8667cff1" + dependencies: + glob "^7.0.0" + interpret "^1.0.0" + rechoir "^0.6.2" + sigmund@~1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/sigmund/-/sigmund-1.0.1.tgz#3ff21f198cad2175f9f3b781853fd94d0d19b590" @@ -3620,9 +3660,9 @@ strip-ansi@^3.0.0, strip-ansi@^3.0.1: dependencies: ansi-regex "^2.0.0" -strip-json-comments@~1.0.1: - version "1.0.4" - resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-1.0.4.tgz#1e15fbcac97d3ee99bf2d73b4c656b082bbafb91" +strip-bom@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3" strip-json-comments@~2.0.1: version "2.0.1" From dbdf7945d554be187b62ec3a6275926739ccf193 Mon Sep 17 00:00:00 2001 From: Tom Coleman Date: Thu, 6 Apr 2017 21:11:25 +1000 Subject: [PATCH 2/2] Render the first story for a kind if no story selected. For https://github.com/storybooks/react-storybook/issues/674 --- dist/modules/api/actions/api.js | 1 + .../ui/components/layout/dimensions.js | 145 ++++++++++++++++++ dist/modules/ui/components/layout/index.js | 90 +++++++++-- dist/modules/ui/configs/handle_routing.js | 2 +- src/modules/api/actions/api.js | 1 + .../ui/configs/__tests__/handle_routing.js | 40 +++-- src/modules/ui/configs/handle_routing.js | 2 +- 7 files changed, 253 insertions(+), 28 deletions(-) create mode 100644 dist/modules/ui/components/layout/dimensions.js diff --git a/dist/modules/api/actions/api.js b/dist/modules/api/actions/api.js index a303d66..c49eb6f 100755 --- a/dist/modules/api/actions/api.js +++ b/dist/modules/api/actions/api.js @@ -77,6 +77,7 @@ function ensureStory(storyKinds, selectedKind, selectedStory) { }); if (found) return found; + // if the selected story is non-existant, select the first story return kindInfo.stories[0]; } diff --git a/dist/modules/ui/components/layout/dimensions.js b/dist/modules/ui/components/layout/dimensions.js new file mode 100644 index 0000000..a7269d6 --- /dev/null +++ b/dist/modules/ui/components/layout/dimensions.js @@ -0,0 +1,145 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); + +var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf); + +var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck'); + +var _classCallCheck3 = _interopRequireDefault(_classCallCheck2); + +var _createClass2 = require('babel-runtime/helpers/createClass'); + +var _createClass3 = _interopRequireDefault(_createClass2); + +var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn'); + +var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2); + +var _inherits2 = require('babel-runtime/helpers/inherits'); + +var _inherits3 = _interopRequireDefault(_inherits2); + +var _extends2 = require('babel-runtime/helpers/extends'); + +var _extends3 = _interopRequireDefault(_extends2); + +var _react = require('react'); + +var _react2 = _interopRequireDefault(_react); + +var _theme = require('../theme'); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var container = { + position: 'absolute', + padding: 5, + bottom: 10, + right: 10, + backgroundColor: 'rgba(255, 255, 255, 0.5)' +}; + +var dimensionStyle = (0, _extends3.default)({ + fontSize: 12 +}, _theme.baseFonts); + +var delimeterStyle = (0, _extends3.default)({ + margin: '0px 5px', + fontSize: 12 +}, _theme.baseFonts); + +// Same as Chrome's timeout in the developer tools +var DISPLAY_TIMEOUT = 1000; + +var Dimensions = function (_React$Component) { + (0, _inherits3.default)(Dimensions, _React$Component); + + function Dimensions(props) { + (0, _classCallCheck3.default)(this, Dimensions); + + var _this = (0, _possibleConstructorReturn3.default)(this, (Dimensions.__proto__ || (0, _getPrototypeOf2.default)(Dimensions)).call(this, props)); + + _this.state = { + isVisible: false + }; + + _this._hideTimeout = null; + return _this; + } + + (0, _createClass3.default)(Dimensions, [{ + key: 'componentWillReceiveProps', + value: function componentWillReceiveProps(_ref) { + var width = _ref.width, + height = _ref.height; + + if (width !== this.state.width || height !== this.state.height) { + this.onChange(width, height); + } + } + }, { + key: 'componentWillUnmount', + value: function componentWillUnmount() { + clearTimeout(this._hideTimeout); + } + }, { + key: 'onChange', + value: function onChange(width, height) { + var _this2 = this; + + this.setState({ isVisible: true }); + + this._hideTimeout = setTimeout(function () { + // Ensure the dimensions aren't still changing + if (width === _this2.props.width && height === _this2.props.height) { + _this2.setState({ isVisible: false }); + } + }, DISPLAY_TIMEOUT); + } + }, { + key: 'render', + value: function render() { + if (!this.state.isVisible) { + return null; + } + + var _props = this.props, + width = _props.width, + height = _props.height; + + + return _react2.default.createElement( + 'div', + { style: container }, + _react2.default.createElement( + 'span', + { style: dimensionStyle }, + width + 'px' + ), + _react2.default.createElement( + 'span', + { style: delimeterStyle }, + 'x' + ), + _react2.default.createElement( + 'span', + { style: dimensionStyle }, + height + 'px' + ) + ); + } + }]); + return Dimensions; +}(_react2.default.Component); + +Dimensions.propTypes = { + width: _react2.default.PropTypes.number.isRequired, + height: _react2.default.PropTypes.number.isRequired +}; + +exports.default = Dimensions; \ No newline at end of file diff --git a/dist/modules/ui/components/layout/index.js b/dist/modules/ui/components/layout/index.js index f399529..69ae9d6 100755 --- a/dist/modules/ui/components/layout/index.js +++ b/dist/modules/ui/components/layout/index.js @@ -36,6 +36,10 @@ var _hsplit = require('./hsplit'); var _hsplit2 = _interopRequireDefault(_hsplit); +var _dimensions = require('./dimensions'); + +var _dimensions2 = _interopRequireDefault(_dimensions); + var _reactSplitPane = require('@kadira/react-split-pane'); var _reactSplitPane2 = _interopRequireDefault(_reactSplitPane); @@ -104,17 +108,72 @@ var onDragEnd = function onDragEnd() { document.body.classList.remove('dragging'); }; +var saveHeightPanel = function saveHeightPanel(h) { + try { + localStorage.setItem('splitPos', h); + return true; + } catch (e) { + return false; + } +}; + +var getSavedHeight = function getSavedHeight(h) { + try { + return localStorage.getItem('splitPos'); + } catch (e) { + return h; + } +}; + var Layout = function (_React$Component) { (0, _inherits3.default)(Layout, _React$Component); - function Layout() { + function Layout(props) { (0, _classCallCheck3.default)(this, Layout); - return (0, _possibleConstructorReturn3.default)(this, (Layout.__proto__ || (0, _getPrototypeOf2.default)(Layout)).apply(this, arguments)); + + var _this = (0, _possibleConstructorReturn3.default)(this, (Layout.__proto__ || (0, _getPrototypeOf2.default)(Layout)).call(this, props)); + + _this.state = { + previewPanelDimensions: { + height: 0, + width: 0 + } + }; + + _this.onResize = _this.onResize.bind(_this); + return _this; } (0, _createClass3.default)(Layout, [{ + key: 'componentDidMount', + value: function componentDidMount() { + window.addEventListener('resize', this.onResize); + } + }, { + key: 'componentWillUnmount', + value: function componentWillUnmount() { + window.removeEventListener('resize', this.onResize); + } + }, { + key: 'onResize', + value: function onResize() { + var _previewPanelRef = this.previewPanelRef, + clientWidth = _previewPanelRef.clientWidth, + clientHeight = _previewPanelRef.clientHeight; + + + this.setState({ + previewPanelDimensions: { + width: clientWidth, + height: clientHeight + } + }); + } + }, { key: 'render', value: function render() { + var _this2 = this; + var _props = this.props, goFullScreen = _props.goFullScreen, showLeftPanel = _props.showLeftPanel, @@ -123,6 +182,7 @@ var Layout = function (_React$Component) { downPanel = _props.downPanel, leftPanel = _props.leftPanel, preview = _props.preview; + var previewPanelDimensions = this.state.previewPanelDimensions; var previewStyle = normalPreviewStyle; @@ -137,12 +197,8 @@ var Layout = function (_React$Component) { downPanelDefaultSize = downPanelInRight ? 400 : 200; } - if (typeof localStorage !== 'undefined') { - var savedSize = localStorage.getItem('splitPos'); - if (typeof savedSize !== 'undefined') { - downPanelDefaultSize = savedSize; - } - } + // Get the value from localStorage or user downPanelDefaultSize + downPanelDefaultSize = getSavedHeight(downPanelDefaultSize); return _react2.default.createElement( 'div', @@ -155,7 +211,8 @@ var Layout = function (_React$Component) { defaultSize: leftPanelDefaultSize, resizerChildren: vsplit, onDragStarted: onDragStart, - onDragFinished: onDragEnd + onDragFinished: onDragEnd, + onChange: this.onResize }, _react2.default.createElement( 'div', @@ -173,9 +230,8 @@ var Layout = function (_React$Component) { onDragStarted: onDragStart, onDragFinished: onDragEnd, onChange: function onChange(size) { - if (typeof localStorage !== 'undefined') { - localStorage.setItem('splitPos', size); - } + saveHeightPanel(size); + _this2.onResize(); } }, _react2.default.createElement( @@ -183,9 +239,15 @@ var Layout = function (_React$Component) { { style: contentPanelStyle }, _react2.default.createElement( 'div', - { style: previewStyle }, + { + style: previewStyle, + ref: function ref(_ref) { + _this2.previewPanelRef = _ref; + } + }, preview() - ) + ), + _react2.default.createElement(_dimensions2.default, previewPanelDimensions) ), _react2.default.createElement( 'div', diff --git a/dist/modules/ui/configs/handle_routing.js b/dist/modules/ui/configs/handle_routing.js index 2b33503..e3ce38d 100755 --- a/dist/modules/ui/configs/handle_routing.js +++ b/dist/modules/ui/configs/handle_routing.js @@ -103,7 +103,7 @@ function updateStore(queryParams, actions) { customQueryParams = (0, _objectWithoutProperties3.default)(queryParams, ['selectedKind', 'selectedStory', 'full', 'down', 'left', 'panelRight', 'downPanel']); - if (selectedKind && selectedStory) { + if (selectedKind) { actions.api.selectStory(selectedKind, selectedStory); } diff --git a/src/modules/api/actions/api.js b/src/modules/api/actions/api.js index dc69002..36d113c 100755 --- a/src/modules/api/actions/api.js +++ b/src/modules/api/actions/api.js @@ -43,6 +43,7 @@ export function ensureStory(storyKinds, selectedKind, selectedStory) { const found = kindInfo.stories.find(item => item === selectedStory); if (found) return found; + // if the selected story is non-existant, select the first story return kindInfo.stories[0]; } diff --git a/src/modules/ui/configs/__tests__/handle_routing.js b/src/modules/ui/configs/__tests__/handle_routing.js index 990af6c..70eb044 100755 --- a/src/modules/ui/configs/__tests__/handle_routing.js +++ b/src/modules/ui/configs/__tests__/handle_routing.js @@ -59,19 +59,21 @@ describe('manager.ui.config.handle_routing', () => { }); describe('handleInitialUrl', () => { + const mockActions = () => ({ + api: { + selectStory: sinon.mock(), + setQueryParams: sinon.mock(), + }, + shortcuts: { + setOptions: sinon.mock(), + }, + ui: { + selectDownPanel: sinon.mock(), + }, + }); + it('should call the correct action according to URL', () => { - const actions = { - api: { - selectStory: sinon.mock(), - setQueryParams: sinon.mock(), - }, - shortcuts: { - setOptions: sinon.mock(), - }, - ui: { - selectDownPanel: sinon.mock(), - }, - }; + const actions = mockActions(); // eslint-disable-next-line max-len const url = '?selectedKind=kk&selectedStory=ss&full=1&down=0&left=0&panelRight=0&downPanel=test&customText=teststring'; @@ -96,5 +98,19 @@ describe('manager.ui.config.handle_routing', () => { expect(actions.api.setQueryParams.calledWith({ customText: 'teststring' })).to.be.true; /* eslint-enable no-unused-expressions */ }); + + it('should handle URLs with only kind selected', () => { + const actions = mockActions(); + + const url = '?selectedKind=kk'; + + const location = { + search: url, + }; + window.location.search = url; + handleInitialUrl(actions, location); + + expect(actions.api.selectStory.callCount).to.be.equal(1); + }); }); }); diff --git a/src/modules/ui/configs/handle_routing.js b/src/modules/ui/configs/handle_routing.js index 5c323d3..c76f7a7 100755 --- a/src/modules/ui/configs/handle_routing.js +++ b/src/modules/ui/configs/handle_routing.js @@ -60,7 +60,7 @@ export function updateStore(queryParams, actions) { ...customQueryParams } = queryParams; - if (selectedKind && selectedStory) { + if (selectedKind) { actions.api.selectStory(selectedKind, selectedStory); }