Fixes issue #1407: language in title #1413
Conversation
@@ -21,7 +21,7 @@ const Article = React.createClass({ | |||
|
|||
shouldShowLanguagePrefix() { | |||
if (!this.props.course.home_wiki) { return false; } | |||
return this.props.article.language !== this.props.course.home_wiki.language; | |||
return this.props.article.language !== this.props.course.home_wiki.language && null; |
ragesoss
Sep 25, 2017
Member
I'm not clear about what the && null
is doing here. It looks like this would always return either false
or null
.
I'm not clear about what the && null
is doing here. It looks like this would always return either false
or null
.
mauditecandela
Sep 25, 2017
Author
Contributor
yes, you are right. reworking on it right now, sorry.
yes, you are right. reworking on it right now, sorry.
mauditecandela
Sep 26, 2017
Author
Contributor
@ragesoss I have doubled checked and at least in my local database, the articles are not receiving the language parameters, and that's why the behaviour was not as expected. Do you know if that happens in the production database as well?
(Wikimedia project lang is always NULL and also their articles, which was the only case the if statement was returning true - both languages are NULL).
One quickfix for the bug would be to change the if statement to include the language only if article.language !== home_wiki.language. Also I would add the home_wiki language in order not to have any problems with the already mention lack of article languages in the database.
So this line (line 38):
const languagePrefix = this.shouldShowLanguagePrefix() ?
${this.props.article.language}: : '';
would change to:
const languagePrefix = this.shouldShowLanguagePrefix() ? '' :
${this.props.course.home_wiki.language}:;
One bigger task would be to research why the articles have not languages defined in the database.
What do you think? If you agree I will do the new PR.
@ragesoss I have doubled checked and at least in my local database, the articles are not receiving the language parameters, and that's why the behaviour was not as expected. Do you know if that happens in the production database as well?
(Wikimedia project lang is always NULL and also their articles, which was the only case the if statement was returning true - both languages are NULL).
One quickfix for the bug would be to change the if statement to include the language only if article.language !== home_wiki.language. Also I would add the home_wiki language in order not to have any problems with the already mention lack of article languages in the database.
So this line (line 38):
const languagePrefix = this.shouldShowLanguagePrefix() ?
${this.props.article.language}: : '';
would change to:
const languagePrefix = this.shouldShowLanguagePrefix() ? '' :
${this.props.course.home_wiki.language}:;
One bigger task would be to research why the articles have not languages defined in the database.
What do you think? If you agree I will do the new PR.
@mauditecandela looking this over, I'm thinking that the best approach might be to have every article go through A big benefit to moving it over to |
I will try that out. |
@mauditecandela there's another linting error that is breaking the build. If you run |
aaaand it's green! Waiting for your feedback :) In my local machine seems to work and worked on the approach of transferring everything to course_utils.js in order to make easier to do some tests. |
@mauditecandela cool! It looks like the only place that users CourseUtils.formattedArticleTitle is in assignment.jsx, and it already has an article object that will include the language and project. So I think we should combine those into a single function that takes article and defaultWiki as arguments (which your new function does) and call it from assignment.jsx I think You can run the javascript tests locally by running |
Hi @ragesoss here my first proposal as a possible solution. As you suggested, I have merged both functions but in order to work finely, I also separated the title formatting action also from articleFromAssignment() function. I think this is more consistent, but also lead me to change different files where the article.formatted_title was expected to be available after creating the article from the assignment. I have also noticed that the problem that appears in this test: https://travis-ci.org/WikiEducationFoundation/WikiEduDashboard/jobs/280854551 was not appearing in my local jest, do you know why? Btw, thanks for the hint, jest is a great tool and now I love it! I look forward your feedback :) |
@mauditecandela we have two different test frameworks: Jest for unit testing of Javascript, and RSpec for doing Ruby unit tests as well as browser tests. Those 'multiwiki assignments' tests are browser tests, so they don't get run by Jest. (If you are running |
I think this will be a lot cleaner if the signature of |
@@ -141,7 +141,7 @@ describe('courseUtils.articleFromTitleInput', () => { | |||
}); | |||
}); | |||
|
|||
describe('courseUtils.articleFromAssignment', () => { | |||
describe('courseUtils.formattedArticleTitle', () => { |
ragesoss
Sep 28, 2017
Member
This is still a test of articleFromAssignment
.
This is still a test of articleFromAssignment
.
@@ -92,18 +92,12 @@ const CourseUtils = class { | |||
const language = assignment.language || 'en'; | |||
const project = assignment.project || 'wikipedia'; | |||
const articleUrl = assignment.article_url || this.urlFromTitleAndWiki(assignment.article_title, language, project); | |||
const formattedTitle = this.formattedArticleTitle( |
ragesoss
Sep 28, 2017
Member
Instead of removing this and setting formatted_title in other places every time this is called, you could do article.formatted_title = this.formattedArticleTitle(article) before the return.
If necessary, you could also make articleFromAssignment take an optional homeWiki argument to include.
In general, the more shared logic we can move into CourseUtils, the better. Isolating that logic into the shared vanilla Javascript function makes it much easier to test and maintain.
Instead of removing this and setting formatted_title in other places every time this is called, you could do article.formatted_title = this.formattedArticleTitle(article) before the return.
If necessary, you could also make articleFromAssignment take an optional homeWiki argument to include.
In general, the more shared logic we can move into CourseUtils, the better. Isolating that logic into the shared vanilla Javascript function makes it much easier to test and maintain.
let languagePrefix = ''; | ||
if (language === undefined || language === 'en') { | ||
if (!home || language === home.language || language === null || language === undefined || language === 'en') { |
ragesoss
Sep 28, 2017
Member
We can probably do away with the special-casing of 'en' here. Also, see if you can simplify this conditional any further.
We can probably do away with the special-casing of 'en' here. Also, see if you can simplify this conditional any further.
@@ -153,8 +153,6 @@ describe('courseUtils.articleFromAssignment', () => { | |||
expect(article.url).to.eq('https://es.wikipedia.org/wiki/Autofoto'); | |||
expect(article.title).to.eq('Autofoto'); | |||
expect(article.language).to.eq('es'); | |||
expect(article.project).to.eq('wikipedia'); |
ragesoss
Sep 28, 2017
Member
This should still be true.
This should still be true.
this.props.assignmentGroup[0].project, | ||
article.title, | ||
this.props.course.home_wiki); | ||
article.formatted_title = CourseUtils.formattedArticleTitle(article); |
ragesoss
Sep 28, 2017
Member
This line seems unnecessary if articleFromAssignment does this already.
This line seems unnecessary if articleFromAssignment does this already.
this.props.course.home_wiki); | ||
article.formatted_title = CourseUtils.formattedArticleTitle(article); | ||
if (!article.formatted_title) { | ||
article.formatted_title = CourseUtils.formattedArticleTitle(this.props.assignmentGroup[0]); |
ragesoss
Sep 28, 2017
Member
Here you can do article.formatted_title = CourseUtils.formattedArticleTitle(article, this.course.home_wiki)
The fewer times we need to call assignmentGroup[0]
, the more understandable this code will be.
Here you can do article.formatted_title = CourseUtils.formattedArticleTitle(article, this.course.home_wiki)
The fewer times we need to call assignmentGroup[0]
, the more understandable this code will be.
language, | ||
project, | ||
language: language, | ||
project: project, |
ragesoss
Sep 28, 2017
Member
This is fine, but means the same thing as what was there before, which is es2015 shorthand notation: { foo }
is the same as { foo: foo }
.
This is fine, but means the same thing as what was there before, which is es2015 shorthand notation: { foo }
is the same as { foo: foo }
.
I have already reduced the code as you suggested the only problems that I see are:
|
@mauditecandela I think the way to solve both of these is to pass course.home_wiki articleFromAssignment, and set the language and project from that if it is not provided by the |
This is passes all tests (finally!) and adds the defaultWiki to articleFromAssignment. I also removed te unneeded part of the object. |
@@ -241,7 +241,8 @@ const AssignButton = React.createClass({ | |||
let removeButton; | |||
let articleLink; | |||
ass.course_id = this.props.course_id; | |||
const article = CourseUtils.articleFromAssignment(ass); | |||
const article = CourseUtils.articleFromAssignment(ass, this.props.course.home_wiki); | |||
if (!article.formatted_title) { CourseUtils.formattedArticleTitle(article, this.props.course.home_wiki); } |
ragesoss
Sep 29, 2017
Member
Is this necessary? Unlike in assignment.jsx
, this article object is always generated by CourseUtils.articleFromAssignment
, so it should always have a formatted_title.
Is this necessary? Unlike in assignment.jsx
, this article object is always generated by CourseUtils.articleFromAssignment
, so it should always have a formatted_title.
mauditecandela
Sep 29, 2017
Author
Contributor
true!
true!
let languagePrefix = ''; | ||
if (language === undefined || language === 'en') { | ||
if (defaultWiki === undefined || article.language === defaultWiki.language || article.language === null || article.language === undefined) { |
ragesoss
Sep 29, 2017
Member
These can be simplified somewhat, I think. Instead of checking article.language and defaultWiki against multiple precise conditions, we can just check for falsiness: !defaultWiki
and !article.language
.
These can be simplified somewhat, I think. Instead of checking article.language and defaultWiki against multiple precise conditions, we can just check for falsiness: !defaultWiki
and !article.language
.
@mauditecandela this is almost there. I really like how much this simplifies both article.jsx and assignment.jsx. What remains:
|
Thanks a lot for all the guidance and the comments @ragesoss Here it is the new version. I added some tests and simplified the logic are formattedArticleTitle. Let me know what you think :) |
@mauditecandela the tests still have some room for improvement, to reflect the different situations where article titles get displayed. It looks like everywhere except for For the tests of formattedArticleTitle, similarly, it looks like we're going to be able to use it always with the defaultWiki included, so the tests should reflect that, but they should test all the main possible situations: when the article is on the same wiki as the course; when the article is the same project but different language; when the article is same language but different project; when the article is different langauge and different project; and when the article is a different project that doesn't have a language (ie, Wikidata). |
@ragesoss you were right, I was too tired yesterday and today I saw that the tests were far from accurate. I corrected them, please let me know what you think. I am excited! I enjoyed very much working on this. :) |
expect(article.formatted_title).to.eq('wikidata:Judith Butler'); | ||
}); | ||
|
||
it('returns true for a weeks array with trainings', () => { |
ragesoss
Sep 30, 2017
Member
Duplicate
Duplicate
:-) Please add the course home_wiki to the |
Done!!! |
f584bfc
into
WikiEducationFoundation:master
#1407