From 40e802d783bf25e05c6876ca43c3918d4e5a5981 Mon Sep 17 00:00:00 2001 From: dbarrbc <89422790+dbarrbc@users.noreply.github.com> Date: Tue, 17 Sep 2024 11:14:23 -0600 Subject: [PATCH 1/2] Update useSendVertexMessage.ts --- .../src/hooks/useSendVertexMessage.ts | 85 ++++++++++++++++++- 1 file changed, 81 insertions(+), 4 deletions(-) diff --git a/explore-assistant-extension/src/hooks/useSendVertexMessage.ts b/explore-assistant-extension/src/hooks/useSendVertexMessage.ts index f81a610b..8702f5e8 100644 --- a/explore-assistant-extension/src/hooks/useSendVertexMessage.ts +++ b/explore-assistant-extension/src/hooks/useSendVertexMessage.ts @@ -432,10 +432,87 @@ ${ } const currentDateTime = new Date().toISOString() - let exampleText = '' - if(exploreGenerationExamples && exploreGenerationExamples.length > 0) { - exampleText = exploreGenerationExamples.map((item) => `input: "${item.input}" ; output: ${item.output}`).join('\n') - } +const parseLookerURL = (url: string): { [key: string]: any } => { + // Split URL and extract model & explore + const [rootURL, queryString] = url.split("?"); + const rootURLElements = rootURL.split("/"); + const model = rootURLElements[rootURLElements.length - 2]; + const explore = rootURLElements[rootURLElements.length - 1]; + + // Initialize lookerEncoding object + + + const lookerEncoding: { [key: string]: any } = {}; + lookerEncoding['model'] = model + lookerEncoding['explore'] = explore + lookerEncoding['fields'] = [] + lookerEncoding['pivots'] = [] + lookerEncoding['fill_fields'] = [] + lookerEncoding['filters'] = {} + lookerEncoding['filter_expression'] = null + lookerEncoding['sorts'] = [] + lookerEncoding['limit'] = 500 + lookerEncoding['column_limit'] = 50 + lookerEncoding['total'] = null + lookerEncoding['row_total'] = null + lookerEncoding['subtotals'] = null + lookerEncoding['vis'] = [] + + + // Split query string and iterate key-value pairs + const keyValuePairs = queryString.split("&"); + for (const qq of keyValuePairs) { + const [key, value] = qq.split('='); + switch (key) { + case "fields": + case "pivots": + case "fill_fields": + case "sorts": + lookerEncoding[key] = value.split(","); + break; + case "filter_expression": + case "total": + case "row_total": + case "subtotals": + lookerEncoding[key] = value; + break; + case "limit": + case "column_limit": + lookerEncoding[key] = parseInt(value); + break; + case "vis": + lookerEncoding[key] = JSON.parse(decodeURIComponent(value)); + break; + default: + if (key.startsWith("f[")) { + const filterKey = key.slice(2, -1); + lookerEncoding.filters[filterKey] = value; + } else if (key.includes(".")) { + const path = key.split("."); + let currentObject = lookerEncoding; + for (let i = 0; i < path.length - 1; i++) { + const segment = path[i]; + if (!currentObject[segment]) { + currentObject[segment] = {}; + } + currentObject = currentObject[segment]; + } + currentObject[path[path.length - 1]] = value; + } + } + } + + return lookerEncoding; + +}; + + + + +let exampleText = '' +if(exploreGenerationExamples && exploreGenerationExamples.length > 0) { + exampleText = exploreGenerationExamples.map((item) => `input: "${item.input}" ; output: ${JSON.stringify(parseLookerURL(item.output))}`).join('\n') +} const contents = ` # Context From caed43aecee031bf99b55f6e296b95617bed8945 Mon Sep 17 00:00:00 2001 From: dbarrbc <89422790+dbarrbc@users.noreply.github.com> Date: Wed, 18 Sep 2024 12:46:49 -0600 Subject: [PATCH 2/2] Fixed issue with parsing cleaned url Added case statement to handle both cleaned an uncleaned urls --- .../src/hooks/useSendVertexMessage.ts | 150 ++++++++++-------- 1 file changed, 80 insertions(+), 70 deletions(-) diff --git a/explore-assistant-extension/src/hooks/useSendVertexMessage.ts b/explore-assistant-extension/src/hooks/useSendVertexMessage.ts index 8702f5e8..361528f4 100644 --- a/explore-assistant-extension/src/hooks/useSendVertexMessage.ts +++ b/explore-assistant-extension/src/hooks/useSendVertexMessage.ts @@ -432,79 +432,89 @@ ${ } const currentDateTime = new Date().toISOString() -const parseLookerURL = (url: string): { [key: string]: any } => { - // Split URL and extract model & explore - const [rootURL, queryString] = url.split("?"); - const rootURLElements = rootURL.split("/"); - const model = rootURLElements[rootURLElements.length - 2]; - const explore = rootURLElements[rootURLElements.length - 1]; - - // Initialize lookerEncoding object - - - const lookerEncoding: { [key: string]: any } = {}; - lookerEncoding['model'] = model - lookerEncoding['explore'] = explore - lookerEncoding['fields'] = [] - lookerEncoding['pivots'] = [] - lookerEncoding['fill_fields'] = [] - lookerEncoding['filters'] = {} - lookerEncoding['filter_expression'] = null - lookerEncoding['sorts'] = [] - lookerEncoding['limit'] = 500 - lookerEncoding['column_limit'] = 50 - lookerEncoding['total'] = null - lookerEncoding['row_total'] = null - lookerEncoding['subtotals'] = null - lookerEncoding['vis'] = [] - - - // Split query string and iterate key-value pairs - const keyValuePairs = queryString.split("&"); - for (const qq of keyValuePairs) { - const [key, value] = qq.split('='); - switch (key) { - case "fields": - case "pivots": - case "fill_fields": - case "sorts": - lookerEncoding[key] = value.split(","); - break; - case "filter_expression": - case "total": - case "row_total": - case "subtotals": - lookerEncoding[key] = value; - break; - case "limit": - case "column_limit": - lookerEncoding[key] = parseInt(value); - break; - case "vis": - lookerEncoding[key] = JSON.parse(decodeURIComponent(value)); - break; - default: - if (key.startsWith("f[")) { - const filterKey = key.slice(2, -1); - lookerEncoding.filters[filterKey] = value; - } else if (key.includes(".")) { - const path = key.split("."); - let currentObject = lookerEncoding; - for (let i = 0; i < path.length - 1; i++) { - const segment = path[i]; - if (!currentObject[segment]) { - currentObject[segment] = {}; - } - currentObject = currentObject[segment]; + const parseLookerURL = (url: string): { [key: string]: any } => { + // Split URL and extract model & explore + const urlSplit = url.split("?"); + let model = "" + let explore = "" + let queryString = "" + if (urlSplit.length == 2) { + const rootURL = urlSplit[0] + queryString = urlSplit[1] + const rootURLElements = rootURL.split("/"); + model = rootURLElements[rootURLElements.length - 2]; + explore = rootURLElements[rootURLElements.length - 1]; + } + else if (urlSplit.length == 1) { + model = "tbd" + explore = "tbd" + queryString = urlSplit[0] + } + // Initialize lookerEncoding object + const lookerEncoding: { [key: string]: any } = {}; + lookerEncoding['model'] = "" + lookerEncoding['explore'] = "" + lookerEncoding['fields'] = [] + lookerEncoding['pivots'] = [] + lookerEncoding['fill_fields'] = [] + lookerEncoding['filters'] = {} + lookerEncoding['filter_expression'] = null + lookerEncoding['sorts'] = [] + lookerEncoding['limit'] = 500 + lookerEncoding['column_limit'] = 50 + lookerEncoding['total'] = null + lookerEncoding['row_total'] = null + lookerEncoding['subtotals'] = null + lookerEncoding['vis'] = [] + // Split query string and iterate key-value pairs + const keyValuePairs = queryString.split("&"); + for (const qq of keyValuePairs) { + const [key, value] = qq.split('='); + console.log(qq) + lookerEncoding['model'] = model + lookerEncoding['explore'] = explore + switch (key) { + case "fields": + case "pivots": + case "fill_fields": + case "sorts": + lookerEncoding[key] = value.split(","); + break; + case "filter_expression": + case "total": + case "row_total": + case "subtotals": + lookerEncoding[key] = value; + break; + case "limit": + case "column_limit": + lookerEncoding[key] = parseInt(value); + break; + case "vis": + lookerEncoding[key] = JSON.parse(decodeURIComponent(value)); + break; + default: + if (key.startsWith("f[")) { + const filterKey = key.slice(2, -1); + lookerEncoding.filters[filterKey] = value; + } else if (key.includes(".")) { + const path = key.split("."); + let currentObject = lookerEncoding; + for (let i = 0; i < path.length - 1; i++) { + const segment = path[i]; + if (!currentObject[segment]) { + currentObject[segment] = {}; + } + currentObject = currentObject[segment]; + } + currentObject[path[path.length - 1]] = value; + } } - currentObject[path[path.length - 1]] = value; } - } - } + return lookerEncoding; + }; + - return lookerEncoding; - -};