Skip to content

Commit

Permalink
Merge branch 'master' into refactor-1
Browse files Browse the repository at this point in the history
  • Loading branch information
prathamVaidya authored Apr 13, 2024
2 parents 0d4032d + 4c59cfa commit 96ca13b
Show file tree
Hide file tree
Showing 71 changed files with 1,463 additions and 892 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const ActivityTableRow = ({ isOpen, diffUrl, revisionDateTime,
if (reportUrl) {
col2 = (
<td>
<a href={reportUrl} target="_blank">Report</a>
<a href={reportUrl} target="_blank">{I18n.t('recent_activity.report')}</a>
</td>
);
}
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/components/alerts/alert.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Alert = ({ alert, adminAlert, resolveAlert }) => {
}
if (alert.resolvable && !alert.resolved) {
resolveButton = (
<button className="button small danger dark" onClick={() => resolveAlert(alert.id)}>Resolve</button>
<button className="button small danger dark" onClick={() => resolveAlert(alert.id)}>{I18n.t('campaign.resolve')}</button>
);
}
resolveCell = (
Expand Down
71 changes: 26 additions & 45 deletions app/assets/javascripts/components/article_finder/article_finder.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect, useRef } from 'react';
import React, { useState, useEffect } from 'react';
import { connect } from 'react-redux';
import InputRange from 'react-input-range';
import { includes, map, find } from 'lodash-es';
Expand All @@ -20,11 +20,11 @@ import { getFilteredArticleFinder } from '../../selectors';

import { trackedWikisMaker } from '../../utils/wiki_utils';
import ArticleUtils from '../../utils/article_utils';
import ArticleFinderSearchBar from './article_finder_search_bar';

const ArticleFinder = (props) => {
const [isSubmitted, setIsSubmitted] = useState(false);
const [showFilters, setShowFilters] = useState(false);
const searchboxRef = useRef(null);

useEffect(() => {
if (window.location.search.substring(1)) {
Expand All @@ -42,12 +42,6 @@ const ArticleFinder = (props) => {
props.resetArticleFinder();
};
}, []);
const onKeyDown = (keyCode, ref) => {
if (keyCode === 13) {
ref.blur();
searchArticles();
}
};

const getParamsURL = () => {
const query = qs.parse(window.location.search);
Expand Down Expand Up @@ -81,35 +75,31 @@ const ArticleFinder = (props) => {
});
history.replaceState(window.location.href, 'query_string', queryStringUrl);
};
const searchArticles = async () => {

const searchArticles = async (searchTerm) => {
setIsSubmitted(true);
const searchTerm = window.location.href.match(/search_term=([^&]*)/)[1];
buildURL('search_term', searchTerm);
if (searchTerm === '') {
return setIsSubmitted(false);
} else if (props.search_type === 'keyword') {
return props.fetchKeywordResults(searchTerm, props.selectedWiki);
}
return props.fetchCategoryResults(searchTerm, props.selectedWiki);
};

const fetchMoreResults = () => {
if (props.search_type === 'keyword') {
return props.fetchKeywordResults(props.search_term, props.selectedWiki, props.offset, true);
}
return props.fetchCategoryResults(props.search_term, props.selectedWiki, props.cmcontinue, true);
};
// const handleChange = (e) => {
// const grade = e.target.value;
// return props.updateFields('grade', grade);
// };

const handleWikiChange = (wiki) => {
wiki = wiki.value;
setIsSubmitted(false);
props.clearResults();
return updateFieldsHandler('wiki', { language: wiki.language, project: wiki.project });
};
// const sortSelect = (e) => {
// props.sortArticleFinder(e.target.value);
// };

const searchType = (
<div>
Expand Down Expand Up @@ -346,16 +336,17 @@ const ArticleFinder = (props) => {
const trackedWikis = trackedWikisMaker(props.course);

const options = (
<SelectedWikiOption
language={props.selectedWiki.language || 'www'}
project={props.selectedWiki.project}
handleWikiChange={handleWikiChange}
trackedWikis={trackedWikis}
/>
<div className="article-finder-options">
<SelectedWikiOption
language={props.selectedWiki.language || 'www'}
project={props.selectedWiki.project}
handleWikiChange={handleWikiChange}
trackedWikis={trackedWikis}
/>
</div>
);

const isButtonDisabled = props.fetchState !== 'PAGEVIEWS_RECEIVED' && !props.loading;
const buttonClasses = `button dark ${isButtonDisabled ? 'disabled' : ''}`;

return (
<div className="container">
Expand All @@ -366,27 +357,17 @@ const ArticleFinder = (props) => {
</div>
</header>
<div className="article-finder-form">
<div className="search-bar">
<TextInput
id="category"
onChange={updateFieldsHandler}
value={props.search_term}
value_key="search_term"
required
editable
label={I18n.t('article_finder.search')}
placeholder={I18n.t('article_finder.search_placeholder')}
onKeyDown={onKeyDown}
ref={searchboxRef}
/>
<button
className={buttonClasses}
disabled={isButtonDisabled}
onClick={searchArticles}
>
{I18n.t('article_finder.submit')}
</button>
</div>

<ArticleFinderSearchBar
value={props.search_term}
wiki={props.selectedWiki}
onChange={(searchTerm) => {
return props.updateFields('search_term', searchTerm);
}}
onSearch={searchArticles}
disabled={isButtonDisabled}
/>

</div>
{options}
{filterBlock}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const ArticleFinderRow = (props) => {
if (props.article.pageviews) {
pageviews = Math.round(props.article.pageviews);
} else if (props.article.fetchState === 'PAGEVIEWS_RECEIVED') {
pageviews = <div>Page Views not found!</div>;
pageviews = <div>{I18n.t('article_finder.page_views_not_found')}</div>;
}
let revScore;
if (
Expand All @@ -77,7 +77,7 @@ const ArticleFinderRow = (props) => {
} else if (props.article.revScore) {
revScore = <td className="revScore">{Math.round(props.article.revScore)}</td>;
} else if (fetchStates[props.article.fetchState] >= fetchStates.REVISIONSCORE_RECEIVED) {
revScore = <td><div>Estimation Score not found!</div></td>;
revScore = <td><div>{I18n.t('article_finder.estimation_score_not_found')}</div></td>;
} else {
revScore = <td />;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React, { useCallback, useState } from 'react';
import { debounce } from 'lodash';
import { fetchArticleAutocompleteResults } from '../../utils/article_finder_utils';

// Controls Search bar and autocomplete functionality

function ArticleFinderSearchBar({ value, onChange, onSearch, disabled, wiki }) {
const [suggestions, setSuggestions] = useState([]);
const [isAutocompleteLoading, setAutocompleteLoading] = useState(false);
let searchClass = 'search-bar';

if (suggestions.length > 0) {
searchClass += ' autocomplete-on';
}

const _getSuggestionsApi = useCallback(debounce(async (q) => {
setAutocompleteLoading(true);
const results = await fetchArticleAutocompleteResults(q, wiki).catch(() => []);
setAutocompleteLoading(false);
setSuggestions(results);
}, 500), []);

const inputChangeHandler = (e) => {
onChange(e.target.value);
// autocomplete disabled while disabled (during loading etc.)
if (!disabled) {
if (e.target.value === '') {
setSuggestions([]);
} else {
_getSuggestionsApi(e.target.value);
}
}
};

const searchHandler = () => {
if (disabled || value.trim() === '') return;
setSuggestions([]);
onSearch(value);
};

const onKeyDownHandler = (e) => {
// Search on Enter
if (e.key === 'Enter') {
searchHandler();
}
};

const autoCompleteClickHandler = (suggestion) => {
onChange(suggestion);
// call onSearch directly instead of searchHandler to use the latest suggestion value and not the old state value
onSearch(suggestion);
setSuggestions([]);
};

return (
<div className={searchClass}>
<input
type="text"
id="article-searchbar"
placeholder={I18n.t('article_finder.search_placeholder')}
onChange={inputChangeHandler}
value={value}
onKeyDown={onKeyDownHandler}
/>

{
isAutocompleteLoading && <div className="loader"><div className="loading__spinner"/></div>
}

<button onClick={searchHandler} disabled={disabled}>
{I18n.t('article_finder.search')}
</button>
<div className="autocomplete">
{
suggestions.map((sug) => {
return <div key={sug} className="autocomplete-item" onClick={() => autoCompleteClickHandler(sug)}> {sug} </div>;
})
}
</div>
</div>
);
}

export default ArticleFinderSearchBar;
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ const ArticleList = createReactClass({

let filterLabel;
if (!!filterWikis || !!filterArticlesSelect || !!filterTracked) {
filterLabel = <b>Filters:</b>;
filterLabel = <b>{I18n.t('articles.filter_text')}</b>;
}

const articleSort = (
Expand Down
12 changes: 6 additions & 6 deletions app/assets/javascripts/components/campaign/campaign_row.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ const CampaignRow = ({ campaign }) => {
return (
<tr>
<td className="title"><a href={`/campaigns/${campaign.slug}/overview`} >{campaign.title}</a></td>
<td><a href={`/campaigns/${campaign.slug}/students.csv`}>students</a></td>
<td><a href={`/campaigns/${campaign.slug}/students.csv?course=true`}>students by course</a></td>
<td><a href={`/campaigns/${campaign.slug}/students.csv`}>{I18n.t('campaign.students_small')}</a></td>
<td><a href={`/campaigns/${campaign.slug}/students.csv?course=true`}>{I18n.t('campaign.student_course')}</a></td>
<td>
<a href={`/campaigns/${campaign.slug}/instructors.csv?course=true`}>instructors by course</a>
<a href={`/campaigns/${campaign.slug}/instructors.csv?course=true`}>{I18n.t('campaign.instructors_course')}</a>
</td>
<td>
<a href={`/campaigns/${campaign.slug}/courses.csv`}>course data</a>
<a href={`/campaigns/${campaign.slug}/courses.csv`}>{I18n.t('campaign.course_data')}</a>
</td>
<td>
<a href={`/campaigns/${campaign.slug}/articles_csv.csv`}>pages edited</a>
<a href={`/campaigns/${campaign.slug}/articles_csv.csv`}>{I18n.t('campaign.pages_edited_small')}</a>
</td>
<td>
<a href={`/campaigns/${campaign.slug}/revisions_csv.csv`}>revision data</a>
<a href={`/campaigns/${campaign.slug}/revisions_csv.csv`}>{I18n.t('campaign.revision_data')}</a>
</td>
</tr>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { printArticleViewer } from '../../../../utils/article_viewer';

export const Footer = ({
article, colors, failureMessage, showArticleFinder, highlightedHtml, isWhocolorLang,
whocolorFailed, users, unhighlightedEditors
whocolorFailed, users, unhighlightedEditors, revisionId, toggleRevisionHandler
}) => {
// Determine the Article Viewer Legend status based on what information
// has returned from various API calls.
Expand All @@ -34,6 +34,26 @@ export const Footer = ({
);
}

const revision_button_text = revisionId ? I18n.t('application.show_current_revision') : I18n.t('application.show_last_revision');
const revision_button = !showArticleFinder && (
<div>
{
!showArticleFinder && (
<button
className="button dark small"
style={{
height: 'max-content',
width: 'max-content',
}}
onClick={toggleRevisionHandler}
>
{revision_button_text}
</button>
)
}
</div>
);

return (
<div
className="article-footer"
Expand All @@ -44,28 +64,40 @@ export const Footer = ({
}}
>
{articleViewerLegend}
<a
className="button dark small pull-right article-viewer-button"
href={article.url}
target="_blank"
style={{
height: 'max-content',
width: 'max-content',
whiteSpace: 'nowrap'
}}
>
{I18n.t('articles.view_on_wiki')}
</a>
<button
className="button dark small"
<div
style={{
height: 'max-content',
width: 'max-content',
display: 'flex',
alignItems: 'center',
gap: '1em',
width: '100%',
justifyContent: 'flex-end',
}}
onClick={printArticleViewer}
>
{I18n.t('application.print')}
</button>
{revision_button}
<a
className="button dark small pull-right article-viewer-button"
href={article.url}
target="_blank"
style={{
height: 'max-content',
width: 'max-content',
whiteSpace: 'nowrap'
}}
>
{I18n.t('articles.view_on_wiki')}
</a>
<button
className="button dark small"
style={{
height: 'max-content',
width: 'max-content',
margin: '0em 0em',
}}
onClick={printArticleViewer}
>
{I18n.t('application.print')}
</button>
</div>
</div>
);
};
Expand Down
Loading

0 comments on commit 96ca13b

Please sign in to comment.