From e39c377e0823afe6c0a2336e68ea4f48a99ed362 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Thu, 31 Aug 2017 16:33:51 +0700 Subject: [PATCH 1/3] Hide empty categories --- .../client/components/Menu.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/talk-plugin-viewing-options/client/components/Menu.js b/plugins/talk-plugin-viewing-options/client/components/Menu.js index 68afe4b3b..18186eccc 100644 --- a/plugins/talk-plugin-viewing-options/client/components/Menu.js +++ b/plugins/talk-plugin-viewing-options/client/components/Menu.js @@ -2,6 +2,7 @@ import React from 'react'; import cn from 'classnames'; import styles from './Menu.css'; import {capitalize} from 'plugin-api/beta/client/utils'; +import {IfSlotIsNotEmpty} from 'plugin-api/beta/client/components'; import Category from './Category'; import {t} from 'plugin-api/beta/client/services'; @@ -16,11 +17,12 @@ class Menu extends React.Component {
{ Object.keys(this.categories).map((category) => - + + + ) }
From b5daf5882bc9654181f96c918344f1a70467fad0 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Thu, 31 Aug 2017 16:58:01 +0700 Subject: [PATCH 2/3] IfSlotIsEmpty and IfSlotIsNotEmpty now only renders a single child --- client/coral-framework/components/IfSlotIsEmpty.js | 11 +++-------- client/coral-framework/components/IfSlotIsNotEmpty.js | 11 +++-------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/client/coral-framework/components/IfSlotIsEmpty.js b/client/coral-framework/components/IfSlotIsEmpty.js index 557ee3b3d..72dc8c988 100644 --- a/client/coral-framework/components/IfSlotIsEmpty.js +++ b/client/coral-framework/components/IfSlotIsEmpty.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, {Children} from 'react'; import {connect} from 'react-redux'; import PropTypes from 'prop-types'; import omit from 'lodash/omit'; @@ -28,18 +28,13 @@ class IfSlotIsEmpty extends React.Component { } render() { - const {className, component: Component = 'div', children} = this.props; - return ( - - {this.isSlotEmpty() ? children : null} - - ); + const {children} = this.props; + return this.isSlotEmpty() ? Children.only(children) : null; } } IfSlotIsEmpty.propTypes = { slot: PropTypes.string, - className: PropTypes.string, }; const mapStateToProps = (state) => ({ diff --git a/client/coral-framework/components/IfSlotIsNotEmpty.js b/client/coral-framework/components/IfSlotIsNotEmpty.js index 4e3abfae4..46e68fe60 100644 --- a/client/coral-framework/components/IfSlotIsNotEmpty.js +++ b/client/coral-framework/components/IfSlotIsNotEmpty.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, {Children} from 'react'; import {connect} from 'react-redux'; import PropTypes from 'prop-types'; import omit from 'lodash/omit'; @@ -28,18 +28,13 @@ class IfSlotIsNotEmpty extends React.Component { } render() { - const {className, component: Component = 'div', children} = this.props; - return ( - - {this.isSlotEmpty() ? null : children} - - ); + const {children} = this.props; + return this.isSlotEmpty() ? null : Children.only(children); } } IfSlotIsNotEmpty.propTypes = { slot: PropTypes.string, - className: PropTypes.string, }; const mapStateToProps = (state) => ({ From 3b7d006d1e6939a4f01089eb26423de3e9e07cd5 Mon Sep 17 00:00:00 2001 From: Chi Vinh Le Date: Thu, 31 Aug 2017 16:59:04 +0700 Subject: [PATCH 3/3] Hide empty categories take 2 --- .../client/components/Category.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/talk-plugin-viewing-options/client/components/Category.js b/plugins/talk-plugin-viewing-options/client/components/Category.js index 184b5cadc..caa3904ff 100644 --- a/plugins/talk-plugin-viewing-options/client/components/Category.js +++ b/plugins/talk-plugin-viewing-options/client/components/Category.js @@ -1,12 +1,12 @@ import React from 'react'; import styles from './Category.css'; -import {Slot, IfSlotIsNotEmpty} from 'plugin-api/beta/client/components'; +import {Slot} from 'plugin-api/beta/client/components'; const childFactory = (child) =>
  • {child}
  • ; const ViewingOptions = ({slot, title, data, asset, root}) => { return ( - +
    {title}
    { data={data} queryData={{asset, root}} /> - +
    ); };