Skip to content
This repository has been archived by the owner on Mar 23, 2019. It is now read-only.

Add client view initial search content #158 #160

Merged
merged 10 commits into from
Oct 17, 2018
6 changes: 3 additions & 3 deletions src/components/Dashboard/UserMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ export default class UserMenu extends Component {
this.setState({ signInDialogOpen: false });
};

handleClickSignOut = () => {
handleClickSignOut = async () => {
this.handleMenuClose();
this.props.onUnauthorize();
// Since Apollo caches query results, it’s important to get rid of them
// when the login state changes.
this.props.client.resetStore();
await this.props.client.resetStore();
this.props.onUnauthorize();
};

render() {
Expand Down
8 changes: 4 additions & 4 deletions src/components/SignInDialog/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ export default class SignInDialog extends Component {
);
}

handleCredentialsSignIn = credentials => {
handleCredentialsSignIn = async credentials => {
const inOneWeek = new Date();

inOneWeek.setDate(inOneWeek.getDate() + 7);

// Since Apollo caches query results, it’s important to get rid of them
// when the login state changes.
await this.props.client.resetStore();
this.props.onAuthorize({
credentials,
expires: inOneWeek.toISOString(),
Expand All @@ -57,9 +60,6 @@ export default class SignInDialog extends Component {
displayName: credentials.clientId,
},
});
// Since Apollo caches query results, it’s important to get rid of them
// when the login state changes.
this.props.client.resetStore();
this.props.onClose();
};

Expand Down
38 changes: 29 additions & 9 deletions src/views/Clients/ViewClients/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ import Button from '../../../components/Button';
import ClientsTable from '../../../components/ClientsTable';
import { VIEW_CLIENTS_PAGE_SIZE } from '../../../utils/constants';
import clientsQuery from './clients.graphql';
import { withAuth } from '../../../utils/Auth';

@hot(module)
@withAuth
@graphql(clientsQuery, {
options: () => ({
options: props => ({
variables: {
projectyang marked this conversation as resolved.
Show resolved Hide resolved
clientOptions: {
...(props.user ? { prefix: props.user.credentials.clientId } : null),
},
clientsConnection: {
limit: VIEW_CLIENTS_PAGE_SIZE,
},
Expand All @@ -31,9 +36,28 @@ import clientsQuery from './clients.graphql';
}))
export default class ViewWorker extends PureComponent {
state = {
clientSearch: '',
clientSearch: this.props.user ? this.props.user.credentials.clientId : '',
projectyang marked this conversation as resolved.
Show resolved Hide resolved
clientId: this.props.user ? this.props.user.credentials.clientId : '',
projectyang marked this conversation as resolved.
Show resolved Hide resolved
projectyang marked this conversation as resolved.
Show resolved Hide resolved
};

static getDerivedStateFromProps(props, state) {
// Any time the current user changes,
// Reset state to reflect new user / log out and default clientSearch query
if (props.user && props.user.credentials.clientId !== state.clientId) {
return {
clientSearch: props.user.credentials.clientId,
clientId: props.user.credentials.clientId,
};
} else if (!props.user && state.clientId !== '') {
return {
clientSearch: '',
clientId: '',
};
}

return null;
}

handlePageChange = ({ cursor, previousCursor }) => {
const {
data: { fetchMore },
Expand Down Expand Up @@ -86,13 +110,9 @@ export default class ViewWorker extends PureComponent {
const { clientSearch } = this.state;

refetch({
...(clientSearch
? {
clientOptions: {
prefix: clientSearch,
},
}
: null),
clientOptions: {
...(clientSearch ? { prefix: clientSearch.trim() } : null),
},
clientsConnection: {
limit: VIEW_CLIENTS_PAGE_SIZE,
},
Expand Down