Skip to content

Commit

Permalink
Merge branch 'main' into case-screenshot-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lcawl authored Sep 24, 2024
2 parents ca3b449 + ed9c3b5 commit 1ab44b5
Show file tree
Hide file tree
Showing 33 changed files with 714 additions and 521 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import {
EuiFlyoutBody,
EuiFlyoutFooter,
EuiFlyoutHeader,
EuiFormControlLayout,
EuiFormRow,
EuiSwitch,
EuiTextArea,
Expand Down Expand Up @@ -128,48 +127,46 @@ export const SavedBookEditor = ({
</EuiTitle>
</EuiFlyoutHeader>
<EuiFlyoutBody>
<EuiFormControlLayout>
<EuiFormRow
label={i18n.translate('embeddableExamples.savedBook.editor.authorLabel', {
defaultMessage: 'Author',
})}
>
<EuiFieldText
value={authorName ?? ''}
onChange={(e) => attributesManager.authorName.next(e.target.value)}
/>
</EuiFormRow>
<EuiFormRow
label={i18n.translate('embeddableExamples.savedBook.editor.titleLabel', {
defaultMessage: 'Title',
})}
>
<EuiFieldText
value={bookTitle ?? ''}
onChange={(e) => attributesManager.bookTitle.next(e.target.value)}
/>
</EuiFormRow>
<EuiFormRow
label={i18n.translate('embeddableExamples.savedBook.editor.pagesLabel', {
defaultMessage: 'Number of pages',
})}
>
<EuiFieldNumber
value={numberOfPages ?? ''}
onChange={(e) => attributesManager.numberOfPages.next(+e.target.value)}
/>
</EuiFormRow>
<EuiFormRow
label={i18n.translate('embeddableExamples.savedBook.editor.synopsisLabel', {
defaultMessage: 'Synopsis',
})}
>
<EuiTextArea
value={synopsis ?? ''}
onChange={(e) => attributesManager.bookSynopsis.next(e.target.value)}
/>
</EuiFormRow>
</EuiFormControlLayout>
<EuiFormRow
label={i18n.translate('embeddableExamples.savedBook.editor.authorLabel', {
defaultMessage: 'Author',
})}
>
<EuiFieldText
value={authorName ?? ''}
onChange={(e) => attributesManager.authorName.next(e.target.value)}
/>
</EuiFormRow>
<EuiFormRow
label={i18n.translate('embeddableExamples.savedBook.editor.titleLabel', {
defaultMessage: 'Title',
})}
>
<EuiFieldText
value={bookTitle ?? ''}
onChange={(e) => attributesManager.bookTitle.next(e.target.value)}
/>
</EuiFormRow>
<EuiFormRow
label={i18n.translate('embeddableExamples.savedBook.editor.pagesLabel', {
defaultMessage: 'Number of pages',
})}
>
<EuiFieldNumber
value={numberOfPages ?? ''}
onChange={(e) => attributesManager.numberOfPages.next(+e.target.value)}
/>
</EuiFormRow>
<EuiFormRow
label={i18n.translate('embeddableExamples.savedBook.editor.synopsisLabel', {
defaultMessage: 'Synopsis',
})}
>
<EuiTextArea
value={synopsis ?? ''}
onChange={(e) => attributesManager.bookSynopsis.next(e.target.value)}
/>
</EuiFormRow>
</EuiFlyoutBody>
<EuiFlyoutFooter>
<EuiFlexGroup justifyContent="spaceBetween">
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1814,7 +1814,7 @@
"swagger-ui-express": "^5.0.1",
"table": "^6.8.1",
"tape": "^5.0.1",
"terser": "^5.32.0",
"terser": "^5.33.0",
"terser-webpack-plugin": "^4.2.3",
"tough-cookie": "^5.0.0",
"tree-kill": "^1.2.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@
margin-top: $euiSizeS;
}

.lnsConfigPanelNoPadding {
padding: 0;
}

.lnsConfigPanelDate__label {
min-width: 56px; // makes both labels ("from" and "to") the same width
.lnsConfigPanelAnnotations__date .euiFormControlLayout__prepend {
min-width: $euiSize * 3.25; // makes both labels ("from" and "to") the same width
}

.lnsConfigPanelAnnotations__addButton {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@

import { i18n } from '@kbn/i18n';
import React from 'react';
import {
EuiFormRow,
EuiSwitch,
EuiText,
EuiFormControlLayout,
EuiFormLabel,
EuiDatePicker,
} from '@elastic/eui';
import { EuiFormRow, EuiSwitch, EuiText, EuiDatePicker } from '@elastic/eui';
import moment from 'moment';
import type {
PointInTimeEventAnnotationConfig,
Expand Down Expand Up @@ -107,36 +100,23 @@ export const ConfigPanelRangeDatePicker = ({
dataTestSubj?: string;
}) => {
return (
<EuiFormRow display="rowCompressed" fullWidth label={label} className="lnsRowCompressedMargin">
{prependLabel ? (
<EuiFormControlLayout
fullWidth
className="lnsConfigPanelNoPadding"
prepend={
<EuiFormLabel className="lnsConfigPanelDate__label">{prependLabel}</EuiFormLabel>
}
>
<EuiDatePicker
calendarClassName={calendarClassName}
fullWidth
showTimeSelect
selected={value}
onChange={onChange}
dateFormat="MMM D, YYYY @ HH:mm:ss.SSS"
data-test-subj={dataTestSubj}
/>
</EuiFormControlLayout>
) : (
<EuiDatePicker
calendarClassName={calendarClassName}
fullWidth
showTimeSelect
selected={value}
onChange={onChange}
dateFormat="MMM D, YYYY @ HH:mm:ss.SSS"
data-test-subj={dataTestSubj}
/>
)}
<EuiFormRow
display="rowCompressed"
fullWidth
label={label}
className="lnsConfigPanelAnnotations__date lnsRowCompressedMargin"
>
<EuiDatePicker
compressed
calendarClassName={calendarClassName}
fullWidth
showTimeSelect
selected={value}
onChange={onChange}
dateFormat="MMM D, YYYY @ HH:mm:ss.SSS"
data-test-subj={dataTestSubj}
prepend={prependLabel}
/>
</EuiFormRow>
);
};
5 changes: 5 additions & 0 deletions src/plugins/discover/public/build_services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ import type { DiscoverContextAppLocator } from './application/context/services/l
import type { DiscoverSingleDocLocator } from './application/doc/locator';
import type { DiscoverAppLocator } from '../common';
import type { ProfilesManager } from './context_awareness';
import type { DiscoverEBTContextManager } from './services/discover_ebt_context_manager';

/**
* Location state of internal Discover history instance
Expand Down Expand Up @@ -130,6 +131,7 @@ export interface DiscoverServices {
noDataPage?: NoDataPagePluginStart;
observabilityAIAssistant?: ObservabilityAIAssistantPublicStart;
profilesManager: ProfilesManager;
ebtContextManager: DiscoverEBTContextManager;
fieldsMetadata?: FieldsMetadataPublicStart;
}

Expand All @@ -145,6 +147,7 @@ export const buildServices = memoize(
scopedHistory,
urlTracker,
profilesManager,
ebtContextManager,
setHeaderActionMenu = noop,
}: {
core: CoreStart;
Expand All @@ -157,6 +160,7 @@ export const buildServices = memoize(
scopedHistory?: ScopedHistory;
urlTracker: UrlTracker;
profilesManager: ProfilesManager;
ebtContextManager: DiscoverEBTContextManager;
setHeaderActionMenu?: AppMountParameters['setHeaderActionMenu'];
}): DiscoverServices => {
const { usageCollection } = plugins;
Expand Down Expand Up @@ -217,6 +221,7 @@ export const buildServices = memoize(
noDataPage: plugins.noDataPage,
observabilityAIAssistant: plugins.observabilityAIAssistant,
profilesManager,
ebtContextManager,
fieldsMetadata: plugins.fieldsMetadata,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
SolutionType,
} from '../profiles';
import { ProfilesManager } from '../profiles_manager';
import { DiscoverEBTContextManager } from '../../services/discover_ebt_context_manager';
import { createLogsContextServiceMock } from '@kbn/discover-utils/src/__mocks__';

export const createContextAwarenessMocks = ({
Expand Down Expand Up @@ -150,10 +151,12 @@ export const createContextAwarenessMocks = ({
documentProfileServiceMock.registerProvider(documentProfileProviderMock);
}

const ebtContextManagerMock = new DiscoverEBTContextManager();
const profilesManagerMock = new ProfilesManager(
rootProfileServiceMock,
dataSourceProfileServiceMock,
documentProfileServiceMock
documentProfileServiceMock,
ebtContextManagerMock
);

const profileProviderServices = createProfileProviderServicesMock();
Expand All @@ -169,6 +172,7 @@ export const createContextAwarenessMocks = ({
contextRecordMock2,
profilesManagerMock,
profileProviderServices,
ebtContextManagerMock,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('ProfilesManager', () => {
beforeEach(() => {
jest.clearAllMocks();
mocks = createContextAwarenessMocks();
jest.spyOn(mocks.ebtContextManagerMock, 'updateProfilesContextWith');
});

it('should return default profiles', () => {
Expand Down Expand Up @@ -60,6 +61,11 @@ describe('ProfilesManager', () => {
mocks.dataSourceProfileProviderMock.profile,
mocks.documentProfileProviderMock.profile,
]);

expect(mocks.ebtContextManagerMock.updateProfilesContextWith).toHaveBeenCalledWith([
'root-profile',
'data-source-profile',
]);
});

it('should expose profiles as an observable', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import type {
DocumentContext,
} from './profiles';
import type { ContextWithProfileId } from './profile_service';
import { DiscoverEBTContextManager } from '../services/discover_ebt_context_manager';

interface SerializedRootProfileParams {
solutionNavId: RootProfileProviderParams['solutionNavId'];
Expand Down Expand Up @@ -52,6 +53,7 @@ export interface GetProfilesOptions {
export class ProfilesManager {
private readonly rootContext$: BehaviorSubject<ContextWithProfileId<RootContext>>;
private readonly dataSourceContext$: BehaviorSubject<ContextWithProfileId<DataSourceContext>>;
private readonly ebtContextManager: DiscoverEBTContextManager;

private prevRootProfileParams?: SerializedRootProfileParams;
private prevDataSourceProfileParams?: SerializedDataSourceProfileParams;
Expand All @@ -61,10 +63,12 @@ export class ProfilesManager {
constructor(
private readonly rootProfileService: RootProfileService,
private readonly dataSourceProfileService: DataSourceProfileService,
private readonly documentProfileService: DocumentProfileService
private readonly documentProfileService: DocumentProfileService,
ebtContextManager: DiscoverEBTContextManager
) {
this.rootContext$ = new BehaviorSubject(rootProfileService.defaultContext);
this.dataSourceContext$ = new BehaviorSubject(dataSourceProfileService.defaultContext);
this.ebtContextManager = ebtContextManager;
}

/**
Expand Down Expand Up @@ -130,6 +134,7 @@ export class ProfilesManager {
return;
}

this.trackActiveProfiles(this.rootContext$.getValue().profileId, context.profileId);
this.dataSourceContext$.next(context);
this.prevDataSourceProfileParams = serializedParams;
}
Expand Down Expand Up @@ -194,6 +199,15 @@ export class ProfilesManager {
map(() => this.getProfiles(options))
);
}

/**
* Tracks the active profiles in the EBT context
*/
private trackActiveProfiles(rootContextProfileId: string, dataSourceContextProfileId: string) {
const dscProfiles = [rootContextProfileId, dataSourceContextProfileId];

this.ebtContextManager.updateProfilesContextWith(dscProfiles);
}
}

const serializeRootProfileParams = (
Expand Down
Loading

0 comments on commit 1ab44b5

Please sign in to comment.