console: filter custom functions with table args from "Untracked custom functions" list (close #6438)

GitOrigin-RevId: c4bb6950872ff2e75054cb64ce7f91fb68de0767
This commit is contained in:
Vijay Prasanna 2021-02-01 20:32:01 +05:30 committed by hasura-bot
parent 94a886ee94
commit 52aa55904b
3 changed files with 35 additions and 15 deletions

View File

@ -50,6 +50,7 @@ import {
} from '../../../../metadata/selector';
import { RightContainer } from '../../../Common/Layout/RightContainer';
import { TrackableFunctionsList } from './FunctionsList';
import { getTrackableFunctions } from './utils';
const DeleteSchemaButton = ({ dispatch, migrationMode, currentDataSource }) => {
const successCb = () => {
@ -264,18 +265,6 @@ class Schema extends Component {
dispatch(updateCurrentSchema(e.target.value, currentDataSource));
};
const _getTrackableFunctions = () => {
const trackedFuncNames = trackedFunctions.map(fn => fn.function_name);
// Assuming schema for both function and tables are same
// return function which are tracked
const filterCondition = func => {
return !trackedFuncNames.includes(func.function_name);
};
return functionsList.filter(filterCondition);
};
const getSectionHeading = (headingText, tooltip, actionElement = null) => {
return (
<div>
@ -293,8 +282,11 @@ class Schema extends Component {
const allUntrackedTables = getUntrackedTables(
getSchemaTables(schema, currentSchema)
);
const trackableFuncs = _getTrackableFunctions();
const trackableFuncs = getTrackableFunctions(
functionsList,
trackedFunctions
);
const getCreateBtn = () => {
let createBtn = null;

View File

@ -0,0 +1,23 @@
import {
ArgType,
PGFunction,
PGInputArgType,
} from '../../../../dataSources/services/postgresql/types';
export const getTrackableFunctions = (
functionsList: PGFunction[],
trackedFunctions: PGFunction[]
): PGFunction[] => {
const trackedFuncNames = trackedFunctions.map(fn => fn.function_name);
const containsTableArgs = (arg: PGInputArgType): boolean =>
arg.type.toLowerCase() === ArgType.CompositeType;
// Assuming schema for both function and tables are same
// return function which are tracked
const filterCondition = (func: PGFunction) => {
return (
!trackedFuncNames.includes(func.function_name) &&
!func.input_arg_types?.some(containsTableArgs)
);
};
return functionsList.filter(filterCondition);
};

View File

@ -1,7 +1,7 @@
export type PGInputArgType = {
schema: string;
name: string;
type: string;
type: ArgType;
};
export type PGFunction = {
@ -57,11 +57,16 @@ export interface PostgresTrigger {
event_manipulation: string;
}
type InputArgType = {
export type InputArgType = {
schema: string;
name: string;
};
export enum ArgType {
CompositeType = 'c',
BaseType = 'b',
}
export interface FunctionState {
functionName: string;
inputArgTypes: InputArgType[];