PromucFlow_constructor/app/client/src/entities/Action/index.ts
Ayangade Adeoluwa c89346f1e0
fix: Don't show schema for schema-less plugins (#25460)
This PR hides schemas for actions of schema-less plugins in the query
editor.

Fixes #25413 

- Bug fix (non-breaking change which fixes an issue)

#### How Has This Been Tested?
> Please describe the tests that you ran to verify your changes. Also
list any relevant details for your test configuration.
> Delete anything that is not relevant
- [x] Manual
- [ ] Jest
- [x] Cypress
>
>
#### Test Plan
> Add Testsmith test cases links that relate to this PR
>
>
#### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
>
>
>
## Checklist:
#### Dev activity
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [x] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [x] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [x] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-07-24 12:18:20 +05:30

242 lines
5.7 KiB
TypeScript

import type { EmbeddedRestDatasource } from "entities/Datasource";
import type { DynamicPath } from "utils/DynamicBindingUtils";
import _ from "lodash";
import type { LayoutOnLoadActionErrors } from "constants/AppsmithActionConstants/ActionConstants";
import type { Plugin } from "api/PluginApi";
import type { AutoGeneratedHeader } from "pages/Editor/APIEditor/helpers";
export enum PluginType {
API = "API",
DB = "DB",
SAAS = "SAAS",
JS = "JS",
REMOTE = "REMOTE",
}
export enum PluginPackageName {
POSTGRES = "postgres-plugin",
MONGO = "mongo-plugin",
S3 = "amazons3-plugin",
GOOGLE_SHEETS = "google-sheets-plugin",
FIRESTORE = "firestore-plugin",
REST_API = "restapi-plugin",
GRAPHQL = "graphql-plugin",
JS = "js-plugin",
ORACLE = "oracle-plugin",
MY_SQL = "mysql-plugin",
MS_SQL = "mssql-plugin",
SNOWFLAKE = "snowflake-plugin",
}
// more can be added subsequently.
export enum PluginName {
MONGO = "MongoDB",
POSTGRES = "PostgreSQL",
MY_SQL = "MySQL",
MS_SQL = "Microsoft SQL Server",
GOOGLE_SHEETS = "Google Sheets",
FIRESTORE = "Firestore",
ORACLE = "Oracle",
SNOWFLAKE = "Snowflake",
ARANGODB = "ArangoDB",
REDSHIFT = "Redshift",
SMTP = "SMTP",
REST_API = "REST API",
REDIS = "Redis",
AIRTABLE = "Airtable",
TWILIO = "Twilio",
HUBSPOT = "HubSpot",
ELASTIC_SEARCH = "Elasticsearch",
GRAPHQL = "Authenticated GraphQL API",
}
export enum PaginationType {
NONE = "NONE",
PAGE_NO = "PAGE_NO",
URL = "URL",
CURSOR = "CURSOR",
}
export interface KeyValuePair {
key?: string;
value?: unknown;
}
export type LimitOffset = {
limit: Record<string, unknown>;
offset: Record<string, unknown>;
};
export interface SelfReferencingData {
limitBased?: LimitOffset;
curserBased?: {
previous?: LimitOffset;
next?: LimitOffset;
};
}
export interface ActionConfig {
timeoutInMillisecond?: number;
paginationType?: PaginationType;
formData?: Record<string, unknown>;
pluginSpecifiedTemplates?: KeyValuePair[];
path?: string;
queryParameters?: KeyValuePair[];
selfReferencingData?: SelfReferencingData;
}
export interface ActionProvider {
name: string;
imageUrl: string;
url: string;
description: string;
credentialSteps: string;
}
export interface Property {
key: string;
value: string;
}
export interface BodyFormData {
editable: boolean;
mandatory: boolean;
description: string;
key: string;
value?: string;
type: string;
}
export interface ApiActionConfig extends Omit<ActionConfig, "formData"> {
headers: Property[];
autoGeneratedHeaders?: AutoGeneratedHeader[];
httpMethod: string;
path?: string;
body?: JSON | string | Record<string, any> | null;
encodeParamsToggle: boolean;
queryParameters?: Property[];
bodyFormData?: BodyFormData[];
formData: Record<string, unknown>;
query?: string | null;
variable?: string | null;
}
export interface QueryActionConfig extends ActionConfig {
body?: string;
}
export const isStoredDatasource = (val: any): val is StoredDatasource => {
if (!_.isObject(val)) return false;
if (!("id" in val)) return false;
return true;
};
export interface StoredDatasource {
name?: string;
id: string;
pluginId?: string;
datasourceConfiguration?: { url?: string };
}
export interface BaseAction {
id: string;
name: string;
workspaceId: string;
pageId: string;
collectionId?: string;
pluginId: string;
executeOnLoad: boolean;
dynamicBindingPathList: DynamicPath[];
isValid: boolean;
invalids: string[];
jsonPathKeys: string[];
cacheResponse: string;
confirmBeforeExecute?: boolean;
eventData?: any;
messages: string[];
userPermissions?: string[];
errorReports?: Array<LayoutOnLoadActionErrors>;
}
interface BaseApiAction extends BaseAction {
pluginType: PluginType.API;
actionConfiguration: ApiActionConfig;
}
export interface SaaSAction extends BaseAction {
pluginType: PluginType.SAAS;
actionConfiguration: any;
datasource: StoredDatasource;
}
export interface RemoteAction extends BaseAction {
pluginType: PluginType.REMOTE;
actionConfiguration: any;
datasource: StoredDatasource;
}
export interface EmbeddedApiAction extends BaseApiAction {
datasource: EmbeddedRestDatasource;
}
export interface StoredDatasourceApiAction extends BaseApiAction {
datasource: StoredDatasource;
}
export type ApiAction = EmbeddedApiAction | StoredDatasourceApiAction;
export type RapidApiAction = ApiAction & {
templateId: string;
proverId: string;
provider: ActionProvider;
pluginId: string;
documentation: { text: string };
};
export interface QueryAction extends BaseAction {
pluginType: PluginType.DB;
pluginName?: PluginName;
actionConfiguration: QueryActionConfig;
datasource: StoredDatasource;
}
export type ActionViewMode = {
id: string;
name: string;
pageId: string;
jsonPathKeys: string[];
confirmBeforeExecute?: boolean;
timeoutInMillisecond?: number;
};
export type Action = ApiAction | QueryAction | SaaSAction | RemoteAction;
export enum SlashCommand {
NEW_API,
NEW_QUERY,
NEW_INTEGRATION,
ASK_AI,
}
export type SlashCommandPayload = {
actionType: SlashCommand;
callback?: (binding: string) => void;
args: any;
};
export function isAPIAction(action: Action): action is ApiAction {
return action.pluginType === PluginType.API;
}
export function isQueryAction(action: Action): action is QueryAction {
return action.pluginType === PluginType.DB;
}
export function isSaaSAction(action: Action): action is SaaSAction {
return action.pluginType === PluginType.SAAS;
}
export function getGraphQLPlugin(plugins: Plugin[]): Plugin | undefined {
return plugins.find((p) => p.packageName === PluginPackageName.GRAPHQL);
}
export function isGraphqlPlugin(plugin: Plugin | undefined) {
return plugin?.packageName === PluginPackageName.GRAPHQL;
}