fix custom functions console bugs (close #1548, #1549) (#1552)

This commit is contained in:
Karthik Venkateswaran 2019-02-06 22:00:57 +05:30 committed by Rikin Kachhia
parent 4bf9d19b13
commit 39982d459a
3 changed files with 39 additions and 19 deletions

View File

@ -2,7 +2,7 @@ import React from 'react';
import Helmet from 'react-helmet';
import CommonTabLayout from '../../../Layout/CommonTabLayout/CommonTabLayout';
import { Link } from 'react-router';
// import { Link } from 'react-router';
import { push } from 'react-router-redux';
import { pageTitle, appPrefix } from '../Modify/constants';
@ -16,11 +16,13 @@ import { fetchCustomFunction } from '../customFunctionReducer';
class Permission extends React.Component {
componentDidMount() {
const { functionName } = this.props.params;
const { functionName, schema } = this.props.params;
if (!functionName) {
this.props.dispatch(push(prefixUrl));
}
Promise.all([this.props.dispatch(fetchCustomFunction(functionName))]);
Promise.all([
this.props.dispatch(fetchCustomFunction(functionName, schema)),
]);
}
render() {
const styles = require('../Modify/ModifyCustomFunction.scss');
@ -28,9 +30,11 @@ class Permission extends React.Component {
functionSchema: schema,
functionName,
setOffTable,
setOffTableSchema,
} = this.props.functions;
const baseUrl = `${appPrefix}/schema/${schema}/functions/${functionName}`;
const permissionTableUrl = `${appPrefix}/schema/${schema}/tables/${setOffTable}/permissions`;
const permissionTableUrl = `${prefixUrl}/schema/${setOffTableSchema}/tables/${setOffTable}/permissions`;
const breadCrumbs = [
{
@ -78,14 +82,14 @@ class Permission extends React.Component {
applicable to the data returned by this function
</p>
<div className={styles.commonBtn}>
<Link to={permissionTableUrl}>
<a href={permissionTableUrl}>
<button
className={styles.yellow_button}
data-test={'custom-function-permission-btn'}
>
{`${setOffTable} Permissions`}
</button>
</Link>
</a>
</div>
</div>
);

View File

@ -170,17 +170,25 @@ const fetchCustomFunction = (functionName, schema) => {
const deleteFunctionSql = () => {
return (dispatch, getState) => {
const currentSchema = getState().tables.currentSchema;
const functionName = getState().functions.functionName;
const functionDefinition = getState().functions.functionDefinition;
const sqlDropFunction =
'DROP FUNCTION ' +
'"' +
currentSchema +
'"' +
'.' +
'"' +
functionName +
'"';
const {
functionName,
functionDefinition,
inputArgTypes,
} = getState().functions;
let functionWSchemaName =
'"' + currentSchema + '"' + '.' + '"' + functionName + '"';
if (inputArgTypes.length > 0) {
let functionString = '(';
inputArgTypes.forEach((i, index) => {
functionString +=
i + ' ' + (index === inputArgTypes.length - 1 ? ')' : ',');
});
functionWSchemaName += functionString;
}
const sqlDropFunction = 'DROP FUNCTION ' + functionWSchemaName;
const sqlUpQueries = [
{
type: 'run_sql',
@ -203,9 +211,11 @@ const deleteFunctionSql = () => {
const errorMsg = 'Deleting function failed';
const customOnSuccess = () => {
dispatch(_push('/'));
dispatch(_push(`/schema/${currentSchema}`));
};
const customOnError = () => {
dispatch({ type: DELETE_CUSTOM_FUNCTION_FAIL });
};
const customOnError = () => {};
dispatch({ type: DELETING_CUSTOM_FUNCTION });
return dispatch(
@ -318,6 +328,9 @@ const customFunctionReducer = (state = functionData, action) => {
functionSchema: action.data[0][0].function_schema || null,
functionDefinition: action.data[1][0].function_definition || null,
setOffTable: action.data[1][0].return_type_name || null,
setOffTableSchema: action.data[1][0].return_type_schema || null,
inputArgNames: action.data[1][0].input_arg_names || null,
inputArgTypes: action.data[1][0].input_arg_types || null,
isFetching: false,
isFetchError: null,
};

View File

@ -12,6 +12,9 @@ const functionData = {
functionSchema: '',
functionDefinition: '',
setOffTable: '',
setOffTableSchema: '',
inputArgNames: [],
inputArgTypes: [],
...asyncState,
};