Skip to content

Commit

Permalink
Perform hasData check
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Fernández Gómez committed Jul 1, 2020
1 parent 62884e0 commit 92607df
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions x-pack/plugins/infra/public/utils/logs_overview_fetchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,10 @@ export function getLogsHasDataFetcher(
getStartServices: InfraClientCoreSetup['getStartServices']
): HasData {
return async () => {
// if you need the data plugin, this is how you get it
// const [, startPlugins] = await getStartServices();
// const { data } = startPlugins;

// if you need a core dep, we need to pass in more than just getStartServices
const [, startPlugins] = await getStartServices();
const { data } = startPlugins;

// perform query
return true;
return await hasLogsOverview('filebeat-*', data);
};
}

Expand All @@ -70,6 +66,30 @@ export function getLogsOverviewDataFetcher(
};
}

async function hasLogsOverview(
index: string,
dataPlugin: InfraClientStartDeps['data']
): Promise<boolean> {
const esSearcher = dataPlugin.search.getSearchStrategy('es');
return new Promise((resolve, reject) => {
esSearcher
.search({
params: {
index,
body: {
size: 0,
},
},
})
.subscribe(
(response) => {
resolve(response.rawResponse.hits.total > 0);
},
(error) => reject(error)
);
});
}

async function fetchLogsOverview(
logParams: LogParams,
params: FetchDataParams,
Expand Down

0 comments on commit 92607df

Please sign in to comment.