Skip to content

Commit

Permalink
Merge branch 'main' into fix-exception-autopopulate-comment
Browse files Browse the repository at this point in the history
  • Loading branch information
WafaaNasr authored Jul 3, 2023
2 parents 7d0ec18 + a81287f commit 233dbbb
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const ConnectorConfiguration: React.FC = () => {
<EuiText size="s">
<FormattedMessage
id="xpack.enterpriseSearch.content.indices.configurationConnector.connectorPackage.description.secondParagraph"
defaultMessage="The connectors repository contains several {link}. Use our framework for accelerated development against custom data sources."
defaultMessage="The connectors repository contains several {link}. Use our framework to accelerate developing connectors for custom data sources."
values={{
link: (
<EuiLink
Expand Down Expand Up @@ -167,7 +167,7 @@ service_type: "${index.connector.service_type || 'changeme'}"
'xpack.enterpriseSearch.content.indices.configurationConnector.connectorPackage.connectorDeployedText',
{
defaultMessage:
'Once you’ve configured the connector, deploy the connector to your self managed infrastructure.',
'Once configured, deploy the connector on your infrastructure.',
}
)}
</EuiText>
Expand All @@ -180,7 +180,7 @@ service_type: "${index.connector.service_type || 'changeme'}"
title: i18n.translate(
'xpack.enterpriseSearch.content.indices.configurationConnector.steps.deployConnector.title',
{
defaultMessage: 'Deploy a connector',
defaultMessage: 'Deploy connector',
}
),
titleSize: 'xs',
Expand Down Expand Up @@ -325,7 +325,7 @@ service_type: "${index.connector.service_type || 'changeme'}"
'xpack.enterpriseSearch.content.indices.configurationConnector.support.description',
{
defaultMessage:
'Your connector will have to be deployed to your own infrastructure.',
'You need to deploy this connector on your own infrastructure.',
}
)}
</EuiText>
Expand All @@ -345,7 +345,7 @@ service_type: "${index.connector.service_type || 'changeme'}"
{i18n.translate(
'xpack.enterpriseSearch.content.indices.configurationConnector.support.manageKeys.label',
{
defaultMessage: 'Manage keys',
defaultMessage: 'Manage API keys',
}
)}
</EuiLinkTo>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,14 @@ export const Tile = ({

const filters = useMemo(() => {
return [
...searchCriteria.filters,
buildCombinedHostsFilter({
field: 'host.name',
values: hostNodes.map((p) => p.name),
dataView,
}),
];
}, [hostNodes, dataView]);
}, [searchCriteria.filters, hostNodes, dataView]);

