Skip to content

feat(action-intent): pass action intent params to actionContext #1270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/agent/src/routes/modification/action/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export default class ActionRoute extends CollectionRoute {
searchField: body.data.attributes.search_field,
searchValues,
includeHiddenFields: false,
actionIntentParams: body.data.attributes.action_intent_params,
});

context.response.body = SchemaGeneratorActions.buildFieldsAndLayout(
Expand Down
1 change: 1 addition & 0 deletions packages/agent/src/services/authorization/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface SmartActionRequestBody {
parent_association_name: string | null;
all_records: boolean;
all_records_subset_query: null;
action_intent_params?: Record<string, unknown> | null;
};
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ export default class ActionCollectionDecorator extends CollectionDecorator {

const formValues = data ? { ...data } : {};
const used = new Set<string>();
const context = this.getContext(caller, action, formValues, filter, used, metas?.changedField);
const context = this.getContext(
caller,
action,
formValues,
filter,
used,
metas?.changedField,
metas?.actionIntentParams,
);

// Convert DynamicField to ActionField in successive steps.
let dynamicFields: DynamicForm = this.isHandler(action.form)
Expand Down Expand Up @@ -171,12 +179,21 @@ export default class ActionCollectionDecorator extends CollectionDecorator {
filter: Filter,
used?: Set<string>,
changedField?: string,
actionIntentParams?: Record<string, unknown>,
): ActionContext {
return new {
Global: ActionContext,
Bulk: ActionContext,
Single: ActionContextSingle,
}[action.scope](this, caller, formValues, filter as unknown as PlainFilter, used, changedField);
}[action.scope](
this,
caller,
formValues,
filter as unknown as PlainFilter,
used,
changedField,
actionIntentParams,
);
}

private getSearchedField(element: DynamicFormElementOrPage, search: string): DynamicField | null {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class ActionContext<
> extends CollectionCustomizationContext<S, N> {
readonly formValues: RecordData;
readonly filter: TFilter<S, N>;
readonly actionIntentParams: Record<string, unknown> | null;

private _changedField: string;

Expand Down Expand Up @@ -47,11 +48,13 @@ export default class ActionContext<
filter: TFilter<S, N>,
used?: Set<string>,
changedField?: string,
actionIntentParams?: Record<string, unknown>,
) {
super(collection, caller);
this.formValues = formValue;
this.filter = filter;
this._changedField = changedField;
this.actionIntentParams = actionIntentParams;
this.reset();

// Spy on which formValues are accessed to set-up change hooks
Expand Down
1 change: 1 addition & 0 deletions packages/datasource-toolkit/src/interfaces/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export type GetFormMetas = {
searchField?: string | null;
searchValues?: Record<string, string | null>;
includeHiddenFields?: boolean;
actionIntentParams?: Record<string, unknown> | null;
};

export interface Collection {
Expand Down
Loading