Skip to content

Commit

Permalink
chore: update widget prop with query name
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinOm committed Oct 9, 2024
1 parent 5938175 commit e3cf293
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
} from "WidgetProvider/constants";
import { createOrUpdateDataSourceWithAction } from "sagas/DatasourcesSagas";
import { PluginPackageName } from "entities/Action";
import type { ActionData } from "ee/reducers/entityReducers/actionsReducer";
import type { WidgetProps } from "widgets/BaseWidget";

export const defaultsConfig = {
isVisible: true,
Expand All @@ -16,13 +18,21 @@ export const defaultsConfig = {
operations: [
{
type: BlueprintOperationTypes.ADD_ACTION,
fn: function* () {
yield createOrUpdateDataSourceWithAction(
fn: function* (widget: WidgetProps & { children?: WidgetProps[] }) {
const action: ActionData = yield createOrUpdateDataSourceWithAction(
PluginPackageName.APPSMITH_AI,
{
usecase: { data: "TEXT_CLASSIFY" },
},
);

return [
{
widgetId: widget.widgetId,
propertyName: "query",
propertyValue: action.config.name,
},
];
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion app/client/src/sagas/ActionSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export function* createActionRequestSaga(
actionPayload: ReduxAction<
// TODO: Fix this the next time the file is edited
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Partial<Action> & { eventData: any; pluginId: string }
Partial<Action> & { eventData?: any; pluginId: string }
>,
) {
const payload = { ...actionPayload.payload };
Expand Down
42 changes: 25 additions & 17 deletions app/client/src/sagas/DatasourcesSagas.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { objectKeys } from "@appsmith/utils";
import {
all,
call,
Expand Down Expand Up @@ -36,6 +35,7 @@ import {
} from "selectors/editorSelectors";
import {
type DatasourceGroupByPluginCategory,
getActions,
getDatasourceByPluginId,
} from "ee/selectors/entitiesSelector";
import {
Expand Down Expand Up @@ -96,6 +96,8 @@ import {
DATASOURCE_DB_FORM,
DATASOURCE_REST_API_FORM,
} from "ee/constants/forms";
import type { ActionDataState } from "ee/reducers/entityReducers/actionsReducer";
import { createActionRequestSaga } from "./ActionSagas";
import { validateResponse } from "./ErrorSagas";
import AnalyticsUtil from "ee/utils/AnalyticsUtil";
import type { GetFormData } from "selectors/formSelectors";
Expand Down Expand Up @@ -184,7 +186,6 @@ import { executeGoogleApi } from "./loadGoogleApi";
import type { ActionParentEntityTypeInterface } from "ee/entities/Engine/actionHelpers";
import { getCurrentModuleId } from "ee/selectors/modulesSelector";
import type { ApplicationPayload } from "entities/Application";
import { createActionRequest } from "../actions/pluginActionActions";

function* fetchDatasourcesSaga(
action: ReduxAction<
Expand Down Expand Up @@ -597,7 +598,7 @@ function* updateDatasourceSaga(
//So we need to update the other storages with the old values.
// TODO server should send ony the updated storage or whole datasource.
if (!isNewStorage) {
objectKeys(datasourcePayload.datasourceStorages).forEach(
Object.keys(datasourcePayload.datasourceStorages).forEach(
(storageId: string) => {
if (storageId !== currentEnvironment) {
response.data.datasourceStorages[storageId] =
Expand Down Expand Up @@ -1129,14 +1130,14 @@ export function* createOrUpdateDataSourceWithAction(
plugin.id,
);
const pageId: string = yield select(getCurrentPageId);
const payload: Datasource = yield getInitialDatasourcePayload(
const datasourcePayload: Datasource = yield getInitialDatasourcePayload(
plugin.id,
plugin.type,
);

if (aiDatasources.length === 0) {
yield createDatasourceFromFormSaga({
payload,
payload: datasourcePayload,
type: ReduxActionTypes.CREATE_DATASOURCE_FROM_FORM_INIT,
});
}
Expand All @@ -1146,18 +1147,25 @@ export function* createOrUpdateDataSourceWithAction(
plugin.id,
);

yield put(
createActionRequest({
pageId,
pluginId: updatedAiDatasources[0].pluginId,
datasource: {
id: updatedAiDatasources[0].id,
},
actionConfiguration: {
formData,
},
}),
);
const actionPayload = {
pageId,
pluginId: updatedAiDatasources[0].pluginId,
datasource: {
id: updatedAiDatasources[0].id,
},
actionConfiguration: {
formData,
},
};

yield createActionRequestSaga({
payload: actionPayload,
type: ReduxActionTypes.CREATE_ACTION_REQUEST,
});

const actions: ActionDataState = yield select(getActions);

return actions[actions.length - 1];
}

export function* createDatasourceFromFormSaga(
Expand Down
15 changes: 13 additions & 2 deletions app/client/src/sagas/WidgetBlueprintSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ export interface UpdatePropertyArgs {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
propertyValue: any;
}
export type BlueprintOperationAddActionFn = () => Generator;
export type BlueprintOperationAddActionFn = (
widget: WidgetProps & { children?: WidgetProps[] },
) => Generator;
export type BlueprintOperationModifyPropsFn = (
widget: WidgetProps & { children?: WidgetProps[] },
widgets: { [widgetId: string]: FlattenedWidgetProps },
Expand Down Expand Up @@ -118,7 +120,16 @@ export function* executeWidgetBlueprintOperations(
switch (operation.type) {
case BlueprintOperationTypes.ADD_ACTION:
if (operation.fn) {
yield (operation.fn as BlueprintOperationAddActionFn)();
const updatePropertyPayloads: UpdatePropertyArgs[] | undefined =
yield (operation.fn as BlueprintOperationAddActionFn)(
widget as WidgetProps & { children?: WidgetProps[] },
);

updatePropertyPayloads &&
updatePropertyPayloads.forEach((params: UpdatePropertyArgs) => {
widgets[params.widgetId][params.propertyName] =
params.propertyValue;
});
}

break;
Expand Down

0 comments on commit e3cf293

Please sign in to comment.