Skip to content

fixing validation around the model to have better messages #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions electron/app/locales/en/webui.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
"model-design-button-startWebLogicRemoteConsole": "Start WebLogic Remote Console",
"model-design-hints-startWebLogicRemoteConsole": "Start the WebLogic Remote Console backend process",

"model-code-form-name": "Code View tab of the Model",
"image-page-hints-createImage": "Create Primary Image",
"image-page-button-createImage": "Create Primary Image",
"image-page-hints-pushImage": "Push Primary Image to Registry",
Expand Down Expand Up @@ -1082,7 +1083,7 @@
"model-page-hints-validateModel": "Validate Model Files",
"model-page-button-prepareModel": "Prepare Model",
"model-page-hints-prepareModel": "Prepare Model for Kubernetes",
"model-page-model-editor-contents": "Model Editor Contents",
"model-page-model-editor-contents": "Model Editor",

"model-properties-table-aria-label": "Model Variables Editable Table",
"model-properties-name-header": "Variable Name",
Expand Down Expand Up @@ -1351,7 +1352,8 @@
"validation-helper-form-tab-and-field-name-message": "The {{fieldName}} field on the {{tabName}} tab of the {{formName}} page is invalid:",
"validation-helper-form-tab-sub-tab-and-field-name-message": "The {{fieldName}} field on the {{tabName}}->{{subTabName}} tab of the {{formName}} page is invalid:",
"validation-helper-validate-field-value-is-not-defined": "The field is required but its value is not defined.",
"validation-helper-validate-string-field-value-is-empty": "The field is required but its value contained no non-whitespace characters.",
"validation-helper-validate-string-field-value-is-empty": "The field is required but its value was empty.",
"validation-helper-validate-string-field-value-is-only-whitespace": "The field is required but its value contained no non-whitespace characters.",
"validation-helper-validate-array-field-value-is-empty": "The field is required but the list is empty.",
"validation-helper-field-error-message": "The {{fieldName}} field is invalid: {{error}}",
"validation-helper-form-and-field-error-message": "The {{fieldName}} field on the {{formName}} page is invalid: {{error}}",
Expand Down
2 changes: 1 addition & 1 deletion webui/src/js/models/wdt-model-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ define(['knockout', 'utils/observable-properties', 'js-yaml', 'utils/validation-
this.validateModel = (isRequired = true) => {
let errors = [];
if (isRequired) {
const emptyFieldError = validationHelper.validateRequiredField(this.modelContent());
const emptyFieldError = validationHelper.validateRequiredFieldContainsNonWhitespaceCharacters(this.modelContent());
if (emptyFieldError) {
errors.push(emptyFieldError);
} else {
Expand Down
18 changes: 18 additions & 0 deletions webui/src/js/utils/validation-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ function(i18n, Validator, ojvalidationError, RegExpValidator, LengthValidator, N
return _validateRequiredFieldValue(currentValue);
};

this.validateRequiredFieldContainsNonWhitespaceCharacters = (currentValue) => {
return _validateRequiredFieldValueContainsNonWhitespaceCharacters(currentValue);
};

this.getRequiredFieldValidators = () => {
return [
{
Expand Down Expand Up @@ -349,6 +353,20 @@ function(i18n, Validator, ojvalidationError, RegExpValidator, LengthValidator, N
return requiredMessage;
}

function _validateRequiredFieldValueContainsNonWhitespaceCharacters(value) {
let nonWhiteSpaceRegex = /\w+/g;

let requiredMessage;
if (value === undefined || value === null) {
requiredMessage = i18n.t('validation-helper-validate-field-value-is-not-defined');
} else if (value === '') {
requiredMessage = i18n.t('validation-helper-validate-string-field-value-is-empty');
} else if (!value.match(nonWhiteSpaceRegex)) {
requiredMessage = i18n.t('validation-helper-validate-string-field-value-is-only-whitespace');
}
return requiredMessage;
}

const K8S_CPU_REGEX = [ /^[1-9]\d*[Mm]?$/, /^\d+(\.\d{1,3})?$/, /^0\.\d{1,3}$/ ];
const K8S_CPU_HELP_URL = 'https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/#meaning-of-cpu';
function _validateK8sCpuValue(value) {
Expand Down
2 changes: 1 addition & 1 deletion webui/src/js/utils/wdt-actions-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ define(['utils/wkt-actions-base', 'utils/validation-helper', 'utils/dialog-helpe
validationHelper.validateRequiredField(this.project.settings.oracleHome.value), settingsFormConfig);

const modelFormConfig = validationObject.getDefaultConfigObject();
modelFormConfig.formName = 'model-design-form-name';
modelFormConfig.formName = 'model-code-form-name';
validationObject.addField('model-page-model-editor-contents',
this.project.wdtModel.validateModel(true), modelFormConfig);

Expand Down