Port preferences dialog to React. Fixes #7149

This commit is contained in:
Nikhil Mohite
2022-03-21 13:29:26 +05:30
committed by Akshay Joshi
parent 3299b0c1b0
commit 74e794b416
65 changed files with 2646 additions and 1006 deletions

View File

@@ -0,0 +1,71 @@
/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2022, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
import gettext from 'sources/gettext';
import _ from 'lodash';
import url_for from 'sources/url_for';
import BaseUISchema from 'sources/SchemaView/base_schema.ui';
import getApiInstance from '../../../../../static/js/api_instance';
import Notify from '../../../../../static/js/helpers/Notifier';
export function getBinaryPathSchema() {
return new BinaryPathSchema();
}
export default class BinaryPathSchema extends BaseUISchema {
constructor() {
super({
isDefault: false,
serverType: undefined,
binaryPath: null,
});
}
get baseFields() {
return [
{
id: 'isDefault', label: gettext('Set as default'), type: 'radio',
width: 32,
radioType: true,
disabled: function (state) {
return state?.binaryPath && state?.binaryPath.length > 0 ? false : true;
},
cell: 'radio',
deps: ['binaryPath'],
},
{
id: 'serverType',
label: gettext('Database Server'),
type: 'text', cell: '',
width: 40,
},
{
id: 'binaryPath', label: gettext('Binary Path'), cell: 'file', type: 'file',
isvalidate: true, controlProps: { dialogType: 'select_folder', supportedTypes: ['*', 'sql', 'backup'], dialogTitle: 'Select folder' },
validate: (data) => {
const api = getApiInstance();
if (_.isNull(data) || data.trim() === '') {
Notify.alert(gettext('Validate Path'), gettext('Path should not be empty.'));
} else {
api.post(url_for('misc.validate_binary_path'),
JSON.stringify({ 'utility_path': data }))
.then(function (res) {
Notify.alert(gettext('Validate binary path'), gettext(res.data.data));
})
.catch(function (error) {
Notify.pgNotifier(error, gettext('Failed to validate binary path.'));
});
}
return true;
}
},
];
}
}