-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TNO-1136: User can set toning #2226
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This solution lacks a few key features.
- None of the reports will show the user's sentiment
- The user cannot select an appropriate tone pool to use
export const sentimentFormSchema = object().shape({ | ||
tonePools: array().of( | ||
object().shape({ | ||
value: number().required('Tone value is required'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe tone is required. Did Scott ask for this?
@@ -215,7 +215,14 @@ export const ContentEditForm = React.forwardRef<HTMLDivElement | null, IContentE | |||
</Col> | |||
<Col className="sentiment"> | |||
<Sentiment | |||
value={form.content.tonePools.length ? form.content.tonePools[0].value : undefined} | |||
value={ | |||
form.content.versions?.[userId]?.tone !== undefined && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell tone
should never be null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First time the tone
can be null when the user did not save her/his tone and until tone
is saved by the user, then we have a value.
: content.body, | ||
|
||
const sentiment = | ||
content.versions?.[userId]?.tone !== undefined && content.versions?.[userId]?.tone != null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell tone
should never be null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First time the tone can be null when the user did not save her/his tone and until tone is saved by the user, then we have a value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it can be null
then your interface is not correct. I would recommend updating the interface if you want to handle null. However, I don't know why you would want both null
and undefined
.
This is one of the reasons I'm not a fan of javascript.
body: | ||
content.versions?.[userId]?.body ?? | ||
(isAV ? (content.isApproved && content.body ? content.body : content.summary) : content.body), | ||
tonePools: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you using a property tonePools
here? The model is for IContentVersionModel
has a tone
property you added.
(isAV ? (content.isApproved && content.body ? content.body : content.summary) : content.body), | ||
tonePools: | ||
sentiment !== undefined && sentiment !== null | ||
? [{ value: sentiment, id: tonePools[0].id }] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no reason to apply the wrong id
to this user's tone`
@@ -152,6 +183,19 @@ export const ContentForm: React.FC<IContentFormProps> = ({ | |||
onContentChange?.(values); | |||
}} | |||
/> | |||
<Formik initialValues={versions} validationSchema={sentimentFormSchema} onSubmit={() => {}}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't create a sub-form simply to work around the behavior of the FormikSentiment. Make the component smarter.
<Formik initialValues={versions} validationSchema={sentimentFormSchema} onSubmit={() => {}}> | ||
{() => ( | ||
<Form> | ||
<FormikSentiment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this component able to show the current value the user selected when the page is reloaded?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Through using handleSentimentChange callback which is executed when the user clicks on the tone
button.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That function saves the value. The component has no way to know the current value. If you refresh the page it wouldn't know how to get the value.
@@ -82,6 +86,7 @@ public ContentVersion(Content content, User owner) | |||
this.Body = content.Body; | |||
this.SourceUrl = content.SourceUrl; | |||
this.IsPrivate = content.IsPrivate; | |||
this.Tone = content.TonePools.Count > 0 ? (int?)content.TonePools[0].Id : null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This incorrect, it should be the TonePoolsManyToMany.FirstOrDefault().Value
not the TonePool[0].Id
.
const updatedTonePools = !!defaultTonePool | ||
? [{ ...defaultTonePool, value: option }] | ||
: []; | ||
setFieldValue(name.toString(), updatedTonePools, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to modify the the formik context field and also call the onSentimentChange
. You can pass the valid name to the component to control what is being updated. Or you can choose to only perform the onSentimentChange
if it has been provided. Doing both is a bad component.
There has been a few changes to |
I have to close this PR. Somehow the changes were lost, I had to retrieve using reflog and created another branch. |
Feature Update: User-Defined Tone Assessment for Articles
This update introduces the ability for subscribers to assess and set a personal tone for an article, independent of the original tone. The custom tone selected by the user will be saved and associated with their account, ensuring that their personal assessment is retained without altering the article's original tone data.
Implementation Details:
FormikSentiment
component has been modified to match the UI in subscriber.Example:
DB:
content.versions:
select c.id, c.status, c.headline, c.body, c.byline, ct.tone_pool_id, ct.value
from "content" c, content_tone ct
where c.id = 3204 and
ct.content_id = c.id
Story: https://citz-gdx.atlassian.net/browse/TNO-1136