Skip to content

Commit

Permalink
Only allow "create feature above" when features are adjacent
Browse files Browse the repository at this point in the history
  • Loading branch information
ekuiter committed Aug 25, 2018
1 parent 012ee18 commit 32418df
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ deploy:
on:
repo: ekuiter/variED
tags: true
all_branches: true
api_key:
secure: l5Agcx9m6DJOMKr9o703gE9mIjcr+zI9iITUhaFoNw/fwpZRm1bvKgitlpfq83e7pzw8TAZdRPIL9WQRbvVRhpx/F4lEn5lF94tJJnrvhKjYolnw/UyZ9E8vgecYtYI15fEBeRwLyQQaSrtYD5XWCUEYVo5p0OJf+yTZoN+67ck1bsjeRICxSsvAl1GQySYvGj2teLe3euqpuFrv51VvCjubiCM0H7aperxJtJdXbJ1H9vCvylcnzn/SZp3hlOm455rooVPVZHHt7Ra4oF9SZn6nwXMpPdLpbnTWNNpbm0GTGxCgQ+KROeGRjx6O2JmnCC2V3Ql6ard+1luyuu9Dfwr6G/uFjBPLBEdSz2O24yogAh/sgzs8Rdt9HL/Wf0nSmLuRM83zKIROFWmdoic7VqRtwkd6sACBj9DxgtKob7IKYe7PWIgJzAiux8kQIbe2vZuNmzBcWbeCfa0NNhgpH4f45l5uHTIOESxYsLlAbFakyNMHkJ6sfDhA3GsUq/ztm4KcUxORyVfiRALNksErYCBE3jU+4dBAbQz5Vd+UbEZ53mE1p4SYOgvOJjmSd4Qm/HCvrYjb+Sw+F71w7uF5YQQnJT5I7VB3eEYVYoYO0B0724elbUB+DA/dNlNQpDiCdydfo1mTuQ7dqhDEZgMxWraLuf2mtxMFu/sNFf7DnS8=
- provider: heroku
Expand Down
27 changes: 19 additions & 8 deletions client/src/components/contextualMenuItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ const contextualMenuItems = {
}
}),
selection: (isSelectMultipleFeatures, onSetSelectMultipleFeatures,
selectedFeatures, onSelectAllFeatures, onDeselectAllFeatures) => ({
selectedFeatures, onSelectAllFeatures, onDeselectAllFeatures, featureModel) => ({
key: 'selection',
text: i18n.t('featureDiagram.commands.selection')(isSelectMultipleFeatures, selectedFeatures),
onClick: () => onSetSelectMultipleFeatures(!isSelectMultipleFeatures), // TODO: tell the user he can choose features now
subMenuProps: isSelectMultipleFeatures
? {
items: selectMultipleFeaturesContextualMenuItems(
selectedFeatures, onSelectAllFeatures, onDeselectAllFeatures)
selectedFeatures, onSelectAllFeatures, onDeselectAllFeatures, featureModel)
}
: null
}),
Expand Down Expand Up @@ -112,12 +112,23 @@ const contextualMenuItems = {
text: i18n.t('featureDiagram.commands.features.deselectAll'),
onClick: onDeselectAll
}),
newFeatureAbove: (featureNames, onClick) => ({
key: 'featureAbove',
text: i18n.t('featureDiagram.commands.features.newFeatureAbove'),
iconProps: {iconName: 'Add'},
onClick: () => actions.server.featureAddAbove(featureNames).then(onClick)
})
newFeatureAbove: (featureNames, onClick, featureModel) => {
let disabled = false;
if (featureNames.length === 0)
disabled = true;
else if (featureNames.length > 1) {
if (!featureModel)
throw new Error('no feature model given');
disabled = !featureModel.isSiblingFeatures(featureNames);
}
return ({
key: 'featureAbove',
text: i18n.t('featureDiagram.commands.features.newFeatureAbove'),
iconProps: {iconName: 'Add'},
disabled,
onClick: () => actions.server.featureAddAbove(featureNames).then(onClick)
});
}
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ class AbstractTreeLayout extends React.Component {
onShowDialog={this.onShowDialog}
onDismiss={this.onHideOverlay}
onSelectAllFeatures={this.props.onSelectAllFeatures}
onDeselectAllFeatures={this.props.onDeselectAllFeatures}/>
onDeselectAllFeatures={this.props.onDeselectAllFeatures}
featureModel={this.props.featureModel}/>
</React.Fragment>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import {ContextualMenu, ContextualMenuItemType} from 'office-ui-fabric-react/lib
import contextualMenuItems from '../../contextualMenuItems';
import {getSetting} from '../../../store/settings';

export const selectMultipleFeaturesContextualMenuItems = (selectedFeatures, onSelectAllFeatures, onDeselectAllFeatures) => [
export const selectMultipleFeaturesContextualMenuItems = (selectedFeatures, onSelectAllFeatures, onDeselectAllFeatures, featureModel) => [
contextualMenuItems.featureDiagram.features.selectAll(onSelectAllFeatures),
contextualMenuItems.featureDiagram.features.deselectAll(onDeselectAllFeatures),
{key: 'divider1', itemType: ContextualMenuItemType.Divider},
contextualMenuItems.featureDiagram.features.newFeatureAbove(selectedFeatures, onDeselectAllFeatures)
contextualMenuItems.featureDiagram.features.newFeatureAbove(selectedFeatures, onDeselectAllFeatures, featureModel)
];

export default props => {
const {onDismiss, onSelectAllFeatures, onDeselectAllFeatures, isSelectMultipleFeatures, selectedFeatures} = props,
const {onDismiss, onSelectAllFeatures, onDeselectAllFeatures, isSelectMultipleFeatures, selectedFeatures, featureModel} = props,
{gapSpace} = getSetting(props.settings, 'featureDiagram.treeLayout.overlay'),
feature = props.node && props.node.feature();
if (!feature)
Expand All @@ -30,7 +30,7 @@ export default props => {
: DirectionalHint.rightCenter}
items={isSelectMultipleFeatures
? selectMultipleFeaturesContextualMenuItems(
selectedFeatures, onSelectAllFeatures, onDeselectAllFeatures)
selectedFeatures, onSelectAllFeatures, onDeselectAllFeatures, featureModel)
: [
contextualMenuItems.featureDiagram.feature.new(feature.name, onDismiss),
contextualMenuItems.featureDiagram.feature.remove(feature.name, onDismiss),
Expand Down
7 changes: 5 additions & 2 deletions client/src/containers/AppContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import DialogContainer from './dialogs/DialogContainer';
import withKeys from '../helpers/withKeys';
import defer from '../helpers/defer';
import EndpointFacepile from '../components/EndpointFacepile';
import {getFeatureModel} from '../store/selectors';

class AppContainer extends React.Component {
componentDidMount() {
Expand All @@ -35,7 +36,8 @@ class AppContainer extends React.Component {
this.props.onSetSelectMultipleFeatures,
this.props.selectedFeatures,
this.props.onSelectAllFeatures,
this.props.onDeselectAllFeatures)
this.props.onDeselectAllFeatures,
this.props.featureModel)
]}
farItems={[
{
Expand Down Expand Up @@ -64,7 +66,8 @@ export default connect(
isSelectMultipleFeatures: state.ui.isSelectMultipleFeatures,
selectedFeatures: state.ui.selectedFeatures,
endpoints: state.server.endpoints,
settings: state.settings
settings: state.settings,
featureModel: getFeatureModel(state)
}),
dispatch => ({
handleMessage: dispatch,
Expand Down
5 changes: 5 additions & 0 deletions client/src/server/FeatureModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,9 @@ export default class FeatureModel {
getFeatureNames() {
return this.hierarchy.descendants().map(node => node.feature().name);
}

isSiblingFeatures(featureNames) {
const parents = featureNames.map(this.getNode.bind(this)).map(node => node.parent);
return parents.every(parent => parent === parents[0]);
}
};

0 comments on commit 32418df

Please sign in to comment.