Skip to content

Commit

Permalink
Merge pull request #1241 from glific/search-logs
Browse files Browse the repository at this point in the history
Added logs for search
  • Loading branch information
mdshamoon authored Mar 31, 2021
2 parents 4a97f19 + ef03f45 commit cc613cf
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 36 deletions.
7 changes: 7 additions & 0 deletions src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,10 @@ export const copyToClipboardMethod = (client: any, text: string) => {
};

export { copyToClipboardMethod as copyToClipboard };

export const addLogsMethod = (event: string, logData: any) => {
setLogs(event, 'info');
setLogs(`variables-${logData}`, 'info');
};

export { addLogsMethod as addLogs };
17 changes: 11 additions & 6 deletions src/containers/BlockContact/BlockContactList/BlockContactList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { SEARCH_QUERY_VARIABLES } from '../../../common/constants';
import { CONTACT_SEARCH_QUERY, GET_CONTACT_COUNT } from '../../../graphql/queries/Contact';
import { DELETE_CONTACT, UPDATE_CONTACT } from '../../../graphql/mutations/Contact';
import { SEARCH_QUERY } from '../../../graphql/queries/Search';
import { addLogs } from '../../../common/utils';

export interface BlockContactListProps {}

Expand Down Expand Up @@ -76,13 +77,17 @@ export const BlockContactList: React.SFC<BlockContactListProps> = () => {
};

