renderForm()

in addons/addon-base-raas-ui/packages/base-raas-ui/src/parts/environments-sc/parts/ScEnvironmentUpdateCidrs.js [160:262]


  renderForm() {
    const form = this.form;
    if (!form) {
      return null;
    }
    const fields = form.$('cidr');

    const anyWideCidr = () => {
      let wideCidrFound = false;
      _.forEach(this.ingressRules, rule => {
        if (!wideCidrFound)
          wideCidrFound = _.some(rule.cidrBlocks, cidr => {
            const parts = cidr.split('/');
            const suffixBits = parts[parts.length - 1];
            return suffixBits <= 16;
          });
      });
      return wideCidrFound;
    };

    const anyInvalidCidr = () => {
      let invalidCidrFound = false;
      _.forEach(this.ingressRules, rule => {
        if (!invalidCidrFound) invalidCidrFound = _.some(rule.cidrBlocks, cidr => IsCidr(cidr) !== 4);
      });
      return invalidCidrFound;
    };

    const validateMaxRStudioCidr = () => {
      let status = false;
      const envOutputs = this.environment.outputs;
      const metaConnection1Type = envOutputs.find(obj => obj.OutputKey === 'MetaConnection1Type');
      if (metaConnection1Type) {
        const productName = metaConnection1Type.OutputValue;
        if (productName === 'RStudioV2') {
          status = this.validateMaxCidrs;
        }
      }
      return status;
    };

    return (
      <Segment clearing className="p3 mb3">
        {fields.value.length === 0 && (
          <Message
            className="mb4"
            icon="warning"
            header="No Ingress Rules configured"
            content="The Security Group for this workspace does not contain any ingress rules configured in the Service Catalog product template"
          />
        )}
        <Form form={form} onCancel={this.handleCancel} onSuccess={this.handleSubmit}>
          {({ processing, onCancel }) => (
            <>
              <Table basic="very">
                <Table.Body>{fields.map((field, index) => this.renderItem(field, index, processing))}</Table.Body>
              </Table>
              {anyWideCidr() && (
                <Message
                  className="mb4"
                  icon="warning"
                  header="Wide CIDR block detected"
                  content="One or more CIDR blocks entered might be too wide and could allow workspace access to a vast number of IP ranges. Please proceed only after you ensure this is intended"
                />
              )}
              {anyInvalidCidr() && (
                <Message
                  negative
                  className="mb4"
                  icon="warning"
                  header="Unsupported or Invalid CIDR block detected"
                  content="One or more options entered are not valid IPv4 CIDR blocks. Please enter CIDR blocks in the format: '255.255.255.255/32'"
                />
              )}
              {validateMaxRStudioCidr() && (
                <Message
                  negative
                  className="mb4"
                  icon="warning"
                  header="Maximum limit CIDR reached"
                  content="You can set maximum number of 4 IPv4 CIDR in this blocks"
                />
              )}
              <Button
                className="ml2"
                size="mini"
                floated="right"
                color="blue"
                icon
                disabled={processing || anyInvalidCidr() || validateMaxRStudioCidr()}
                type="submit"
              >
                Submit
              </Button>
              <Button floated="right" size="mini" disabled={processing} onClick={onCancel}>
                Cancel
              </Button>
            </>
          )}
        </Form>
      </Segment>
    );
  }