Skip to content

Commit

Permalink
[Lens] Fix rollup related bugs (elastic#75314)
Browse files Browse the repository at this point in the history
Co-authored-by: Marta Bondyra <marta.bondyra@elastic.co>
  • Loading branch information
flash1293 and mbondyra authored Aug 26, 2020
1 parent eecf4aa commit ddf99b6
Show file tree
Hide file tree
Showing 26 changed files with 1,765 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const initialState: IndexPatternPrivateState = {
id: '1',
title: 'idx1',
timeFieldName: 'timestamp',
hasRestrictions: false,
fields: [
{
name: 'timestamp',
Expand Down Expand Up @@ -134,6 +135,7 @@ const initialState: IndexPatternPrivateState = {
id: '2',
title: 'idx2',
timeFieldName: 'timestamp',
hasRestrictions: true,
fields: [
{
name: 'timestamp',
Expand Down Expand Up @@ -191,6 +193,7 @@ const initialState: IndexPatternPrivateState = {
id: '3',
title: 'idx3',
timeFieldName: 'timestamp',
hasRestrictions: false,
fields: [
{
name: 'timestamp',
Expand Down Expand Up @@ -322,8 +325,20 @@ describe('IndexPattern Data Panel', () => {
isFirstExistenceFetch: false,
currentIndexPatternId: 'a',
indexPatterns: {
a: { id: 'a', title: 'aaa', timeFieldName: 'atime', fields: [] },
b: { id: 'b', title: 'bbb', timeFieldName: 'btime', fields: [] },
a: {
id: 'a',
title: 'aaa',
timeFieldName: 'atime',
fields: [],
hasRestrictions: false,
},
b: {
id: 'b',
title: 'bbb',
timeFieldName: 'btime',
fields: [],
hasRestrictions: false,
},
},
layers: {
1: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export function IndexPatternDataPanel({
title: indexPatterns[id].title,
timeFieldName: indexPatterns[id].timeFieldName,
fields: indexPatterns[id].fields,
hasRestrictions: indexPatterns[id].hasRestrictions,
}));

const dslQuery = buildSafeEsQuery(
Expand Down Expand Up @@ -422,6 +423,8 @@ export const InnerIndexPatternDataPanel = function InnerIndexPatternDataPanel({
]
);

const fieldInfoUnavailable = existenceFetchFailed || currentIndexPattern.hasRestrictions;

return (
<ChildDragDropProvider {...dragDropContext}>
<EuiFlexGroup
Expand Down Expand Up @@ -568,7 +571,7 @@ export const InnerIndexPatternDataPanel = function InnerIndexPatternDataPanel({
initialIsOpen={localState.isAvailableAccordionOpen}
id="lnsIndexPatternAvailableFields"
label={
existenceFetchFailed
fieldInfoUnavailable
? i18n.translate('xpack.lens.indexPattern.allFieldsLabel', {
defaultMessage: 'All fields',
})
Expand All @@ -577,6 +580,7 @@ export const InnerIndexPatternDataPanel = function InnerIndexPatternDataPanel({
})
}
exists={true}
hideDetails={fieldInfoUnavailable}
hasLoaded={!!hasSyncedExistingFields}
fieldsCount={filteredFieldGroups.availableFields.length}
isFiltered={
Expand Down Expand Up @@ -609,7 +613,7 @@ export const InnerIndexPatternDataPanel = function InnerIndexPatternDataPanel({
}
/>
<EuiSpacer size="m" />
{!existenceFetchFailed && (
{!fieldInfoUnavailable && (
<FieldsAccordion
initialIsOpen={localState.isEmptyAccordionOpen}
isFiltered={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const expectedIndexPatterns = {
title: 'my-fake-index-pattern',
timeFieldName: 'timestamp',
hasExistence: true,
hasRestrictions: false,
fields: [
{
name: 'timestamp',
Expand Down Expand Up @@ -1256,6 +1257,7 @@ describe('IndexPatternDimensionEditorPanel', () => {
foo: {
id: 'foo',
title: 'Foo pattern',
hasRestrictions: false,
fields: [
{
aggregatable: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface FieldsAccordionProps {
renderCallout: JSX.Element;
exists: boolean;
showExistenceFetchError?: boolean;
hideDetails?: boolean;
}

export const InnerFieldsAccordion = function InnerFieldsAccordion({
Expand All @@ -61,13 +62,20 @@ export const InnerFieldsAccordion = function InnerFieldsAccordion({
fieldProps,
renderCallout,
exists,
hideDetails,
showExistenceFetchError,
}: FieldsAccordionProps) {
const renderField = useCallback(
(field: IndexPatternField) => (
<FieldItem {...fieldProps} key={field.name} field={field} exists={!!exists} />
<FieldItem
{...fieldProps}
key={field.name}
field={field}
exists={exists}
hideDetails={hideDetails}
/>
),
[fieldProps, exists]
[fieldProps, exists, hideDetails]
);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const expectedIndexPatterns = {
id: '1',
title: 'my-fake-index-pattern',
timeFieldName: 'timestamp',
hasRestrictions: false,
fields: [
{
name: 'timestamp',
Expand Down Expand Up @@ -70,6 +71,7 @@ const expectedIndexPatterns = {
id: '2',
title: 'my-fake-restricted-pattern',
timeFieldName: 'timestamp',
hasRestrictions: true,
fields: [
{
name: 'timestamp',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const expectedIndexPatterns = {
id: '1',
title: 'my-fake-index-pattern',
timeFieldName: 'timestamp',
hasRestrictions: false,
fields: [
{
name: 'timestamp',
Expand Down Expand Up @@ -68,6 +69,7 @@ const expectedIndexPatterns = {
2: {
id: '2',
title: 'my-fake-restricted-pattern',
hasRestrictions: true,
timeFieldName: 'timestamp',
fields: [
{
Expand Down Expand Up @@ -322,6 +324,7 @@ describe('IndexPattern Data Source suggestions', () => {
1: {
id: '1',
title: 'no timefield',
hasRestrictions: false,
fields: [
{
name: 'bytes',
Expand Down Expand Up @@ -532,6 +535,7 @@ describe('IndexPattern Data Source suggestions', () => {
1: {
id: '1',
title: 'no timefield',
hasRestrictions: false,
fields: [
{
name: 'bytes',
Expand Down Expand Up @@ -1350,6 +1354,7 @@ describe('IndexPattern Data Source suggestions', () => {
1: {
id: '1',
title: 'my-fake-index-pattern',
hasRestrictions: false,
fields: [
{
name: 'field1',
Expand Down Expand Up @@ -1493,6 +1498,7 @@ describe('IndexPattern Data Source suggestions', () => {
1: {
id: '1',
title: 'my-fake-index-pattern',
hasRestrictions: false,
fields: [
{
name: 'field1',
Expand Down Expand Up @@ -1555,6 +1561,7 @@ describe('IndexPattern Data Source suggestions', () => {
1: {
id: '1',
title: 'my-fake-index-pattern',
hasRestrictions: false,
fields: [
{
name: 'field1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ const initialState: IndexPatternPrivateState = {
id: '1',
title: 'my-fake-index-pattern',
timeFieldName: 'timestamp',
hasRestrictions: false,
fields: [
{
name: 'timestamp',
Expand Down Expand Up @@ -103,6 +104,7 @@ const initialState: IndexPatternPrivateState = {
'2': {
id: '2',
title: 'my-fake-restricted-pattern',
hasRestrictions: true,
timeFieldName: 'timestamp',
fields: [
{
Expand Down Expand Up @@ -160,6 +162,7 @@ const initialState: IndexPatternPrivateState = {
id: '3',
title: 'my-compatible-pattern',
timeFieldName: 'timestamp',
hasRestrictions: false,
fields: [
{
name: 'timestamp',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const indexPattern1 = ({
id: '1',
title: 'my-fake-index-pattern',
timeFieldName: 'timestamp',
hasRestrictions: false,
fields: [
{
name: 'timestamp',
Expand Down Expand Up @@ -105,6 +106,7 @@ const indexPattern2 = ({
id: '2',
title: 'my-fake-restricted-pattern',
timeFieldName: 'timestamp',
hasRestrictions: true,
fields: [
{
name: 'timestamp',
Expand Down Expand Up @@ -733,9 +735,9 @@ describe('loader', () => {
dateRange: { fromDate: '1900-01-01', toDate: '2000-01-01' },
fetchJson,
indexPatterns: [
{ id: '1', title: '1', fields: [] },
{ id: '2', title: '1', fields: [] },
{ id: '3', title: '1', fields: [] },
{ id: '1', title: '1', fields: [], hasRestrictions: false },
{ id: '2', title: '1', fields: [], hasRestrictions: false },
{ id: '3', title: '1', fields: [], hasRestrictions: false },
],
setState,
dslQuery,
Expand Down Expand Up @@ -783,9 +785,9 @@ describe('loader', () => {
dateRange: { fromDate: '1900-01-01', toDate: '2000-01-01' },
fetchJson,
indexPatterns: [
{ id: '1', title: '1', fields: [] },
{ id: '2', title: '1', fields: [] },
{ id: 'c', title: '1', fields: [] },
{ id: '1', title: '1', fields: [], hasRestrictions: false },
{ id: '2', title: '1', fields: [], hasRestrictions: false },
{ id: 'c', title: '1', fields: [], hasRestrictions: false },
],
setState,
dslQuery,
Expand Down Expand Up @@ -817,6 +819,7 @@ describe('loader', () => {
{
id: '1',
title: '1',
hasRestrictions: false,
fields: [{ name: 'field1' }, { name: 'field2' }] as IndexPatternField[],
},
],
Expand Down
8 changes: 8 additions & 0 deletions x-pack/plugins/lens/public/indexpattern_datasource/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export async function loadIndexPatterns({
timeFieldName,
fieldFormatMap,
fields: newFields,
hasRestrictions: !!typeMeta?.aggs,
};

return {
Expand Down Expand Up @@ -334,6 +335,7 @@ export async function syncExistingFields({
title: string;
fields: IndexPatternField[];
timeFieldName?: string | null;
hasRestrictions: boolean;
}>;
fetchJson: HttpSetup['post'];
setState: SetState;
Expand All @@ -343,6 +345,12 @@ export async function syncExistingFields({
showNoDataPopover: () => void;
}) {
const existenceRequests = indexPatterns.map((pattern) => {
if (pattern.hasRestrictions) {
return {
indexPatternTitle: pattern.title,
existingFieldNames: pattern.fields.map((field) => field.name),
};
}
const body: Record<string, string | object> = {
dslQuery,
fromDate: dateRange.fromDate,
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/lens/public/indexpattern_datasource/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const createMockedIndexPattern = (): IndexPattern => ({
id: '1',
title: 'my-fake-index-pattern',
timeFieldName: 'timestamp',
hasRestrictions: false,
fields: [
{
name: 'timestamp',
Expand Down Expand Up @@ -70,6 +71,7 @@ export const createMockedRestrictedIndexPattern = () => ({
id: '2',
title: 'my-fake-restricted-pattern',
timeFieldName: 'timestamp',
hasRestrictions: true,
fields: [
{
name: 'timestamp',
Expand Down
Loading

0 comments on commit ddf99b6

Please sign in to comment.