const handleUnblock = () => {
unblockContact({
variables: {
id: contactId,
input: {
status: 'VALID',
},
const variables = {
id: contactId,
input: {
status: 'VALID',
},
};

addLogs(`Unblock contact-${contactId}`, variables);

unblockContact({
variables,
});
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from '../../../../common/constants';
import { updateConversations } from '../../../../services/ChatService';
import { showMessages } from '../../../../common/responsive';
import { addLogs } from '../../../../common/utils';

interface ConversationListProps {
searchVal: string;
Expand Down Expand Up @@ -214,12 +215,14 @@ export const ConversationList: React.SFC<ConversationListProps> = (props) => {
useEffect(() => {
// Use multi search when has search value and when there is no collection id
if (searchVal && Object.keys(searchParam).length === 0 && !selectedCollectionId) {
addLogs(`Use multi search when has search value`, filterSearch());
getFilterSearch({
variables: filterSearch(),
});
} else {
// This is used for filtering the searches, when you click on it, so only call it
// when user clicks and savedSearchCriteriaId is set.
addLogs(`filtering the searches`, filterVariables());
getFilterConvos({
variables: filterVariables(),
});
Expand Down
69 changes: 48 additions & 21 deletions src/containers/Chat/ChatMessages/ChatMessages.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
import { FILTER_TAGS_NAME } from '../../../graphql/queries/Tag';
import { ReactComponent as TagIcon } from '../../../assets/images/icons/Tags/Selected.svg';
import { getCachedConverations, updateConversationsCache } from '../../../services/ChatService';
import { addLogs } from '../../../common/utils';
import { CollectionInformation } from '../../Collection/CollectionInformation/CollectionInformation';

export interface ChatMessagesProps {
Expand Down Expand Up @@ -299,6 +300,13 @@ export const ChatMessages: React.SFC<ChatMessagesProps> = ({ contactId, collecti
flow: 'OUTBOUND',
};

const variables = {
groupId: collectionId,
input: updatePayload(payload, selectedTemplate, variableParam),
};

addLogs(`send Message To Collection-${collectionId}`, variables);

setCollectionVariables({
groupId: collectionId,
input: updatePayload(payload, selectedTemplate, variableParam),
Expand Down Expand Up @@ -378,15 +386,19 @@ export const ChatMessages: React.SFC<ChatMessagesProps> = ({ contactId, collecti
// if conversation is not present then fetch for contact
if (conversationIndex < 0) {
if ((!loading && !called) || (data && data.search[0].contact.id !== contactId)) {
getSearchQuery({
variables: {
filter: { id: contactId },
contactOpts: { limit: 1 },
messageOpts: {
limit: DEFAULT_MESSAGE_LIMIT,
offset: messageParameterOffset,
},
const variables = {
filter: { id: contactId },
contactOpts: { limit: 1 },
messageOpts: {
limit: DEFAULT_MESSAGE_LIMIT,
offset: messageParameterOffset,
},
};

addLogs(`if conversation is not present then search for contact-${contactId}`, variables);

getSearchQuery({
variables,
});
}
// lets not get from cache if parameter is present
Expand All @@ -395,15 +407,19 @@ export const ChatMessages: React.SFC<ChatMessagesProps> = ({ contactId, collecti
(!parameterLoading && !parameterCalled) ||
(parameterdata && parameterdata.search[0].contact.id !== contactId)
) {
getSearchParameterQuery({
variables: {
filter: { id: contactId },
contactOpts: { limit: 1 },
messageOpts: {
limit: DEFAULT_MESSAGE_LIMIT,
offset: messageParameterOffset,
},
const variables = {
filter: { id: contactId },
contactOpts: { limit: 1 },
messageOpts: {
limit: DEFAULT_MESSAGE_LIMIT,
offset: messageParameterOffset,
},
};

addLogs(`if search message is not present then search for contact-${contactId}`, variables);

getSearchParameterQuery({
variables,
});
}
}
Expand All @@ -423,12 +439,19 @@ export const ChatMessages: React.SFC<ChatMessagesProps> = ({ contactId, collecti
// if conversation is not present then fetch the collection
if (conversationIndex < 0) {
if (!loading && !data) {
const variables = {
filter: { id: collectionId, searchGroup: true },
contactOpts: { limit: DEFAULT_CONTACT_LIMIT },
messageOpts: { limit: DEFAULT_MESSAGE_LIMIT, offset: 0 },
};

addLogs(
`if conversation is not present then search for collection-${collectionId}`,
variables
);

getSearchQuery({
variables: {
filter: { id: collectionId, searchGroup: true },
contactOpts: { limit: DEFAULT_CONTACT_LIMIT },
messageOpts: { limit: DEFAULT_MESSAGE_LIMIT, offset: 0 },
},
variables,
});
}
}
Expand Down Expand Up @@ -550,6 +573,8 @@ export const ChatMessages: React.SFC<ChatMessagesProps> = ({ contactId, collecti
variables.filter = { id: collectionId.toString(), searchGroup: true };
}

addLogs(`load More Messages-${collectionId}`, variables);

getSearchQuery({
variables,
});
Expand Down Expand Up @@ -690,6 +715,8 @@ export const ChatMessages: React.SFC<ChatMessagesProps> = ({ contactId, collecti
variables.filter = { id: collectionId.toString(), searchGroup: true };
}

addLogs(`show Latest Message for contact-${contactId}`, variables);

getSearchParameterQuery({
variables,
});
Expand Down
2 changes: 2 additions & 0 deletions src/containers/Chat/ChatMessages/ContactBar/ContactBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import { Tooltip } from '../../../../components/UI/Tooltip/Tooltip';
import { CLEAR_MESSAGES } from '../../../../graphql/mutations/Chat';
import { showChats } from '../../../../common/responsive';
import { CollectionInformation } from '../../../Collection/CollectionInformation/CollectionInformation';
import { addLogs } from '../../../../common/utils';
import AddContactsToCollection from '../AddContactsToCollection/AddContactsToCollection';

const status = ['SESSION', 'SESSION_AND_HSM', 'HSM'];
Expand Down Expand Up @@ -293,6 +294,7 @@ export const ContactBar: React.SFC<ContactBarProps> = (props) => {
}

const handleBlock = () => {
addLogs(`refetch after block Contact`, SEARCH_QUERY_VARIABLES);
blockContact({
variables: {
id: contactId,
Expand Down
27 changes: 18 additions & 9 deletions src/containers/Chat/ChatSubscription/ChatSubscription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
} from '../../../graphql/subscriptions/Tag';
import { Loading } from '../../../components/UI/Layout/Loading/Loading';
import { setErrorMessage } from '../../../common/notification';
import { addLogs } from '../../../common/utils';

export interface ChatSubscriptionProps {
setDataLoaded: any;
Expand Down Expand Up @@ -200,16 +201,23 @@ export const ChatSubscription: React.SFC<ChatSubscriptionProps> = ({
// it to the cached conversations
// let's also skip fetching contact when we trigger this via group subscriptions
if (!conversationFound && newMessage && !newMessage.groupId) {
getContactQuery({
variables: {
contactOpts: {
limit: DEFAULT_CONTACT_LIMIT,
},
filter: { id: contactId },
messageOpts: {
limit: DEFAULT_MESSAGE_LIMIT,
},
const variables = {
contactOpts: {
limit: DEFAULT_CONTACT_LIMIT,
},
filter: { id: contactId },
messageOpts: {
limit: DEFAULT_MESSAGE_LIMIT,
},
};

addLogs(
`contact is not cached, so we need to fetch the conversations and add to cache`,
variables
);

getContactQuery({
variables,
});

return cachedConversations;
Expand Down Expand Up @@ -369,6 +377,7 @@ export const ChatSubscription: React.SFC<ChatSubscriptionProps> = ({
if (triggerRefetch) {
// lets refetch here
if (refetch) {
addLogs('refetch for subscription', queryVariables);
refetch();
}
setTriggerRefetch(false);
Expand Down

0 comments on commit cc613cf

Please sign in to comment.