Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Buyantogtokh authored and batamar committed Jan 13, 2020
1 parent 7f99cf9 commit a39396e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
37 changes: 32 additions & 5 deletions ui/src/modules/settings/team/components/UserList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { IButtonMutateProps } from 'modules/common/types';
import { router } from 'modules/common/utils';
import { __ } from 'modules/common/utils';
import { FlexItem, FlexRow } from 'modules/insights/styles';
import SelectBrands from 'modules/settings/brands/containers/SelectBrands';
import { IUserGroup } from 'modules/settings/permissions/types';
import React from 'react';
import Select from 'react-select-plus';
Expand All @@ -33,6 +34,7 @@ type IProps = {
refetchQueries: any;
renderButton: (props: IButtonMutateProps) => JSX.Element;
queryParams?: any;
configsEnvQuery?: any;
};

type FinalProps = ICommonListProps &
Expand All @@ -49,9 +51,7 @@ class UserList extends React.Component<FinalProps, States> {
constructor(props: FinalProps) {
super(props);

const {
queryParams: { searchValue }
} = props;
const { queryParams: { searchValue } } = props;

this.state = {
searchValue: searchValue || ''
Expand Down Expand Up @@ -213,12 +213,39 @@ class UserList extends React.Component<FinalProps, States> {
router.setParams(this.props.history, { isActive: status.value });
};

renderBrandChooser() {
const { configsEnvQuery = {}, history, queryParams } = this.props;

const env = configsEnvQuery.configsGetEnv || {};

if (env.USE_BRAND_RESTRICTIONS !== 'true') {
return null;
}

const onSelect = brandIds => {
router.setParams(history, { brandIds });
};

return (
<FlexItem>
<ControlLabel>{__('Brand')}</ControlLabel>
<SelectBrands
label={__('Choose brands')}
onSelect={onSelect}
value={queryParams.brandIds}
name="selectedBrands"
/>
</FlexItem>
);
}

renderFilter = () => {
return (
<FilterContainer>
<FlexRow>
{this.renderBrandChooser()}
<FlexItem>
<ControlLabel>Search</ControlLabel>
<ControlLabel>{__('Search')}</ControlLabel>
<FormControl
placeholder="Search"
name="searchValue"
Expand All @@ -230,7 +257,7 @@ class UserList extends React.Component<FinalProps, States> {
</FlexItem>

<FlexItem>
<ControlLabel>Status</ControlLabel>
<ControlLabel>{__('Status')}</ControlLabel>
<Select
placeholder={__('Choose status')}
value={this.props.queryParams.isActive || true}
Expand Down
15 changes: 11 additions & 4 deletions ui/src/modules/settings/team/containers/UserList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ICommonFormProps,
ICommonListProps
} from 'modules/settings/common/types';
import { queries as generalQueries } from 'modules/settings/general/graphql';
import { queries as permissionQueries } from 'modules/settings/permissions/graphql';
import { IUserGroup } from 'modules/settings/permissions/types';
import React from 'react';
Expand Down Expand Up @@ -93,13 +94,15 @@ class UserListContainer extends React.Component<
}
}

const options = ({ queryParams }: { queryParams: any }) => {
const options = ({ queryParams }: { queryParams: any }): any => {
return {
variables: {
...generatePaginationParams(queryParams),
searchValue: queryParams.searchValue,
isActive: queryParams.isActive === 'false' ? false : true
}
isActive: queryParams.isActive === 'false' ? false : true,
brandIds: queryParams.brandIds
},
fetchPolicy: 'network-only'
};
};

Expand Down Expand Up @@ -140,5 +143,9 @@ export default commonListComposer<{ queryParams: any; history: any }>({
name: 'totalCountQuery',
options
}),
ListComponent: UserListContainer
ListComponent: UserListContainer,
gqlConfigsQuery: graphql(gql(generalQueries.configsGetEnv), {
name: 'configsEnvQuery',
options: { fetchPolicy: 'network-only' }
})
});
8 changes: 6 additions & 2 deletions ui/src/modules/settings/team/graphql/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,15 @@ const userConversations = `
const listParamsDef = `
$searchValue: String,
$isActive: Boolean,
$ids: [String]
$ids: [String],
$brandIds: [String]
`;

const listParamsValue = `
searchValue: $searchValue,
isActive: $isActive,
ids: $ids
ids: $ids,
brandIds: $brandIds
`;

const users = `
Expand All @@ -71,6 +73,7 @@ const users = `
isActive
groupIds
brandIds
details {
avatar
fullName
Expand All @@ -79,6 +82,7 @@ const users = `
description
location
}
links {
linkedIn
twitter
Expand Down
6 changes: 4 additions & 2 deletions ui/src/modules/settings/utils/commonListComposer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ function commonListComposer<ComponentProps>(options) {
gqlListQuery,
gqlTotalCountQuery,
gqlRemoveMutation,
ListComponent
ListComponent,
gqlConfigsQuery
} = options;

type Props = {
Expand Down Expand Up @@ -114,7 +115,8 @@ function commonListComposer<ComponentProps>(options) {
compose(
...composeAttr,
gqlListQuery,
gqlTotalCountQuery
gqlTotalCountQuery,
gqlConfigsQuery
)(ListContainer)
);
}
Expand Down

0 comments on commit a39396e

Please sign in to comment.