PromucFlow_constructor/app/client/src/api/PluginApi.ts
Ayush Pahwa 813d5850b0
fix: Update api params for dynamic fetched values (#11463)
* <feat> Updated payload for formEvals

- Added datasource and plugin ID to the payload

* <feat> Added IDs to dispatch calls

- Added datasource and plugin IDs to the dispatch calls so they can be used for dynamic query fetch

* <feat> Added type in evaluation saga

- Added datasource ID and plugin ID in the expected type for the eval function
- Updated call type from GET to POST for the dynamic trigger URLs

* <feat> Made params compulsory for editor config

- Params are now compulsory for any config defined in editor JSON for the dynamic value fetching

* <feat> Updated API definition

- Update the definition for the axios function from GET to POST

* <feat> Added configProperty to payload

- Added configProperty to the payload to allow for distinction between different components making a call to the server

* <chroe> Added null check

- Added null check to function call for datasource and plugin IDs in API since they are not compulsory in the type

* <refactor> Remove unused imports
2022-02-27 03:32:36 +00:00

70 lines
1.9 KiB
TypeScript

import Api from "api/Api";
import { AxiosPromise } from "axios";
import { GenericApiResponse } from "api/ApiResponses";
import { PluginType } from "entities/Action";
import { DependencyMap } from "utils/DynamicBindingUtils";
import { DropdownOption } from "components/ads/Dropdown";
export type PluginId = string;
export type PluginPackageName = string;
export type GenerateCRUDEnabledPluginMap = Record<PluginId, PluginPackageName>;
export enum UIComponentTypes {
DbEditorForm = "DbEditorForm",
UQIDbEditorForm = "UQIDbEditorForm",
ApiEditorForm = "ApiEditorForm",
RapidApiEditorForm = "RapidApiEditorForm",
JsEditorForm = "JsEditorForm",
}
export enum DatasourceComponentTypes {
RestAPIDatasourceForm = "RestAPIDatasourceForm",
AutoForm = "AutoForm",
}
export interface Plugin {
id: string;
name: string;
type: PluginType;
packageName: string;
iconLocation?: string;
uiComponent: UIComponentTypes;
datasourceComponent: DatasourceComponentTypes;
allowUserDatasources?: boolean;
templates: Record<string, string>;
responseType?: "TABLE" | "JSON";
documentationLink?: string;
generateCRUDPageComponent?: string;
}
export interface PluginFormPayload {
form: any[];
editor: any[];
setting: any[];
dependencies: DependencyMap;
}
class PluginsApi extends Api {
static url = "v1/plugins";
static fetchPlugins(
orgId: string,
): AxiosPromise<GenericApiResponse<Plugin[]>> {
return Api.get(PluginsApi.url, { organizationId: orgId });
}
static fetchFormConfig(
id: string,
): AxiosPromise<GenericApiResponse<PluginFormPayload>> {
return Api.get(PluginsApi.url + `/${id}/form`);
}
// Definition to fetch the dynamic data via the URL passed in the config
static fetchDynamicFormValues(
url: string,
body: Record<string, any>,
): AxiosPromise<GenericApiResponse<DropdownOption[]>> {
return Api.post(url, body);
}
}
export default PluginsApi;