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

[Workspace]Change workspace description field to textarea #6907

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
2 changes: 2 additions & 0 deletions changelogs/fragments/6907.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- [Workspace] Change description field to textarea ([#6907](/~https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6907))
Original file line number Diff line number Diff line change
Expand Up @@ -116,23 +116,6 @@ describe('WorkspaceCreator', () => {
expect(workspaceClientCreate).not.toHaveBeenCalled();
});

it('should not create workspace with invalid description', async () => {
const { getByTestId } = render(
<WorkspaceCreator
workspaceConfigurableApps$={new BehaviorSubject([...PublicAPPInfoMap.values()])}
/>
);
const nameInput = getByTestId('workspaceForm-workspaceDetails-nameInputText');
fireEvent.input(nameInput, {
target: { value: 'test workspace name' },
});
const descriptionInput = getByTestId('workspaceForm-workspaceDetails-descriptionInputText');
fireEvent.input(descriptionInput, {
target: { value: '~' },
});
expect(workspaceClientCreate).not.toHaveBeenCalled();
});

it('cancel create workspace', async () => {
const { findByText, getByTestId } = render(
<WorkspaceCreator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,6 @@ describe('useWorkspaceForm', () => {
});
expect(onSubmitMock).not.toHaveBeenCalled();
});
it('should return "Invalid workspace description" and not call onSubmit when invalid description', async () => {
const { renderResult, onSubmitMock } = setup({
id: 'foo',
name: 'test-workspace-name',
description: '~',
});
expect(renderResult.result.current.formErrors).toEqual({});

act(() => {
renderResult.result.current.handleFormSubmit({ preventDefault: jest.fn() });
});
expect(renderResult.result.current.formErrors).toEqual({
description: 'Invalid workspace description',
});
expect(onSubmitMock).not.toHaveBeenCalled();
});
it('should call onSubmit with workspace name and features', async () => {
const { renderResult, onSubmitMock } = setup({
id: 'foo',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
*/

import { useCallback, useState, FormEventHandler, useRef, useMemo, useEffect } from 'react';
import { htmlIdGenerator, EuiFieldTextProps, EuiColorPickerProps } from '@elastic/eui';
import {
htmlIdGenerator,
EuiFieldTextProps,
EuiColorPickerProps,
EuiTextAreaProps,
} from '@elastic/eui';
import { useApplications } from '../../hooks';
import { featureMatchesConfig } from '../../utils';

Expand Down Expand Up @@ -97,7 +102,7 @@ export const useWorkspaceForm = ({ application, defaultValues, onSubmit }: Works
setName(e.target.value);
}, []);

const handleDescriptionInputChange = useCallback<Required<EuiFieldTextProps>['onChange']>((e) => {
const handleDescriptionChange = useCallback<Required<EuiTextAreaProps>['onChange']>((e) => {
setDescription(e.target.value);
}, []);

Expand Down Expand Up @@ -136,6 +141,6 @@ export const useWorkspaceForm = ({ application, defaultValues, onSubmit }: Works
handleTabFeatureClick,
setPermissionSettings,
handleTabPermissionClick,
handleDescriptionInputChange,
handleDescriptionChange,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,6 @@ describe('validateWorkspaceForm', () => {
it('should return error if name is invalid', () => {
expect(validateWorkspaceForm({ name: '~' }).name).toEqual('Invalid workspace name');
});
it('should return error if description is invalid', () => {
expect(validateWorkspaceForm({ description: '~' }).description).toEqual(
'Invalid workspace description'
);
});
it('should return error if permission setting type is invalid', () => {
expect(
validateWorkspaceForm({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,6 @@ export const validateWorkspaceForm = (
defaultMessage: "Name can't be empty.",
});
}
if (description && !isValidFormTextInput(description)) {
formErrors.description = i18n.translate('workspace.form.detail.description.invalid', {
defaultMessage: 'Invalid workspace description',
});
}
if (permissionSettings) {
const permissionSettingsErrors: { [key: number]: string } = {};
for (let i = 0; i < permissionSettings.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
EuiHorizontalRule,
EuiTab,
EuiTabs,
EuiTextArea,
} from '@elastic/eui';
import { i18n } from '@osd/i18n';

Expand Down Expand Up @@ -47,7 +48,7 @@ export const WorkspaceForm = (props: WorkspaceFormProps) => {
handleTabFeatureClick,
setPermissionSettings,
handleTabPermissionClick,
handleDescriptionInputChange,
handleDescriptionChange,
} = useWorkspaceForm(props);
const workspaceDetailsTitle = i18n.translate('workspace.form.workspaceDetails.title', {
defaultMessage: 'Workspace Details',
Expand Down Expand Up @@ -91,18 +92,29 @@ export const WorkspaceForm = (props: WorkspaceFormProps) => {
Description - <i>optional</i>
</>
}
helpText={i18n.translate('workspace.form.workspaceDetails.description.helpText', {
defaultMessage:
'Valid characters are a-z, A-Z, 0-9, (), [], _ (underscore), - (hyphen) and (space).',
})}
isInvalid={!!formErrors.description}
error={formErrors.description}
>
<EuiFieldText
value={formData.description}
onChange={handleDescriptionInputChange}
data-test-subj="workspaceForm-workspaceDetails-descriptionInputText"
/>
<>
<EuiText size="xs" color="subdued">
{i18n.translate('workspace.form.workspaceDetails.description.introduction', {
defaultMessage:
'Help others understand the purpose of this workspace by providing an overview of the workspace you’re creating.',
})}
</EuiText>
<EuiTextArea
value={formData.description}
onChange={handleDescriptionChange}
data-test-subj="workspaceForm-workspaceDetails-descriptionInputText"
rows={4}
placeholder={i18n.translate(
'workspace.form.workspaceDetails.description.placeholder',
{
defaultMessage: 'Describe the workspace',
}
)}
/>
</>
</EuiFormRow>
<EuiFormRow
label={i18n.translate('workspace.form.workspaceDetails.color.label', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,23 +138,6 @@ describe('WorkspaceUpdater', () => {
expect(workspaceClientUpdate).not.toHaveBeenCalled();
});

it('cannot update workspace with invalid description', async () => {
const { getByTestId } = render(
<WorkspaceUpdater
workspaceConfigurableApps$={new BehaviorSubject([...PublicAPPInfoMap.values()])}
/>
);
const nameInput = getByTestId('workspaceForm-workspaceDetails-nameInputText');
fireEvent.input(nameInput, {
target: { value: 'test workspace name' },
});
const descriptionInput = getByTestId('workspaceForm-workspaceDetails-descriptionInputText');
fireEvent.input(descriptionInput, {
target: { value: '~' },
});
expect(workspaceClientUpdate).not.toHaveBeenCalled();
});

it('cancel update workspace', async () => {
const { findByText, getByTestId } = render(
<WorkspaceUpdater
Expand Down
Loading