Skip to content

Commit

Permalink
BUGIFX: ONE-3427 Fix typings on AttributeFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-nejezchleb committed Nov 13, 2018
1 parent f10f1e6 commit cf92447
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
11 changes: 8 additions & 3 deletions src/components/filters/AttributeFilter/AttributeFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export interface IAttributeFilterProps {
getObjectUri: Function;
getObjectDetails: Function;
};

onApply: Function;
fullscreenOnMobile?: boolean;
locale?: string;
FilterLoading?: any;
FilterError?: any;
Expand Down Expand Up @@ -50,7 +51,8 @@ export class AttributeFilter extends React.PureComponent<IAttributeFilterProps>
uri: PropTypes.string,
identifier: PropTypes.string,
projectId: PropTypes.string,

onApply: PropTypes.func.isRequired,
fullscreenOnMobile: PropTypes.bool,
FilterLoading: PropTypes.func,
FilterError: PropTypes.func,
locale: PropTypes.string
Expand All @@ -63,7 +65,8 @@ export class AttributeFilter extends React.PureComponent<IAttributeFilterProps>
locale: 'en-US',

FilterLoading: DefaultFilterLoading,
FilterError: DefaultFilterError
FilterError: DefaultFilterError,
fullscreenOnMobile: false
};

private sdk: SDK;
Expand Down Expand Up @@ -109,12 +112,14 @@ export class AttributeFilter extends React.PureComponent<IAttributeFilterProps>
this.props,
Object.keys(AttributeDropdownWrapped.propTypes)
);
const isUsingIdentifier = this.props.identifier !== null;
const { md } = this.sdk;
return (
<AttributeDropdown
attributeDisplayForm={attributeDisplayForm}
metadata={md}
{...dropdownProps}
isUsingIdentifier={isUsingIdentifier}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// (C) 2007-2018 GoodData Corporation
import * as React from 'react';
import { mount } from 'enzyme';
import { testUtils } from '@gooddata/js-utils';
import { AttributeFilter } from '../AttributeFilter';
import { AttributeDropdown } from '../AttributeDropdown';
import { createMetadataMock } from './utils';

describe('AttributeFilter', () => {
Expand All @@ -28,4 +30,14 @@ describe('AttributeFilter', () => {
const wrapper = renderComponent({ uri: '/gdc/md/projectId/obj/123' });
expect(wrapper.find('.s-button-loading')).toHaveLength(1);
});

it('should detect usage of identifier and pass it to the AttributeDropdown', () => {
const wrapper = renderComponent({ identifier: 'id123' });

return testUtils.delay().then(() => {
wrapper.update();
expect(wrapper.find(AttributeDropdown).prop('isUsingIdentifier')).toBeTruthy();
});

});
});
7 changes: 3 additions & 4 deletions stories/helper_components/AttributeFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ import * as React from 'react';
import { storiesOf } from '@storybook/react';
import { action } from '@storybook/addon-actions';

import { AttributeFilter } from '../../src/components/filters/AttributeFilter/AttributeFilter';
import { AttributeFilter, IAttributeFilterProps } from '../../src/components/filters/AttributeFilter/AttributeFilter';
import '../../styles/scss/attributeFilter.scss';

const attributeFilterWithUri = {
const attributeFilterWithUri: IAttributeFilterProps = {
uri: '/gdc/md/storybook/obj/3.df',
isOpenDefault: true,
projectId: 'storybook',
onApply: action('apply')
};

const attributeFilterWithIdentifier = {
const attributeFilterWithIdentifier: IAttributeFilterProps = {
identifier: '3.df',
projectId: 'storybook',
fullscreenOnMobile: false,
Expand Down

0 comments on commit cf92447

Please sign in to comment.