-
Notifications
You must be signed in to change notification settings - Fork 603
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
Frontend changes for showing tabbed course overview stats #5064
Changes from all commits
02da8da
8c237a3
a0bb519
0c81559
23821ba
918faf0
8f2d6ca
9cc4b44
5670769
7dd7f26
f0e4e0b
c0b47bc
ae7d15d
f019e01
d8d7bf0
49b696b
f7c9833
c170b1c
82d042f
8aea637
1639e9f
34b8c98
6f58d37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import OverviewStat from './overview_stat'; | ||
|
||
const NamespaceOverviewStats = ({ statistics }) => { | ||
return ( | ||
<div className="stat-display"> | ||
<OverviewStat | ||
id="articles-created" | ||
className="stat-display__value" | ||
stat={statistics.new_count} | ||
statMsg={I18n.t('metrics.articles_created')} | ||
renderZero={false} | ||
/> | ||
<OverviewStat | ||
id="articles-edited" | ||
className="stat-display__value" | ||
stat = {statistics.edited_count} | ||
statMsg={I18n.t('metrics.articles_edited')} | ||
renderZero={false} | ||
/> | ||
<OverviewStat | ||
id="total-edits" | ||
className="stat-display__value" | ||
stat = {statistics.revision_count} | ||
statMsg={I18n.t('metrics.edit_count_description')} | ||
renderZero={false} | ||
/> | ||
<OverviewStat | ||
id="student-editors" | ||
className="stat-display__value" | ||
stat={statistics.user_count} | ||
statMsg={I18n.t('courses.student_editors')} | ||
renderZero={false} | ||
/> | ||
<OverviewStat | ||
id="word-count" | ||
className="stat-display__value" | ||
stat={statistics.word_count} | ||
statMsg={I18n.t('metrics.word_count')} | ||
renderZero={false} | ||
/> | ||
<OverviewStat | ||
id="references-count" | ||
className="stat-display__value" | ||
stat={statistics.references_count} | ||
statMsg={I18n.t('metrics.references_count')} | ||
renderZero={false} | ||
/> | ||
<OverviewStat | ||
id="view-count" | ||
className="stat-display__value" | ||
stat={statistics.views_count} | ||
statMsg={I18n.t('metrics.view_count_description')} | ||
renderZero={false} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
NamespaceOverviewStats.propTypes = { | ||
statistics: PropTypes.object.isRequired | ||
}; | ||
|
||
export default NamespaceOverviewStats; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import WikidataOverviewStats from '../wikidata_overview_stats'; | ||
import NamespaceOverviewStats from './namespace_overview_stats'; | ||
|
||
const OverviewStatsContent = ({ content }) => { | ||
const title = content.statsTitle; | ||
const data = content.statsData; | ||
const statistics = (title === 'www.wikidata.org') | ||
? <WikidataOverviewStats statistics={data} isCourseOverview={true}/> | ||
: <NamespaceOverviewStats statistics={data} />; | ||
|
||
return ( | ||
<div className="content-container"> | ||
<h2 className="title">{title}</h2> | ||
<div className="stats-data"> | ||
{statistics} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
OverviewStatsContent.propTypes = { | ||
content: PropTypes.object.isRequired | ||
}; | ||
|
||
export default OverviewStatsContent; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
const OverviewStatsTab = ({ id, title, active, onClick }) => { | ||
const isActive = (active) ? ' active' : ''; | ||
const tabClass = `tab${isActive}`; | ||
const tabId = `tab-${id}`; | ||
return ( | ||
<div className={tabClass} onClick={onClick} id={tabId}> | ||
<p>{title}</p> | ||
</div> | ||
); | ||
}; | ||
|
||
OverviewStatsTab.propTypes = { | ||
id: PropTypes.number.isRequired, | ||
title: PropTypes.string.isRequired, | ||
active: PropTypes.bool.isRequired, | ||
onClick: PropTypes.func.isRequired | ||
}; | ||
|
||
export default OverviewStatsTab; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import React, { useState } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import OverviewStatsTab from './OverviewStats/overview_stats_tab'; | ||
import OverviewStatsContent from './OverviewStats/overview_stats_content'; | ||
|
||
import { overviewStatsLabel } from '../../utils/wiki_utils'; | ||
|
||
|
||
const OverviewStatsTabs = ({ statistics }) => { | ||
const [currentTabId, setCurrentTabId] = useState(0); | ||
|
||
const onTabChange = (e) => { | ||
const tabId = e.currentTarget.id; | ||
const tabIdNumber = Number(tabId.split('-')[1]); | ||
return setCurrentTabId(tabIdNumber); | ||
}; | ||
|
||
const statsList = []; | ||
const tabsList = []; | ||
|
||
let index = 0; | ||
Object.keys(statistics).forEach((wiki_ns_key) => { | ||
const statsTitle = overviewStatsLabel(wiki_ns_key); | ||
const statsData = statistics[wiki_ns_key]; | ||
|
||
statsList.push({ statsTitle, statsData }); | ||
tabsList.push( | ||
<OverviewStatsTab | ||
key={index} | ||
id={index} | ||
onClick={onTabChange} | ||
title={statsTitle} | ||
active={currentTabId === index} | ||
/> | ||
); | ||
index += 1; | ||
}); | ||
|
||
const content = <OverviewStatsContent content={statsList[currentTabId]} />; | ||
// Hide tabs container if there is only one tab | ||
const tabsClass = `tabs-container${(tabsList.length === 1) ? ' hide' : ''}`; | ||
|
||
return ( | ||
<div className="overview-stats-tabs-container"> | ||
<div className={tabsClass}> | ||
{tabsList} | ||
</div> | ||
{content} | ||
</div> | ||
); | ||
}; | ||
|
||
OverviewStatsTabs.propTypes = { | ||
statistics: PropTypes.object.isRequired | ||
}; | ||
|
||
export default OverviewStatsTabs; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,10 +3,16 @@ import PropTypes from 'prop-types'; | |
import OverviewStat from './OverviewStats/overview_stat'; | ||
import I18n from 'i18n-js'; | ||
|
||
const WikidataOverviewStats = ({ statistics }) => { | ||
const WikidataOverviewStats = ({ statistics, isCourseOverview }) => { | ||
let containerClass = 'wikidata-stats-container'; | ||
let title = 'Wikidata stats'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this title isn't used in the the latest screenshots you shared? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it is used. In the last one. Here, the title isn't "Wikidata stats", but "www.wikidata.org". I thought that this would be in accordance with other namespace stats and their title. So, "Wikidata Stats" would be only shown for campaign overview stats. Is it okay? |
||
if (isCourseOverview) { | ||
containerClass = 'wikidata-stats-container course-overview'; | ||
title = null; | ||
} | ||
return ( | ||
<div className="wikidata-stats-container"> | ||
<h2 className="wikidata-stats-title">Wikidata stats</h2> | ||
<div className={containerClass}> | ||
<h2 className="wikidata-stats-title">{title}</h2> | ||
<div className="wikidata-display"> | ||
<div className="stat-display__row"> | ||
<h5 className="stats-label">{I18n.t('metrics.general')}</h5> | ||
|
@@ -216,7 +222,8 @@ const WikidataOverviewStats = ({ statistics }) => { | |
}; | ||
|
||
WikidataOverviewStats.propTypes = { | ||
statistics: PropTypes.object | ||
statistics: PropTypes.object.isRequired, | ||
isCourseOverview: PropTypes.bool | ||
}; | ||
|
||
export default WikidataOverviewStats; |
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 think the user count needs to be in any namespace-specific stats.
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.
Won't it give insight of how many students worked on particular tracked namespace?