Skip to content

Commit

Permalink
Added create URL support to drilldown
Browse files Browse the repository at this point in the history
  • Loading branch information
traeok committed Nov 19, 2021
1 parent 3e96719 commit ef831ed
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
38 changes: 26 additions & 12 deletions drilldown/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,35 @@ export interface QueryResult {
* @param callback Function that is passed the response from said query (key and results)
*/
export const fetchQuery = async (queryExp: any, callback: Function) => {
// Cannot work with the URL if it isn't a visualization edit/create URL
if (window.location.href.indexOf('edit') < 0 && window.location.href.indexOf('create') < 0) {
return;
}

const kibanaAppURL = window.location.href.substring(0, window.location.href.indexOf('app'));
const kibanaApiURL = `${kibanaAppURL}api/`;
const [visIDMatch, visualizationID] = window.location.href.match(/visualize#\/edit\/(.+?)\?_g=/);
const editMatch = window.location.href.match(/visualize#\/edit\/(.+?)\?_g=/);
const createMatch = window.location.href.match(
/visualize#\/create\?type=(?:.+?)&indexPattern=(.+?)&_g/
);

const indexPattern = await fetch(
kibanaApiURL + `saved_objects/visualization/${visualizationID}`,
{
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
}
)
.then((resp) => resp.json())
.then((data) => data.references[0].id);
const indexPattern =
editMatch == null
? createMatch == null
? null
: createMatch[1]
: await fetch(kibanaApiURL + `saved_objects/visualization/${editMatch[1]}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
})
.then((resp) => resp.json())
.then((data) => data.references[0].id);

if (indexPattern == null) {
return;
}

// query:(language:kuery,query:'...')
const [fullMatch, gParams, filters, query] = window.location.href.match(
Expand Down
2 changes: 1 addition & 1 deletion line-visualizer/public/components/Options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export const LineVisualizerOptions = ({
useEffect(() => {
setIntervalId(
setInterval(() => {
if (window.location.href.indexOf('edit') < 0) {
if (window.location.href.indexOf('edit') < 0 && window.location.href.indexOf('create') < 0) {
clearInterval(intervalId);
return;
}
Expand Down
2 changes: 1 addition & 1 deletion radar-visualizer/public/components/Options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export const RadarVisualizerOptions = ({
useEffect(() => {
setIntervalId(
setInterval(() => {
if (window.location.href.indexOf('edit') < 0) {
if (window.location.href.indexOf('edit') < 0 && window.location.href.indexOf('create') < 0) {
clearInterval(intervalId);
return;
}
Expand Down

0 comments on commit ef831ed

Please sign in to comment.