From bc6697a879710aeb2603584d780d61efe434bdb4 Mon Sep 17 00:00:00 2001 From: Ran Byron Date: Thu, 19 Sep 2019 21:11:39 +0300 Subject: [PATCH] Alert redesign #3 - Destinations single pane mode --- client/app/components/SelectItemsDialog.jsx | 67 ++++++++++++------- .../app/components/groups/ListItemAddon.jsx | 8 ++- .../alert/components/AlertDestinations.jsx | 23 ++++--- .../alert/components/AlertDestinations.less | 9 +++ 4 files changed, 68 insertions(+), 39 deletions(-) diff --git a/client/app/components/SelectItemsDialog.jsx b/client/app/components/SelectItemsDialog.jsx index df4be5e109..f54dc27773 100644 --- a/client/app/components/SelectItemsDialog.jsx +++ b/client/app/components/SelectItemsDialog.jsx @@ -1,10 +1,11 @@ -import { filter, debounce, find } from 'lodash'; +import { filter, debounce, find, isEmpty, size } from 'lodash'; import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import Modal from 'antd/lib/modal'; import Input from 'antd/lib/input'; import List from 'antd/lib/list'; +import Button from 'antd/lib/button'; import { wrap as wrapDialog, DialogPropType } from '@/components/DialogWrapper'; import { BigMessage } from '@/components/BigMessage'; @@ -29,6 +30,9 @@ class SelectItemsDialog extends React.Component { // right list; args/results save as for `renderItem`. if not specified - `renderItem` will be used renderStagedItem: PropTypes.func, save: PropTypes.func, // (selectedItems[]) => Promise + width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), + extraFooterContent: PropTypes.node, + showCount: PropTypes.bool, }; static defaultProps = { @@ -37,8 +41,11 @@ class SelectItemsDialog extends React.Component { selectedItemsTitle: 'Selected items', itemKey: item => item.id, renderItem: () => '', - renderStagedItem: null, // use `renderItem` by default + renderStagedItem: null, // hidden by default save: items => items, + width: '80%', + extraFooterContent: null, + showCount: false, }; state = { @@ -108,7 +115,7 @@ class SelectItemsDialog extends React.Component { renderItem(item, isStagedList) { const { renderItem, renderStagedItem } = this.props; const isSelected = this.isSelected(item); - const render = isStagedList ? (renderStagedItem || renderItem) : renderItem; + const render = isStagedList ? renderStagedItem : renderItem; const { content, className, isDisabled } = render(item, { isSelected }); @@ -123,23 +130,29 @@ class SelectItemsDialog extends React.Component { } render() { - const { dialog, dialogTitle, inputPlaceholder, selectedItemsTitle } = this.props; + const { dialog, dialogTitle, inputPlaceholder } = this.props; + const { selectedItemsTitle, renderStagedItem, width, showCount } = this.props; const { loading, saveInProgress, items, selected } = this.state; const hasResults = items.length > 0; return ( this.save()} + footer={( +
+ {this.props.extraFooterContent} + + +
+ )} >
-
+
this.search(event.target.value)} @@ -147,13 +160,15 @@ class SelectItemsDialog extends React.Component { autoFocus />
-
-
{selectedItemsTitle}
-
+ {renderStagedItem && ( +
+
{selectedItemsTitle}
+
+ )}
-
+
{loading && } {!loading && !hasResults && ( @@ -166,15 +181,17 @@ class SelectItemsDialog extends React.Component { /> )}
-
- {(selected.length > 0) && ( - this.renderItem(item, true)} - /> - )} -
+ {renderStagedItem && ( +
+ {(selected.length > 0) && ( + this.renderItem(item, true)} + /> + )} +
+ )}
); diff --git a/client/app/components/groups/ListItemAddon.jsx b/client/app/components/groups/ListItemAddon.jsx index ec4fd22ade..53a9f0b525 100644 --- a/client/app/components/groups/ListItemAddon.jsx +++ b/client/app/components/groups/ListItemAddon.jsx @@ -2,24 +2,26 @@ import React from 'react'; import PropTypes from 'prop-types'; import Tooltip from 'antd/lib/tooltip'; -export default function ListItemAddon({ isSelected, isStaged, alreadyInGroup }) { +export default function ListItemAddon({ isSelected, isStaged, alreadyInGroup, deselectedIcon }) { if (isStaged) { return ; } if (alreadyInGroup) { - return ; + return ; } - return isSelected ? : ; + return isSelected ? : ; } ListItemAddon.propTypes = { isSelected: PropTypes.bool, isStaged: PropTypes.bool, alreadyInGroup: PropTypes.bool, + deselectedIcon: PropTypes.string, }; ListItemAddon.defaultProps = { isSelected: false, isStaged: false, alreadyInGroup: false, + deselectedIcon: 'fa-angle-double-right', }; diff --git a/client/app/pages/alert/components/AlertDestinations.jsx b/client/app/pages/alert/components/AlertDestinations.jsx index 679b752d9a..37dc659d6b 100644 --- a/client/app/pages/alert/components/AlertDestinations.jsx +++ b/client/app/pages/alert/components/AlertDestinations.jsx @@ -85,8 +85,18 @@ export default class AlertDestinations extends React.Component { const { dests, subs } = this.state; SelectItemsDialog.showModal({ + width: 570, + showCount: true, + extraFooterContent: ( + <> + {' '} + Create new destinations in{' '} + + Alert Destinations + + + ), dialogTitle: 'Add Existing Alert Destinations', - selectedItemsTitle: 'Pending Destinations', inputPlaceholder: 'Search destinations...', searchItems: (searchTerm) => { searchTerm = searchTerm.toLowerCase(); @@ -101,22 +111,13 @@ export default class AlertDestinations extends React.Component {
{name} {item.name} - +
), isDisabled: alreadyInGroup, className: isSelected || alreadyInGroup ? 'selected' : '', }; }, - renderStagedItem: item => ({ - content: ( -
- {name} - {item.name} - -
- ), - }), save: (items) => { const promises = map(items, item => this.subscribe(item)); return Promise.all(promises).then(() => { diff --git a/client/app/pages/alert/components/AlertDestinations.less b/client/app/pages/alert/components/AlertDestinations.less index f091e01cd8..54e0b4f6a0 100644 --- a/client/app/pages/alert/components/AlertDestinations.less +++ b/client/app/pages/alert/components/AlertDestinations.less @@ -46,6 +46,10 @@ min-height: 38px; width: 100%; + .select-items-dialog & { + padding: 0; + } + .destination-icon { height: 25px; width: 25px; @@ -58,5 +62,10 @@ justify-content: center; font-size: 12px; } + + .select-items-dialog & { + width: 35px; + height: 35px; + } } }