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

fix(ChatMessage): show timestamp if reactionGroup is provided #1100

Merged
merged 12 commits into from
Mar 26, 2019

Conversation

mnajdova
Copy link
Contributor

@mnajdova mnajdova commented Mar 25, 2019

There is update for the reactions + timestamp in Teams theme. When there are reaction on the message, the timestamp should always be shown.

@mnajdova mnajdova changed the title WIP WIP fix(ChatMessage): show timestamp if reactionGroup is provided Mar 25, 2019
@codecov
Copy link

codecov bot commented Mar 25, 2019

Codecov Report

Merging #1100 into master will decrease coverage by 0.05%.
The diff coverage is 46.87%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1100      +/-   ##
==========================================
- Coverage   82.14%   82.09%   -0.06%     
==========================================
  Files         716      717       +1     
  Lines        8554     8567      +13     
  Branches     1230     1233       +3     
==========================================
+ Hits         7027     7033       +6     
- Misses       1511     1518       +7     
  Partials       16       16
Impacted Files Coverage Δ
...src/themes/teams/components/Chat/chatItemStyles.ts 20% <0%> (-18.47%) ⬇️
.../themes/teams/components/Chat/chatMessageStyles.ts 10.25% <0%> (-3.54%) ⬇️
packages/react/src/components/Chat/ChatMessage.tsx 95.16% <100%> (+0.16%) ⬆️
packages/react/src/lib/index.ts 100% <100%> (ø) ⬆️
packages/react/src/lib/getElementProp.ts 100% <100%> (ø)
packages/react/src/components/Chat/ChatItem.tsx 88.37% <61.53%> (-11.63%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e521c9f...1985394. Read the comment docs.

@mnajdova mnajdova changed the title WIP fix(ChatMessage): show timestamp if reactionGroup is provided fix(ChatMessage): show timestamp if reactionGroup is provided Mar 25, 2019
@@ -50,6 +50,9 @@ export interface ChatMessageProps
/** Menu with actions of the message. */
actionMenu?: ShorthandValue

/** Controls messages's relation to other chat messages. It is automatically set from the ChatItem */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit-nit: lets end description with dot, also, we might consider to use by instead of from, something like:

 Controls messages's relation to other chat messages. Is automatically set by the ChatItem.

},
})

// the box element is ChatMessage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment may be a bit misleading - what we are testing here is not the Box element, but rather if messageElement is ChatMessage. Lets just omit box from the comment text

})

// the box element is ChatMessage
if (this.checkIfElementIsChatMessage(messageElement)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we may shorten the name of predicate method:

if (this.isChatMessageElement(messageElement)) {
   ..
}

-changed method name
}

checkIfElementIsChatMessage = (element, prop?) => {
return _.get(element, `${prop ? `props.${prop}.` : ''}type.__isChatMessage`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to make this method's logic as simple as possible - then it would be much easier to reason of what this method is supposed to do at the place of usage:

// just single parameter
isChatMessageElement = (element) => ...

As a next step, we might notice that this method relies on the aspects that are provided by another type, i.e. ChatMessage's __isChatMessage static prop, which name might change. Thus, I would suggest to put this check as part of the ChatMessage component's logic:

class ChatMessage extends ... {
  static isChatMessageElement(element) => ...
}

And, finally - while I do see the benefit of introducing second arg to original method to avoid duplication of prop fetching logic, we might just want to introduce a dedicated method for props fetching for that:

getElementProp = (element, propName) => { .. }

once again, with preserving the benefit of reducing duplication, we would have yet additional one: this method is quite easy to reason about on the client's side.

As a result, we might end with something like:

 if (ChatMessage.isTypeOfElement(messageElement) { .. }
 if (ChatMessage.isTypeOfElement(getElementProp(messageElement, 'content')) { .. }

return this.cloneElementWithCustomProps(messageElement, { attached })
}

// the children element is ChatMessage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given that children, theoretically, may be a function, the following comment would be more correct:

the children is ChatMessage element

the same applies to the content

{contentPosition === 'end' && gutterElement}
</>
)
}

getMessageAugmentedWithChatMessageProps = styles => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to better deliver the main intent of this method - lets rename if to something like setAttachedPropValueForChatMessage

@mnajdova mnajdova merged commit 6a85de6 into master Mar 26, 2019
@delete-merged-branch delete-merged-branch bot deleted the fix/chat-message-reactions-styles branch March 26, 2019 17:34
// the content is ChatMessage
if (ChatMessage.isTypeOfElement(getElementProp(messageElement, 'content'))) {
return this.cloneElementWithCustomProps(messageElement, { attached }, 'content')
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please clarify this for me? Will we add attached prop only is element/children/content are ChatItem?
But, any HOC will break this: https://codesandbox.io/s/n4mm1ny55l 💣

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, by default we will propagate the attached in these three use cases (which we see as the most common) - the attached prop can always be applied on the ChatMessage if it is wrapped... I am open for refactoring it if we have some better ideas.. (once the template mechanism will be available to the user, we can safely omit these changes)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants