Skip to content

Commit

Permalink
marking optional fields optional
Browse files Browse the repository at this point in the history
  • Loading branch information
drewdaemon committed May 26, 2023
1 parent 5e7814a commit f8cdd41
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { i18n } from '@kbn/i18n';
import React, { Fragment } from 'react';
import { FormattedMessage } from '@kbn/i18n-react';
import { EuiFormRow, EuiTextArea, EuiSwitch } from '@elastic/eui';
import { EuiFormRow, EuiSwitch } from '@elastic/eui';
import { SavedObjectSaveModal } from '@kbn/saved-objects-plugin/public';

import type { DashboardSaveOptions } from '../../../types';
Expand Down Expand Up @@ -39,14 +39,12 @@ interface Props {
}

interface State {
description: string;
tags: string[];
timeRestore: boolean;
}

export class DashboardSaveModal extends React.Component<Props, State> {
state: State = {
description: this.props.description,
timeRestore: this.props.timeRestore,
tags: this.props.tags ?? [],
};
Expand All @@ -57,18 +55,20 @@ export class DashboardSaveModal extends React.Component<Props, State> {

saveDashboard = ({
newTitle,
newDescription,
newCopyOnSave,
isTitleDuplicateConfirmed,
onTitleDuplicate,
}: {
newTitle: string;
newDescription: string;
newCopyOnSave: boolean;
isTitleDuplicateConfirmed: boolean;
onTitleDuplicate: () => void;
}) => {
this.props.onSave({
newTitle,
newDescription: this.state.description,
newDescription,
newCopyOnSave,
newTimeRestore: this.state.timeRestore,
isTitleDuplicateConfirmed,
Expand All @@ -77,12 +77,6 @@ export class DashboardSaveModal extends React.Component<Props, State> {
});
};

onDescriptionChange = (event: any) => {
this.setState({
description: event.target.value,
});
};

onTimeRestoreChange = (event: any) => {
this.setState({
timeRestore: event.target.checked,
Expand All @@ -102,28 +96,12 @@ export class DashboardSaveModal extends React.Component<Props, State> {
tags,
});
}}
markOptional
/>
) : undefined;

return (
<Fragment>
<EuiFormRow
label={
<FormattedMessage
id="dashboard.topNav.saveModal.descriptionFormRowLabel"
defaultMessage="Description"
/>
}
fullWidth
>
<EuiTextArea
fullWidth
data-test-subj="dashboardDescription"
value={this.state.description}
onChange={this.onDescriptionChange}
/>
</EuiFormRow>

{tagSelector}

<EuiFormRow
Expand Down Expand Up @@ -156,13 +134,14 @@ export class DashboardSaveModal extends React.Component<Props, State> {
onSave={this.saveDashboard}
onClose={this.props.onClose}
title={this.props.title}
description={this.props.description}
showDescription
showCopyOnSave={this.props.showCopyOnSave}
initialCopyOnSave={this.props.showCopyOnSave}
objectType={i18n.translate('dashboard.topNav.saveModal.objectType', {
defaultMessage: 'dashboard',
})}
options={this.renderDashboardSaveOptions()}
showDescription={false}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ export class SavedObjectSaveModal extends React.Component<Props, SaveModalState>
return (
<EuiFormRow
fullWidth
labelAppend={
<EuiText size="xs" color="subdued">
<FormattedMessage id="savedObjects.saveModal.optional" defaultMessage="Optional" />
</EuiText>
}
label={
<FormattedMessage
id="savedObjects.saveModal.descriptionLabel"
Expand Down
5 changes: 5 additions & 0 deletions src/plugins/saved_objects_tagging_oss/public/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,11 @@ export type SavedObjectSaveModalTagSelectorComponentProps = EuiComboBoxProps<
* tags selection callback
*/
onTagsSelected: (ids: string[]) => void;

/**
* Add "Optional" to the label
*/
markOptional?: boolean;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ export const getTopNavConfig = (
onTagsSelected={(newSelection) => {
selectedTags = newSelection;
}}
markOptional
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const TagEnhancedSavedObjectSaveModalDashboard: FC<
<savedObjectsTagging.ui.components.SavedObjectSaveModalTagSelector
initialSelection={initialTags}
onTagsSelected={setSelectedTags}
markOptional
/>
) : undefined,
[savedObjectsTagging, initialTags]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const SaveModal = ({
<savedObjectsTagging.ui.components.SavedObjectSaveModalTagSelector
initialSelection={selectedTags}
onTagsSelected={setSelectedTags}
markOptional
/>
) : undefined
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export function getTopNavConfig({
<savedObjectsTagging.ui.components.SavedObjectSaveModalTagSelector
initialSelection={selectedTags}
onTagsSelected={onTagsSelected}
markOptional
/>
) : undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React, { FC, useCallback, useState } from 'react';
import useObservable from 'react-use/lib/useObservable';
import { EuiFormRow } from '@elastic/eui';
import { EuiFormRow, EuiText } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { SavedObjectSaveModalTagSelectorComponentProps } from '@kbn/saved-objects-tagging-oss-plugin/public';
import { TagsCapabilities } from '../../../common';
Expand All @@ -29,6 +29,7 @@ export const getConnectedSavedObjectModalTagSelectorComponent = ({
return ({
initialSelection,
onTagsSelected: notifySelectionChange,
markOptional,
...rest
}: SavedObjectSaveModalTagSelectorComponentProps) => {
const tags = useObservable(cache.getState$(), cache.getState());
Expand All @@ -51,6 +52,16 @@ export const getConnectedSavedObjectModalTagSelectorComponent = ({
defaultMessage="Tags"
/>
}
labelAppend={
markOptional && (
<EuiText color="subdued" size="xs">
<FormattedMessage
id="xpack.savedObjectsTagging.uiApi.saveModal.optional"
defaultMessage="Optional"
/>
</EuiText>
)
}
>
<TagSelector
selected={selected}
Expand Down

0 comments on commit f8cdd41

Please sign in to comment.