-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add hover on policy name with details
- Loading branch information
Showing
8 changed files
with
165 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
packages/kbn-monaco/src/esql/lib/ast/shared/resources_helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import type { ESQLCallbacks } from './types'; | ||
import type { ESQLRealField } from '../validation/types'; | ||
|
||
// These are method useful for any non-validation use cases that can be re-used. | ||
// Validation has its own logic so DO NOT USE THESE there. | ||
|
||
export function getFieldsByTypeHelper(resourceRetriever?: ESQLCallbacks) { | ||
const cacheFields = new Map<string, ESQLRealField>(); | ||
const getFields = async () => { | ||
if (!cacheFields.size) { | ||
const fieldsOfType = await resourceRetriever?.getFieldsFor?.(); | ||
for (const field of fieldsOfType || []) { | ||
cacheFields.set(field.name, field); | ||
} | ||
} | ||
}; | ||
return { | ||
getFieldsByType: async (expectedType: string | string[] = 'any', ignored: string[] = []) => { | ||
const types = Array.isArray(expectedType) ? expectedType : [expectedType]; | ||
await getFields(); | ||
return ( | ||
Array.from(cacheFields.values()) | ||
?.filter(({ name, type }) => { | ||
const ts = Array.isArray(type) ? type : [type]; | ||
return ( | ||
!ignored.includes(name) && ts.some((t) => types[0] === 'any' || types.includes(t)) | ||
); | ||
}) | ||
.map(({ name }) => name) || [] | ||
); | ||
}, | ||
getFieldsMap: async () => { | ||
await getFields(); | ||
const cacheCopy = new Map<string, ESQLRealField>(); | ||
cacheFields.forEach((value, key) => cacheCopy.set(key, value)); | ||
return cacheCopy; | ||
}, | ||
}; | ||
} | ||
|
||
export function getPolicyHelper(resourceRetriever?: ESQLCallbacks) { | ||
const getPolicies = async () => { | ||
return (await resourceRetriever?.getPolicies?.()) || []; | ||
}; | ||
return { | ||
getPolicies: async () => { | ||
const policies = await getPolicies(); | ||
return policies; | ||
}, | ||
getPolicyMetadata: async (policyName: string) => { | ||
const policies = await getPolicies(); | ||
return policies.find(({ name }) => name === policyName); | ||
}, | ||
}; | ||
} | ||
|
||
export function getSourcesHelper(resourceRetriever?: ESQLCallbacks) { | ||
return async () => { | ||
return (await resourceRetriever?.getSources?.()) || []; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
/** @internal **/ | ||
type CallbackFn<Options = {}, Result = string> = (ctx?: Options) => Result[] | Promise<Result[]>; | ||
|
||
/** @public **/ | ||
export interface ESQLCallbacks { | ||
getSources?: CallbackFn; | ||
getFieldsFor?: CallbackFn< | ||
{ sourcesOnly?: boolean } | { customQuery?: string }, | ||
{ name: string; type: string } | ||
>; | ||
getPolicies?: CallbackFn< | ||
{}, | ||
{ name: string; sourceIndices: string[]; matchField: string; enrichFields: string[] } | ||
>; | ||
getPolicyFields?: CallbackFn; | ||
getPolicyMatchingField?: CallbackFn; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters