Skip to content

Commit

Permalink
dynamic parameter passing in nxql
Browse files Browse the repository at this point in the history
  • Loading branch information
swarnadipa-dev committed Oct 4, 2024
1 parent 83eae15 commit ef014a9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export class NXQLTabComponent implements OnInit, OnDestroy {
nxqlQueryHintSanitized: SafeHtml = "";
activeFeature: FeaturesKey = {} as FeaturesKey;
inputPlaceholder = "";
requestQuery = "";

constructor(
public dialogService: MatDialog,
Expand Down Expand Up @@ -206,13 +207,13 @@ export class NXQLTabComponent implements OnInit, OnDestroy {
/* decode user input to handle path names that contain spaces,
which would not be decoded by default by nuxeo js client & would result in invalid api parameter */
try {
const decodedUserInput = decodeURIComponent(
this.requestQuery = decodeURIComponent(
/* Remove leading single & double quotes in case of path, to avoid invalid nuxeo js client api parameter */
this.genericMultiFeatureUtilitiesService.removeLeadingCharacters(
userInput
)
);
this.fetchNoOfDocuments(decodedUserInput);
this.fetchNoOfDocuments(this.requestQuery);
} catch (error) {
this.genericMultiFeatureUtilitiesService.spinnerStatus.next(false);
this.showActionErrorModal({
Expand Down Expand Up @@ -313,9 +314,19 @@ export class NXQLTabComponent implements OnInit, OnDestroy {
this.activeFeature
) as FeaturesKey;
if (featureKey in FEATURES) {
let requestUrl = "";
let requestParams = this.templateConfigData?.data["bodyParam"];

Check failure on line 318 in nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/components/nxql-tab/nxql-tab.component.ts

View workflow job for this annotation

GitHub Actions / lint

'requestParams' is never reassigned. Use 'const' instead
if (requestParams) {
// Since, it is bodyParam, the query would be part of body params object & not the url
requestParams["query"] = this.requestQuery;
} else {
// since it is queryParam, the query would be appended to the url
requestUrl = this.requestQuery;

Check warning on line 324 in nuxeo-admin-console-web/angular-app/src/app/features/sub-features/generic-multi-feature-layout/components/nxql-tab/nxql-tab.component.ts

View workflow job for this annotation

GitHub Actions / lint

'requestUrl' is assigned a value but never used
}
this.store.dispatch(
FeatureActions.performNxqlAction({
nxqlQuery: this.decodedUserInput,
requestUrl: this.requestQuery,
requestParams,
featureEndpoint: REST_END_POINTS[featureKey as FeaturesKey],
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export function getFeatureKeyByValue(

export const featureMap = () => ({
[FEATURES.ELASTIC_SEARCH_REINDEX]: (tabType: string) => {
let requestParams: string;
let labels: labelsList;
let data = {};

Expand Down Expand Up @@ -49,11 +48,15 @@ export const featureMap = () => ({
break;

case GENERIC_LABELS.NXQL:
(requestParams = `ecm:uuid='{queryParam}' OR ecm:ancestorId='{queryParam}' ${GENERIC_LABELS.AND} ${GENERIC_LABELS.SELECT_QUERY_CONDITIONS}`),
(labels = {
pageTitle: ELASTIC_SEARCH_LABELS.NXQL_QUERY_REINDEX_TITLE,
submitBtnLabel: ELASTIC_SEARCH_LABELS.REINDEX_BUTTON_LABEL,
});
labels = {
pageTitle: ELASTIC_SEARCH_LABELS.NXQL_QUERY_REINDEX_TITLE,
submitBtnLabel: ELASTIC_SEARCH_LABELS.REINDEX_BUTTON_LABEL,
};
data = {
queryParam: {
query: `ecm:uuid='{query}' OR ecm:ancestorId='{query}' ${GENERIC_LABELS.AND} ${GENERIC_LABELS.SELECT_QUERY_CONDITIONS}`,
},
};
break;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,13 @@ export class GenericMultiFeatureEndpointsService {
}

performNXQLAction(
nxqlQuery: string | null,
requestUrl: string | null,
requestParams: unknown,
featureEndpoint: string
): Observable<ActionInfo> {
return this.networkService.makeHttpRequest<ActionInfo>(
REST_END_POINTS[featureEndpoint as keyof typeof REST_END_POINTS],
{ query: nxqlQuery }
{ queryParam: { requestUrl }, bodyParam: { requestParams } }
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const resetFolderActionState = createAction(
);
export const performNxqlAction = createAction(
"[Admin] Perform NXQL Action",
props<{ nxqlQuery: string | null; featureEndpoint: string }>()
props<{ requestUrl: string | null; requestParams: unknown; featureEndpoint: string }>()
);
export const onNxqlActionLaunch = createAction(
"[Admin] On NXQL Action Launch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export const loadPerformNxqlActionEffect = createEffect(
ofType(FeatureActions.performNxqlAction),
switchMap((action) => {
return genericMultiFeatureEndpointsService
.performNXQLAction(action?.nxqlQuery, action?.featureEndpoint)
.performNXQLAction(action?.requestUrl, action?.requestParams, action?.featureEndpoint)
.pipe(
map((data) => {
return FeatureActions.onNxqlActionLaunch({
Expand Down

0 comments on commit ef014a9

Please sign in to comment.