Skip to content

Commit

Permalink
Implementing query and pagination for object filter
Browse files Browse the repository at this point in the history
  • Loading branch information
GTFalcao committed Jun 26, 2024
1 parent 2e5655b commit dc1c76c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
20 changes: 16 additions & 4 deletions components/google_ads/actions/create-report/create-report.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,29 @@ export default {
label: `Filter by ${label}s`,
description: `Select the ${label}s to generate a report for (or leave blank for all ${label}s)`,
optional: true,
options: async () => {
useQuery: true,
options: async ({
query, prevContext: { nextPageToken: pageToken },
}) => {
const {
accountId, customerClientId, resource,
} = this;
const items = await this.googleAds.listResources({
const {
results, nextPageToken,
} = await this.googleAds.listResources({
accountId,
customerClientId,
resource,
query,
pageToken,
});
console.log(items);
return items?.map?.((item) => this.getResourceOption(item, resource));
const options = results?.map?.((item) => this.getResourceOption(item, resource));
return {
options,
context: {
nextPageToken,
},
};
},
},
dateRange: {
Expand Down
9 changes: 7 additions & 2 deletions components/google_ads/common/queries.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,19 @@ function listCampaigns({
return `SELECT ${fields.map((s) => `campaign.${s}`).join(", ")} FROM campaign${filter}`;
}

function listResources(resource) {
function listResources(resource, query) {
const name = resource === "customer"
? "descriptive_name"
: "name";
const fieldResource = resource === "ad_group_ad"
? "ad_group_ad.ad"
: resource;
return `SELECT ${fieldResource}.id, ${fieldResource}.${name} FROM ${resource}`;

let result = `SELECT ${fieldResource}.id, ${fieldResource}.${name} FROM ${resource}`;
if (query) {
result += ` WHERE ${fieldResource}.${name} LIKE '%${query}%'`;
}
return result;
}

export const QUERIES = {
Expand Down
34 changes: 23 additions & 11 deletions components/google_ads/google_ads.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export default {
},
...args,
});
return response.results;
return response;
},
async listAccessibleCustomers() {
const response = await this._makeRequest({
Expand All @@ -139,13 +139,15 @@ export default {
async listCustomerClients({
query, ...args
}) {
return this.search({
const { results } = await this.search({
query: QUERIES.listCustomerClients(query),
...args,
});
return results;
},
async createReport(args) {
return this.search(args);
const { results } = await this.search(args);
return results;
},
async createUserList(args) {
const response = await this._makeRequest({
Expand All @@ -156,52 +158,62 @@ export default {
return response;
},
async listUserLists(args) {
return this.search({
const { results } = await this.search({
query: QUERIES.listUserLists(),
...args,
});
return results;
},
async listConversionActions(args) {
return this.search({
const { results } = await this.search({
query: QUERIES.listConversionActions(),
...args,
});
return results;
},
async listRemarketingActions(args) {
return this.search({
const { results } = await this.search({
query: QUERIES.listRemarketingActions(),
...args,
});
return results;
},
async listLeadForms(args) {
return this.search({
const { results } = await this.search({
query: QUERIES.listLeadForms(),
...args,
});
return results;
},
async listCampaigns({
query, ...args
}) {
return this.search({
const { results } = await this.search({
query: QUERIES.listCampaigns(query),
...args,
});
return results;
},
async listResources({
resource, ...args
resource, query, pageToken, ...args
}) {
return this.search({
query: QUERIES.listResources(resource),
query: QUERIES.listResources(resource, query),
params: {
pageSize: 100,
pageToken,
},
...args,
});
},
async getLeadFormData({
leadFormId, ...args
}) {
return this.search({
const { results } = await this.search({
query: QUERIES.listLeadFormSubmissionData(leadFormId),
...args,
});
return results;
},
async createConversionAction(args) {
const response = await this._makeRequest({
Expand Down

0 comments on commit dc1c76c

Please sign in to comment.