Skip to content

Commit

Permalink
Check if component is set at place id
Browse files Browse the repository at this point in the history
  • Loading branch information
aldipower committed Mar 10, 2016
1 parent 89d1f88 commit 4da21c8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/js/components/OptionalPortsAndServiceDiscoveryComponent.jsx
Expand Up @@ -7,6 +7,7 @@ import DuplicableRowsMixin from "../mixins/DuplicableRowsMixin";
import FormActions from "../actions/FormActions";
import FormGroupComponent from "../components/FormGroupComponent";
import PortInputAttributes from "../constants/PortInputAttributes";
import PluginComponentStore from "../stores/PluginComponentStore";
import PluginMountPointComponent from "../components/PluginMountPointComponent";
import PluginMountPoints from "../plugin/shared/PluginMountPoints";

Expand Down Expand Up @@ -233,13 +234,15 @@ var OptionalPortsAndServiceDiscoveryComponent = React.createClass({
);
},

getPortDefinitionRows: function () {
return (
<PluginMountPointComponent
placeId={PluginMountPoints.OPTIONAL_PORTS_AND_SERVICE_DISCOVERY} />
);
getPortDefinitionRows: function (hasPlaceIdSet = false) {
if (hasPlaceIdSet) {
return (
<PluginMountPointComponent
placeId={PluginMountPoints.OPTIONAL_PORTS_AND_SERVICE_DISCOVERY} />
);
}

var rows = this.state.rows[fieldsetId];
let rows = this.state.rows[fieldsetId];

if (rows == null) {
return null;
Expand All @@ -254,7 +257,11 @@ var OptionalPortsAndServiceDiscoveryComponent = React.createClass({
},

render: function () {
if (isTooComplexStructure(this.props.fields)) {
var hasPlaceIdSet = PluginComponentStore.hasComponentAtPlaceId(
PluginMountPoints.OPTIONAL_PORTS_AND_SERVICE_DISCOVERY
);

if (!hasPlaceIdSet && isTooComplexStructure(this.props.fields)) {
return (
<div>
Looks like your ports &amp; service discovery configuration
Expand All @@ -270,7 +277,7 @@ var OptionalPortsAndServiceDiscoveryComponent = React.createClass({
return (
<div>
<div className="duplicable-list">
{this.getPortDefinitionRows()}
{this.getPortDefinitionRows(hasPlaceIdSet)}
</div>
{this.getGeneralErrorBlock(fieldsetId)}
{this.getHelpText()}
Expand Down
4 changes: 4 additions & 0 deletions src/js/stores/PluginComponentStore.js
Expand Up @@ -12,6 +12,10 @@ var components = [];
var PluginComponentStore = Util.extendObject(EventEmitter.prototype, {
get components() {
return components;
},

hasComponentAtPlaceId: function (placeId) {
return components.some(component => component.placeId === placeId);
}
});

Expand Down

0 comments on commit 4da21c8

Please sign in to comment.