mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-01-10 08:04:36 -06:00
764677431f
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
92 lines
2.5 KiB
JavaScript
92 lines
2.5 KiB
JavaScript
/////////////////////////////////////////////////////////////
|
|
//
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
//
|
|
// Copyright (C) 2013 - 2021, The pgAdmin Development Team
|
|
// This software is released under the PostgreSQL Licence
|
|
//
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
/* This is the base schema class for SchemaView.
|
|
* A UI schema must inherit this to use SchemaView for UI.
|
|
*/
|
|
export default class BaseUISchema {
|
|
constructor(defaults) {
|
|
/* Pass the initial data to constructor so that
|
|
they will set to defaults */
|
|
this._defaults = defaults;
|
|
|
|
this.keys = null; // If set, other fields except keys will be filtered
|
|
this.informText = null; // Inform text to show after save, this only saves it
|
|
this._top = null;
|
|
}
|
|
|
|
/* Top schema is helpful if this is used as child */
|
|
set top(val) {
|
|
this._top = val;
|
|
}
|
|
|
|
get top() {
|
|
/* If no top, I'm the top */
|
|
return this._top || this;
|
|
}
|
|
|
|
/* The original data before any changes */
|
|
set origData(val) {
|
|
this._origData = val;
|
|
}
|
|
|
|
get origData() {
|
|
return this._origData || {};
|
|
}
|
|
|
|
/* Property allows to restrict setting this later */
|
|
get defaults() {
|
|
return this._defaults || {};
|
|
}
|
|
|
|
/* ID key for the view state */
|
|
get idAttribute() {
|
|
return 'id';
|
|
}
|
|
|
|
/* Schema fields, to be defined by inherited UI schema. Override this */
|
|
get baseFields() {
|
|
throw new Error('Property method \'baseFields()\' must be implemented.');
|
|
}
|
|
|
|
/* Used by schema view component. Do not override this, it will
|
|
concat base fields with extraFields.
|
|
*/
|
|
get fields() {
|
|
/* Select only keys if specified */
|
|
return this.baseFields
|
|
.filter((field)=>this.keys ? this.keys.indexOf(field.id) > -1 : true);
|
|
}
|
|
|
|
/* Check if current data is new or existing */
|
|
isNew(state) {
|
|
if(_.has(state, this.idAttribute)) {
|
|
return _.isUndefined(state[this.idAttribute])
|
|
|| _.isNull(state[this.idAttribute]);
|
|
}
|
|
/* Nested collection rows may or may not have idAttribute.
|
|
So to decide whether row is new or not set, the cid starts with
|
|
nn (not new) for existing rows. Newly added will start with 'c' (created)
|
|
*/
|
|
if(_.has(state, 'cid')) {
|
|
return !state.cid.startsWith('nn');
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/* Called by SchemaView to validate data, return true indicates invalid.
|
|
validate will receive two params state and setError func
|
|
Eg - setError('fieldname', 'Some error').
|
|
And return true if invalid, otherwise false.
|
|
*/
|
|
validate() {
|
|
return false;
|
|
}
|
|
}
|