const handleBrushEnd = useCallback(
({ range }: BrushTriggerEvent['data']) => {
Expand Down Expand Up @@ -122,9 +123,10 @@ export const Tile = ({
() =>
getExtraActions({
timeRange: afterLoadedState.dateRange,
query: searchCriteria.query,
filters,
}),
[afterLoadedState.dateRange, filters, getExtraActions]
[afterLoadedState.dateRange, filters, getExtraActions, searchCriteria.query]
);

return (
Expand Down Expand Up @@ -168,6 +170,7 @@ export const Tile = ({
lastReloadRequestTime={afterLoadedState.lastReloadRequestTime}
dateRange={afterLoadedState.dateRange}
filters={afterLoadedState.filters}
query={afterLoadedState.query}
onBrushEnd={handleBrushEnd}
loading={loading}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,23 @@ export const MetricChart = ({ title, type, breakdownSize }: MetricChartProps) =>

const filters = useMemo(() => {
return [
...searchCriteria.filters,
buildCombinedHostsFilter({
field: 'host.name',
values: currentPage.map((p) => p.name),
dataView,
}),
];
}, [currentPage, dataView]);
}, [currentPage, dataView, searchCriteria.filters]);

const extraActions: Action[] = useMemo(
() =>
getExtraActions({
timeRange: afterLoadedState.dateRange,
query: afterLoadedState.query,
filters,
}),
[afterLoadedState.dateRange, filters, getExtraActions]
[afterLoadedState.dateRange, afterLoadedState.query, filters, getExtraActions]
);

const handleBrushEnd = useCallback(
Expand Down Expand Up @@ -137,6 +139,7 @@ export const MetricChart = ({ title, type, breakdownSize }: MetricChartProps) =>
lastReloadRequestTime={afterLoadedState.lastReloadRequestTime}
dateRange={afterLoadedState.dateRange}
filters={filters}
query={afterLoadedState.query}
onBrushEnd={handleBrushEnd}
loading={loading}
hasTitle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,20 @@ describe('useUserProfileForm', () => {
<UserProfile user={nonCloudUser} data={data} />
</Providers>
);
const darkModeButton = testWrapper.find('EuiButtonGroup[data-test-subj="darkModeButton"]');
expect(darkModeButton).toBeTruthy();
expect(darkModeButton.getDOMNode()).not.toBeDisabled();

const overrideMsg = testWrapper.find('EuiText[data-test-subj="themeOverrideMessage"]');
expect(overrideMsg).toHaveLength(0);

const themeMenu = testWrapper.find('EuiKeyPadMenu[data-test-subj="themeMenu"]');
expect(themeMenu).toHaveLength(1);

const themeOptions = themeMenu.find('EuiKeyPadMenuItem');
expect(themeOptions).toHaveLength(3);
themeOptions.forEach((option) => {
expect(option.getDOMNode().classList.contains('euiKeyPadMenuItem-isDisabled')).toEqual(
false
);
});
});

it('should not display if the User is a cloud user', () => {
Expand All @@ -281,7 +292,7 @@ describe('useUserProfileForm', () => {
</Providers>
);

expect(testWrapper.exists('EuiButtonGroup[data-test-subj="darkModeButton"]')).toBeFalsy();
expect(testWrapper.exists('EuiButtonGroup[data-test-subj="themeMenu"]')).toBeFalsy();
});

it('should add special toast after submitting form successfully since darkMode requires a refresh', async () => {
Expand Down Expand Up @@ -314,8 +325,8 @@ describe('useUserProfileForm', () => {
const data: UserProfileData = {};

const nonCloudUser = mockAuthenticatedUser({ elastic_cloud_user: false });
coreStart.settings.client.get.mockReturnValueOnce(true);
coreStart.settings.client.isOverridden.mockReturnValueOnce(true);
coreStart.settings.client.get.mockReturnValue(true);
coreStart.settings.client.isOverridden.mockReturnValue(true);

const testWrapper = mount(
<Providers
Expand All @@ -332,17 +343,27 @@ describe('useUserProfileForm', () => {
</Providers>
);

const darkModeButton = testWrapper.find('EuiButtonGroup[data-test-subj="darkModeButton"]');
expect(darkModeButton).toBeTruthy();
expect(darkModeButton.getDOMNode()).toHaveProperty('disabled');
const overrideMsg = testWrapper.find('EuiIconTip[data-test-subj="themeOverrideTooltip"]');
expect(overrideMsg).toHaveLength(1);

const themeMenu = testWrapper.find('EuiKeyPadMenu[data-test-subj="themeMenu"]');
expect(themeMenu).toHaveLength(1);

const themeOptions = themeMenu.find('EuiKeyPadMenuItem');
expect(themeOptions).toHaveLength(3);
themeOptions.forEach((option) => {
expect(option.getDOMNode().classList.contains('euiKeyPadMenuItem-isDisabled')).toEqual(
true
);
});
});

it('should be disabled if the theme has been set to `darkMode: false` in the config', () => {
const data: UserProfileData = {};

const nonCloudUser = mockAuthenticatedUser({ elastic_cloud_user: false });
coreStart.settings.client.get.mockReturnValueOnce(false);
coreStart.settings.client.isOverridden.mockReturnValueOnce(true);
coreStart.settings.client.get.mockReturnValue(false);
coreStart.settings.client.isOverridden.mockReturnValue(true);

const testWrapper = mount(
<Providers
Expand All @@ -359,9 +380,19 @@ describe('useUserProfileForm', () => {
</Providers>
);

const darkModeButton = testWrapper.find('EuiButtonGroup[data-test-subj="darkModeButton"]');
expect(darkModeButton).toBeTruthy();
expect(darkModeButton.getDOMNode()).toHaveProperty('disabled');
const overrideMsg = testWrapper.find('EuiIconTip[data-test-subj="themeOverrideTooltip"]');
expect(overrideMsg).toHaveLength(1);

const themeMenu = testWrapper.find('EuiKeyPadMenu[data-test-subj="themeMenu"]');
expect(themeMenu).toHaveLength(1);

const themeOptions = themeMenu.find('EuiKeyPadMenuItem');
expect(themeOptions).toHaveLength(3);
themeOptions.forEach((option) => {
expect(option.getDOMNode().classList.contains('euiKeyPadMenuItem-isDisabled')).toEqual(
true
);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
EuiFormRow,
EuiIcon,
EuiIconTip,
EuiKeyPadMenu,
EuiKeyPadMenuItem,
EuiPageTemplate_Deprecated as EuiPageTemplate,
EuiSpacer,
EuiText,
Expand Down Expand Up @@ -165,6 +167,27 @@ function UserSettingsEditor({
}
}

interface ThemeKeyPadItem {
id: string;
label: string;
icon: string;
}

const themeKeyPadMenuItem = ({ id, label, icon }: ThemeKeyPadItem) => {
return (
<EuiKeyPadMenuItem
name={id}
label={label}
checkable="single"
isSelected={idSelected === id}
isDisabled={isThemeOverridden}
onChange={() => formik.setFieldValue('data.userSettings.darkMode', id)}
>
<EuiIcon type={icon} size="l" />
</EuiKeyPadMenuItem>
);
};

return (
<EuiDescribedFormGroup
fullWidth
Expand All @@ -186,62 +209,56 @@ function UserSettingsEditor({
>
<FormRow
name="data.userSettings.darkMode"
helpText={renderHelpText(isThemeOverridden)}
label={
<FormLabel for="data.userSettings.darkMode">
<FormattedMessage
id="xpack.security.accountManagement.userProfile.userSettings.theme"
defaultMessage="Mode"
/>
</FormLabel>
<EuiFlexGroup alignItems="center" gutterSize="s" responsive={false}>
<EuiFlexItem grow={false}>
<FormLabel for="data.userSettings.darkMode">
<FormattedMessage
id="xpack.security.accountManagement.userProfile.userSettings.theme"
defaultMessage="Mode"
/>
</FormLabel>
</EuiFlexItem>
<EuiFlexItem grow={false}>{renderHelpText(isThemeOverridden)}</EuiFlexItem>
</EuiFlexGroup>
}
fullWidth
>
<EuiButtonGroup
legend={i18n.translate(
<EuiKeyPadMenu
aria-label={i18n.translate(
'xpack.security.accountManagement.userProfile.userSettings.themeGroupDescription',
{
defaultMessage: 'Elastic theme',
}
)}
buttonSize="m"
data-test-subj="darkModeButton"
idSelected={idSelected}
isDisabled={isThemeOverridden}
options={[
{
id: '',
label: (
<FormattedMessage
id="xpack.security.accountManagement.userProfile.defaultModeButton"
defaultMessage="Space default"
/>
),
},
{
id: 'light',
label: (
<FormattedMessage
id="xpack.security.accountManagement.userProfile.lightModeButton"
defaultMessage="Light"
/>
),
iconType: 'sun',
},
{
id: 'dark',
label: (
<FormattedMessage
id="xpack.security.accountManagement.userProfile.darkModeButton"
defaultMessage="Dark"
/>
),
iconType: 'moon',
},
]}
onChange={(id: string) => formik.setFieldValue('data.userSettings.darkMode', id)}
isFullWidth
/>
data-test-subj="themeMenu"
checkable={true}
>
{themeKeyPadMenuItem({
id: '',
label: i18n.translate(
'xpack.security.accountManagement.userProfile.defaultModeButton',
{
defaultMessage: 'Space default',
}
),
icon: 'spaces',
})}
{themeKeyPadMenuItem({
id: 'light',
label: i18n.translate('xpack.security.accountManagement.userProfile.lightModeButton', {
defaultMessage: 'Light',
}),
icon: 'sun',
})}
{themeKeyPadMenuItem({
id: 'dark',
label: i18n.translate('xpack.security.accountManagement.userProfile.darkModeButton', {
defaultMessage: 'Dark',
}),
icon: 'moon',
})}
</EuiKeyPadMenu>
</FormRow>
</EuiDescribedFormGroup>
);
Expand Down Expand Up @@ -912,12 +929,23 @@ export const SaveChangesBottomBar: FunctionComponent = () => {
function renderHelpText(isOverridden: boolean) {
if (isOverridden) {
return (
<EuiText size="xs">
<FormattedMessage
id="xpack.security.accountManagement.userProfile.overriddenMessage"
defaultMessage="This setting is overridden by the Kibana server and can not be changed."
/>
</EuiText>
<EuiIconTip
data-test-subj="themeOverrideTooltip"
aria-label={i18n.translate(
'xpack.security.accountManagement.userProfile.themeModeLockedLabel',
{
defaultMessage: 'Theme mode locked',
}
)}
size="s"
type="lock"
content={
<FormattedMessage
id="xpack.security.accountManagement.userProfile.overriddenMessage"
defaultMessage="This setting is overridden by the Kibana server and can not be changed."
/>
}
/>
);
}
}
Expand Down

0 comments on commit 233dbbb

Please sign in to comment.