Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] [SR] Add tooltips for disabled fields on managed SLM repository and policy (#196565) #197882

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React, { ReactElement } from 'react';
import { EuiToolTip } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

export const MANAGED_REPOSITORY_TOOLTIP_MESSAGE = i18n.translate(
'xpack.snapshotRestore.repositoryForm.disableToolTip',
{
defaultMessage: 'This field is disabled because you are editing a managed repository.',
}
);

export const MANAGED_POLICY_TOOLTIP_MESSAGE = i18n.translate(
'xpack.snapshotRestore.policyForm.disableToolTip',
{
defaultMessage: 'This field is disabled because you are editing a managed policy.',
}
);

interface Props {
isManaged?: boolean;
tooltipMessage: string;
component: ReactElement;
}

/**
* Component that wraps a given component (disabled field) with a tooltip if a repository
* or policy is managed (isManaged === true).
*
* @param {boolean} isManaged - Determines if the tooltip should be displayed.
* @param {string} tooltipMessage - The message to display inside the tooltip.
* @param {React.ReactElement} component - The component to wrap with the tooltip.
*/
export const DisableToolTip: React.FunctionComponent<Props> = ({
isManaged,
tooltipMessage,
component,
}) => {
return isManaged ? (
<EuiToolTip content={tooltipMessage} display="block">
{component}
</EuiToolTip>
) : (
component
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { useLoadRepositories } from '../../../services/http';
import { linkToAddRepository } from '../../../services/navigation';
import { InlineLoading } from '../..';
import { StepProps } from '.';
import { DisableToolTip, MANAGED_POLICY_TOOLTIP_MESSAGE } from '../../disable_tooltip';

export const PolicyStepLogistics: React.FunctionComponent<StepProps> = ({
policy,
Expand Down Expand Up @@ -258,22 +259,28 @@ export const PolicyStepLogistics: React.FunctionComponent<StepProps> = ({
}

return (
<EuiSelect
options={repositories.map(({ name }: Repository) => ({
value: name,
text: name,
}))}
hasNoInitialSelection={!doesRepositoryExist}
value={!doesRepositoryExist ? '' : policy.repository}
onBlur={() => setTouched({ ...touched, repository: true })}
onChange={(e) => {
updatePolicy({
repository: e.target.value,
});
}}
fullWidth
data-test-subj="repositorySelect"
disabled={policy?.isManagedPolicy && isEditing}
<DisableToolTip
isManaged={policy?.isManagedPolicy}
tooltipMessage={MANAGED_POLICY_TOOLTIP_MESSAGE}
component={
<EuiSelect
options={repositories.map(({ name }: Repository) => ({
value: name,
text: name,
}))}
hasNoInitialSelection={!doesRepositoryExist}
value={!doesRepositoryExist ? '' : policy.repository}
onBlur={() => setTouched({ ...touched, repository: true })}
onChange={(e) => {
updatePolicy({
repository: e.target.value,
});
}}
fullWidth
data-test-subj="repositorySelect"
disabled={policy?.isManagedPolicy && isEditing}
/>
}
/>
);
};
Expand Down Expand Up @@ -325,25 +332,31 @@ export const PolicyStepLogistics: React.FunctionComponent<StepProps> = ({
}
fullWidth
>
<EuiFieldText
defaultValue={policy.snapshotName}
fullWidth
onChange={(e) => {
updatePolicy({
snapshotName: e.target.value,
});
}}
onBlur={() => setTouched({ ...touched, snapshotName: true })}
placeholder={i18n.translate(
'xpack.snapshotRestore.policyForm.stepLogistics.policySnapshotNamePlaceholder',
{
defaultMessage: `'<daily-snap-{now/d}>'`,
description:
'Example date math snapshot name. Keeping the same syntax is important: <SOME-TRANSLATION-{now/d}>',
}
)}
data-test-subj="snapshotNameInput"
disabled={policy?.isManagedPolicy && isEditing}
<DisableToolTip
isManaged={policy?.isManagedPolicy}
tooltipMessage={MANAGED_POLICY_TOOLTIP_MESSAGE}
component={
<EuiFieldText
defaultValue={policy.snapshotName}
fullWidth
onChange={(e) => {
updatePolicy({
snapshotName: e.target.value,
});
}}
onBlur={() => setTouched({ ...touched, snapshotName: true })}
placeholder={i18n.translate(
'xpack.snapshotRestore.policyForm.stepLogistics.policySnapshotNamePlaceholder',
{
defaultMessage: `'<daily-snap-{now/d}>'`,
description:
'Example date math snapshot name. Keeping the same syntax is important: <SOME-TRANSLATION-{now/d}>',
}
)}
data-test-subj="snapshotNameInput"
disabled={policy?.isManagedPolicy && isEditing}
/>
}
/>
</EuiFormRow>
</EuiDescribedFormGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
import { AzureRepository, Repository } from '../../../../../common/types';
import { RepositorySettingsValidation } from '../../../services/validation';
import { ChunkSizeField, MaxSnapshotsField, MaxRestoreField } from './common';
import { DisableToolTip, MANAGED_REPOSITORY_TOOLTIP_MESSAGE } from '../../disable_tooltip';

interface Props {
repository: AzureRepository;
Expand Down Expand Up @@ -94,16 +95,22 @@ export const AzureSettings: React.FunctionComponent<Props> = ({
isInvalid={Boolean(hasErrors && settingErrors.client)}
error={settingErrors.client}
>
<EuiFieldText
defaultValue={client || ''}
fullWidth
onChange={(e) => {
updateRepositorySettings({
client: e.target.value,
});
}}
data-test-subj="clientInput"
disabled={isManagedRepository}
<DisableToolTip
isManaged={isManagedRepository}
tooltipMessage={MANAGED_REPOSITORY_TOOLTIP_MESSAGE}
component={
<EuiFieldText
defaultValue={client || ''}
fullWidth
onChange={(e) => {
updateRepositorySettings({
client: e.target.value,
});
}}
data-test-subj="clientInput"
disabled={isManagedRepository}
/>
}
/>
</EuiFormRow>
</EuiDescribedFormGroup>
Expand Down Expand Up @@ -139,16 +146,22 @@ export const AzureSettings: React.FunctionComponent<Props> = ({
isInvalid={Boolean(hasErrors && settingErrors.container)}
error={settingErrors.container}
>
<EuiFieldText
defaultValue={container || ''}
fullWidth
onChange={(e) => {
updateRepositorySettings({
container: e.target.value,
});
}}
data-test-subj="containerInput"
disabled={isManagedRepository}
<DisableToolTip
isManaged={isManagedRepository}
tooltipMessage={MANAGED_REPOSITORY_TOOLTIP_MESSAGE}
component={
<EuiFieldText
defaultValue={container || ''}
fullWidth
onChange={(e) => {
updateRepositorySettings({
container: e.target.value,
});
}}
data-test-subj="containerInput"
disabled={isManagedRepository}
/>
}
/>
</EuiFormRow>
</EuiDescribedFormGroup>
Expand Down Expand Up @@ -184,16 +197,22 @@ export const AzureSettings: React.FunctionComponent<Props> = ({
isInvalid={Boolean(hasErrors && settingErrors.basePath)}
error={settingErrors.basePath}
>
<EuiFieldText
defaultValue={basePath || ''}
fullWidth
onChange={(e) => {
updateRepositorySettings({
basePath: e.target.value,
});
}}
data-test-subj="basePathInput"
disabled={isManagedRepository}
<DisableToolTip
isManaged={isManagedRepository}
tooltipMessage={MANAGED_REPOSITORY_TOOLTIP_MESSAGE}
component={
<EuiFieldText
defaultValue={basePath || ''}
fullWidth
onChange={(e) => {
updateRepositorySettings({
basePath: e.target.value,
});
}}
data-test-subj="basePathInput"
disabled={isManagedRepository}
/>
}
/>
</EuiFormRow>
</EuiDescribedFormGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { EuiDescribedFormGroup, EuiFieldText, EuiFormRow, EuiSwitch, EuiTitle }
import { GCSRepository, Repository } from '../../../../../common/types';
import { RepositorySettingsValidation } from '../../../services/validation';
import { ChunkSizeField, MaxSnapshotsField, MaxRestoreField } from './common';
import { DisableToolTip, MANAGED_REPOSITORY_TOOLTIP_MESSAGE } from '../../disable_tooltip';

interface Props {
repository: GCSRepository;
Expand Down Expand Up @@ -82,16 +83,22 @@ export const GCSSettings: React.FunctionComponent<Props> = ({
isInvalid={Boolean(hasErrors && settingErrors.client)}
error={settingErrors.client}
>
<EuiFieldText
defaultValue={client || ''}
fullWidth
onChange={(e) => {
updateRepositorySettings({
client: e.target.value,
});
}}
data-test-subj="clientInput"
disabled={isManagedRepository}
<DisableToolTip
isManaged={isManagedRepository}
tooltipMessage={MANAGED_REPOSITORY_TOOLTIP_MESSAGE}
component={
<EuiFieldText
defaultValue={client || ''}
fullWidth
onChange={(e) => {
updateRepositorySettings({
client: e.target.value,
});
}}
data-test-subj="clientInput"
disabled={isManagedRepository}
/>
}
/>
</EuiFormRow>
</EuiDescribedFormGroup>
Expand Down Expand Up @@ -127,16 +134,22 @@ export const GCSSettings: React.FunctionComponent<Props> = ({
isInvalid={Boolean(hasErrors && settingErrors.bucket)}
error={settingErrors.bucket}
>
<EuiFieldText
defaultValue={bucket || ''}
fullWidth
onChange={(e) => {
updateRepositorySettings({
bucket: e.target.value,
});
}}
data-test-subj="bucketInput"
disabled={isManagedRepository}
<DisableToolTip
isManaged={isManagedRepository}
tooltipMessage={MANAGED_REPOSITORY_TOOLTIP_MESSAGE}
component={
<EuiFieldText
defaultValue={bucket || ''}
fullWidth
onChange={(e) => {
updateRepositorySettings({
bucket: e.target.value,
});
}}
data-test-subj="bucketInput"
disabled={isManagedRepository}
/>
}
/>
</EuiFormRow>
</EuiDescribedFormGroup>
Expand Down Expand Up @@ -172,16 +185,22 @@ export const GCSSettings: React.FunctionComponent<Props> = ({
isInvalid={Boolean(hasErrors && settingErrors.basePath)}
error={settingErrors.basePath}
>
<EuiFieldText
defaultValue={basePath || ''}
fullWidth
onChange={(e) => {
updateRepositorySettings({
basePath: e.target.value,
});
}}
data-test-subj="basePathInput"
disabled={isManagedRepository}
<DisableToolTip
isManaged={isManagedRepository}
tooltipMessage={MANAGED_REPOSITORY_TOOLTIP_MESSAGE}
component={
<EuiFieldText
defaultValue={basePath || ''}
fullWidth
onChange={(e) => {
updateRepositorySettings({
basePath: e.target.value,
});
}}
data-test-subj="basePathInput"
disabled={isManagedRepository}
/>
}
/>
</EuiFormRow>
</EuiDescribedFormGroup>
Expand Down
Loading