mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Added React framework for the properties dialog and port Server Group, Server, and Database dialogs.
Following changes done for the framework: - Framework for creating React based dynamic form view out of a pre-defined UI schema. Previously, it was based on Backform/Backbone. - The new framework and components will use MaterialUI as the base. Previously, Bootstrap/Backform/jQuery components were used. - The new code uses JSS instead of CSS since material UI and most modern React libraries also use JSS. In the future, this will allow us to change the theme in real-time without refresh. - 90% code covered by 80-85 new jasmine test cases. - Server group node UI Schema migration to new, with schema test cases. - Server node UI Schema migration to new, with schema test cases. - Database node UI Schema migration to new, with schema test cases. - Few other UI changes. Fixes #6130
This commit is contained in:
committed by
Akshay Joshi
parent
a10b0c7786
commit
764677431f
70
web/pgadmin/static/js/validators.js
Normal file
70
web/pgadmin/static/js/validators.js
Normal file
@@ -0,0 +1,70 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2021, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import {sprintf} from 'sources/utils';
|
||||
import _ from 'lodash';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
|
||||
/* Validate value for min max range */
|
||||
export function minMaxValidator(label, value, minValue, maxValue) {
|
||||
if((_.isUndefined(value) || _.isNull(value) || String(value) === ''))
|
||||
return null;
|
||||
if (!_.isUndefined(minValue) && value < minValue) {
|
||||
return sprintf(pgAdmin.Browser.messages.MUST_GR_EQ, label, minValue);
|
||||
} else if (!_.isUndefined(maxValue) && value > maxValue) {
|
||||
return sprintf(pgAdmin.Browser.messages.MUST_LESS_EQ, label, maxValue);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* Validate value to check if it is a number */
|
||||
export function numberValidator(label, value) {
|
||||
if((_.isUndefined(value) || _.isNull(value) || String(value) === ''))
|
||||
return null;
|
||||
var pattern = new RegExp('^-?[0-9]+(\.?[0-9]*)?$');
|
||||
if (!pattern.test(value)) {
|
||||
return sprintf(pgAdmin.Browser.messages.MUST_BE_NUM, label);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* Validate value to check if it is an integer */
|
||||
export function integerValidator(label, value) {
|
||||
if((_.isUndefined(value) || _.isNull(value) || String(value) === ''))
|
||||
return null;
|
||||
var pattern = new RegExp('^-?[0-9]*$');
|
||||
if (!pattern.test(value)) {
|
||||
return sprintf(pgAdmin.Browser.messages.MUST_BE_INT, label);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/* Validate value to check if it is empty */
|
||||
export function emptyValidator(label, value) {
|
||||
if(isEmptyString(value) || String(value).replace(/^\s+|\s+$/g, '') == '') {
|
||||
return sprintf(pgAdmin.Browser.messages.CANNOT_BE_EMPTY, label);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function isEmptyString(string) {
|
||||
return _.isUndefined(string) || _.isNull(string) || String(string).trim() === '';
|
||||
}
|
||||
|
||||
/* Validate rows to check for any duplicate rows based on uniqueCols-columns array */
|
||||
export function checkUniqueCol(rows, uniqueCols) {
|
||||
if(uniqueCols) {
|
||||
for(const [i, row] of rows.entries()) {
|
||||
for(const checkRow of rows.slice(0, i)) {
|
||||
if(_.isEqual(_.pick(checkRow, uniqueCols), _.pick(row, uniqueCols))) return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
Reference in New Issue
Block a user