Skip to content

Commit

Permalink
chore: Changes the dashboard properties modal to use the new select c…
Browse files Browse the repository at this point in the history
…omponent (apache#16064)
  • Loading branch information
michael-s-molina authored Aug 6, 2021
1 parent 12f4ce8 commit 9dff62d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ test('should render - FeatureFlag disabled', async () => {
expect(screen.getByRole('button', { name: 'Save' })).toBeInTheDocument();
expect(screen.getAllByRole('button')).toHaveLength(4);

expect(screen.getAllByRole('textbox')).toHaveLength(3);
expect(screen.getAllByRole('textbox')).toHaveLength(2);
expect(screen.getByRole('combobox')).toBeInTheDocument();

expect(spyColorSchemeControlWrapper).toBeCalledTimes(4);
expect(spyColorSchemeControlWrapper).toBeCalledWith(
Expand Down Expand Up @@ -201,7 +202,8 @@ test('should render - FeatureFlag enabled', async () => {
expect(screen.getByRole('button', { name: 'Save' })).toBeInTheDocument();
expect(screen.getAllByRole('button')).toHaveLength(4);

expect(screen.getAllByRole('textbox')).toHaveLength(4);
expect(screen.getAllByRole('textbox')).toHaveLength(2);
expect(screen.getAllByRole('combobox')).toHaveLength(2);

expect(spyColorSchemeControlWrapper).toBeCalledTimes(4);
expect(spyColorSchemeControlWrapper).toBeCalledWith(
Expand All @@ -220,9 +222,11 @@ test('should open advance', async () => {
await screen.findByTestId('dashboard-edit-properties-form'),
).toBeInTheDocument();

expect(screen.getAllByRole('textbox')).toHaveLength(4);
expect(screen.getAllByRole('textbox')).toHaveLength(2);
expect(screen.getAllByRole('combobox')).toHaveLength(2);
userEvent.click(screen.getByRole('button', { name: 'Advanced' }));
expect(screen.getAllByRole('textbox')).toHaveLength(5);
expect(screen.getAllByRole('textbox')).toHaveLength(3);
expect(screen.getAllByRole('combobox')).toHaveLength(2);
});

test('should close modal', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { Row, Col, Input } from 'src/common/components';
import { Form, FormItem } from 'src/components/Form';
import jsonStringify from 'json-stringify-pretty-compact';
import Button from 'src/components/Button';
import { AsyncSelect } from 'src/components/Select';
import { Select } from 'src/components';
import rison from 'rison';
import {
styled,
Expand Down Expand Up @@ -91,18 +91,23 @@ const loadAccessOptions = accessType => (input = '') => {
return SupersetClient.get({
endpoint: `/api/v1/dashboard/related/${accessType}?q=${query}`,
}).then(
response =>
response.json.result.map(item => ({
response => ({
data: response.json.result.map(item => ({
value: item.value,
label: item.text,
})),
totalCount: response.json.count,
}),
badResponse => {
handleErrorResponse(badResponse);
return [];
},
);
};

const loadOwners = loadAccessOptions('owners');
const loadRoles = loadAccessOptions('roles');

class PropertiesModal extends React.PureComponent {
constructor(props) {
super(props);
Expand Down Expand Up @@ -326,16 +331,15 @@ class PropertiesModal extends React.PureComponent {
<Col xs={24} md={12}>
<h3 style={{ marginTop: '1em' }}>{t('Access')}</h3>
<FormItem label={t('Owners')}>
<AsyncSelect
<Select
allowClear
ariaLabel={t('Owners')}
disabled={!isDashboardLoaded}
name="owners"
isMulti
mode="multiple"
value={values.owners}
loadOptions={loadAccessOptions('owners')}
defaultOptions // load options on render
cacheOptions
options={loadOwners}
onChange={this.onOwnersChange}
disabled={!isDashboardLoaded}
filterOption={null} // options are filtered at the api
/>
<p className="help-block">
{t(
Expand Down Expand Up @@ -368,16 +372,15 @@ class PropertiesModal extends React.PureComponent {
<Row gutter={16}>
<Col xs={24} md={12}>
<FormItem label={t('Owners')}>
<AsyncSelect
<Select
allowClear
ariaLabel={t('Owners')}
disabled={!isDashboardLoaded}
name="owners"
isMulti
mode="multiple"
value={values.owners}
loadOptions={loadAccessOptions('owners')}
defaultOptions // load options on render
cacheOptions
options={loadOwners}
onChange={this.onOwnersChange}
disabled={!isDashboardLoaded}
filterOption={null} // options are filtered at the api
/>
<p className="help-block">
{t(
Expand All @@ -388,16 +391,15 @@ class PropertiesModal extends React.PureComponent {
</Col>
<Col xs={24} md={12}>
<FormItem label={t('Roles')}>
<AsyncSelect
<Select
allowClear
ariaLabel={t('Roles')}
disabled={!isDashboardLoaded}
name="roles"
isMulti
mode="multiple"
value={values.roles}
loadOptions={loadAccessOptions('roles')}
defaultOptions // load options on render
cacheOptions
options={loadRoles}
onChange={this.onRolesChange}
disabled={!isDashboardLoaded}
filterOption={null} // options are filtered at the api
/>
<p className="help-block">
{t(
Expand Down

0 comments on commit 9dff62d

Please sign in to comment.