Skip to content
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

Fix #16069: Add a "Newest First" tag for reviewable questions #16534

Merged
merged 31 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
0366952
Add backend functions for sorting questions with the newest first
qinghaoyang Nov 13, 2022
412fca4
Merge remote-tracking branch 'upstream/develop' into sorting_questions
qinghaoyang Nov 13, 2022
5283c47
Fix lint errors
qinghaoyang Nov 13, 2022
45fc067
Completes the covereage test
qinghaoyang Nov 13, 2022
449dc4b
Merge remote-tracking branch 'upstream/develop' into sorting_questions
qinghaoyang Nov 29, 2022
748de42
Fix mypy errors
qinghaoyang Nov 29, 2022
9f470bb
Merge remote-tracking branch 'upstream/develop' into sorting_questions
qinghaoyang Dec 4, 2022
581281c
Change backend functions
qinghaoyang Dec 6, 2022
baa32ff
Change frontend functions
qinghaoyang Dec 6, 2022
8370912
Fix lint errors
qinghaoyang Dec 6, 2022
c33e9d3
Fix mypy errors
qinghaoyang Dec 6, 2022
304673a
Fix arguments error
qinghaoyang Dec 6, 2022
5734746
Merge remote-tracking branch 'upstream/develop' into sorting_questions
qinghaoyang Dec 22, 2022
75bc4d8
Merge remote-tracking branch 'upstream/develop' into sorting_questions
qinghaoyang Dec 29, 2022
6c2bfdd
Use positional args
qinghaoyang Dec 29, 2022
807fdc8
Use Date as the default choice
qinghaoyang Dec 29, 2022
e04ce60
Fix backend errors
qinghaoyang Dec 29, 2022
8cc15ce
Add a constant in constants.ts
qinghaoyang Dec 29, 2022
19371f4
Fetch a batch of items one time
qinghaoyang Dec 30, 2022
44c8d20
Merge remote-tracking branch 'upstream/develop' into sorting_questions
qinghaoyang Dec 30, 2022
0959288
Fix mypy errors
qinghaoyang Dec 30, 2022
b7848b1
Update frontend test
qinghaoyang Dec 30, 2022
91f889c
Fixed frontend bugs
qinghaoyang Dec 31, 2022
39de584
Set sort_key as a mandatory argument
qinghaoyang Jan 9, 2023
c3fc3b4
Merge remote-tracking branch 'upstream/develop' into sorting_questions
qinghaoyang Jan 9, 2023
3f3e83e
Update frontend tests
qinghaoyang Jan 9, 2023
766a329
Change the default sort key of reviewable translations to date
qinghaoyang Jan 10, 2023
8d9849a
Fix a bug about calculating offset
qinghaoyang Jan 10, 2023
4e80671
Fix mypy errors
qinghaoyang Jan 10, 2023
428f2ee
Add indexes
qinghaoyang Jan 10, 2023
a7cadb5
Merge remote-tracking branch 'upstream/develop' into sorting_questions
qinghaoyang Jan 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions assets/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5857,6 +5857,8 @@ export default {
"translation", "voiceover", "question", "submit_question"
],

"SUGGESTIONS_SORT_KEY_DATE": "Date",

"ACTION_REMOVE_ALL_REVIEW_RIGHTS": "all",
"ACTION_REMOVE_SPECIFIC_CONTRIBUTION_RIGHTS": "specific",
"USER_FILTER_CRITERION_USERNAME": "username",
Expand Down
2 changes: 1 addition & 1 deletion core/controllers/contributor_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def _get_reviewable_exploration_opportunity_summaries(
in_review_suggestions, _ = (
suggestion_services
.get_reviewable_translation_suggestions_by_offset(
user_id, topic_exp_ids, None, 0, language))
user_id, topic_exp_ids, None, 0, None, language))
# Filter out suggestions that should not be shown to the user.
# This is defined as a set as we only care about the unique IDs.
in_review_suggestion_target_ids = {
Expand Down
31 changes: 26 additions & 5 deletions core/controllers/suggestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,11 @@ class FrontendBaseSuggestionDict(TypedDict):
str,
Dict[
str,
Optional[Dict[str, Union[str, List[Dict[str, Union[str, int]]]]]]
Union[
Optional[
Dict[str, Union[str, List[Dict[str, Union[str, int]]]]]],
List[str]
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain why this was changed? I don't see a List[str] added to the handler.

Copy link
Contributor Author

@qinghaoyang qinghaoyang Dec 29, 2022

Choose a reason for hiding this comment

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

Otherwise, there will be an error:

Dict entry 1 has incompatible type "str": "List[str]" ...

for feconf.QUESTIONS_SORT_KEYS during Mypy type checks.

        'sort_key': {
            'schema': {
                'type': 'basestring'
            },
            'choices': feconf.QUESTIONS_SORT_KEYS,
            'default_value': None
        },

]
]
]
]
Expand Down Expand Up @@ -677,6 +681,7 @@ class ReviewableSuggestionsHandlerNormalizedRequestDict(TypedDict):

limit: int
offset: int
sort_key: str
exploration_id: Optional[str]


Expand Down Expand Up @@ -723,6 +728,12 @@ class ReviewableSuggestionsHandler(
}]
}
},
'sort_key': {
'schema': {
'type': 'basestring'
},
'choices': feconf.SUGGESTIONS_SORT_KEYS,
},
'exploration_id': {
'schema': {
'type': 'basestring'
Expand All @@ -746,6 +757,7 @@ def get(self, target_type: str, suggestion_type: str) -> None:
target_type, suggestion_type)
limit = self.normalized_request['limit']
offset = self.normalized_request['offset']
sort_key = self.normalized_request['sort_key']
exploration_id = self.normalized_request.get('exploration_id')
exp_ids = [exploration_id] if exploration_id else []

Expand All @@ -755,7 +767,7 @@ def get(self, target_type: str, suggestion_type: str) -> None:
reviewable_suggestions, next_offset = (
suggestion_services
.get_reviewable_translation_suggestions_by_offset(
self.user_id, exp_ids, limit, offset))
self.user_id, exp_ids, limit, offset, sort_key))
# Filter out obsolete translation suggestions, i.e. suggestions with
# translations that no longer match the current exploration content
# text. See issue #16536 for more details.
Expand All @@ -767,7 +779,7 @@ def get(self, target_type: str, suggestion_type: str) -> None:
suggestions, next_offset = (
suggestion_services
.get_reviewable_question_suggestions_by_offset(
self.user_id, limit, offset))
self.user_id, limit, offset, sort_key))
self._render_suggestions(target_type, suggestions, next_offset)


Expand All @@ -778,6 +790,7 @@ class UserSubmittedSuggestionsHandlerNormalizedRequestDict(TypedDict):

limit: int
offset: int
sort_key: str


class UserSubmittedSuggestionsHandler(
Expand Down Expand Up @@ -823,6 +836,12 @@ class UserSubmittedSuggestionsHandler(
'min_value': 0
}]
}
},
'sort_key': {
'schema': {
'type': 'basestring'
},
'choices': feconf.SUGGESTIONS_SORT_KEYS,
}
}
}
Expand All @@ -841,9 +860,10 @@ def get(self, target_type: str, suggestion_type: str) -> None:
target_type, suggestion_type)
limit = self.normalized_request['limit']
offset = self.normalized_request['offset']
sort_key = self.normalized_request['sort_key']
suggestions, next_offset = (
suggestion_services.get_submitted_suggestions_by_offset(
self.user_id, suggestion_type, limit, offset
self.user_id, suggestion_type, limit, offset, sort_key
)
)
if suggestion_type == feconf.SUGGESTION_TYPE_TRANSLATE_CONTENT:
Expand Down Expand Up @@ -873,7 +893,8 @@ def get(self, target_type: str, suggestion_type: str) -> None:
self.user_id,
feconf.SUGGESTION_TYPE_TRANSLATE_CONTENT,
limit,
next_offset
next_offset,
sort_key
)
)
suggestions_with_translatable_exps = (
Expand Down
66 changes: 44 additions & 22 deletions core/controllers/suggestion_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2476,7 +2476,8 @@ def test_suggestion_not_included_when_exploration_is_not_editable(
response = self.get_json(
'/getsubmittedsuggestions/exploration/translate_content', {
'limit': constants.OPPORTUNITIES_PAGE_SIZE,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
})
self.assertEqual(len(response['suggestions']), 1)

Expand All @@ -2485,7 +2486,8 @@ def test_suggestion_not_included_when_exploration_is_not_editable(
response = self.get_json(
'/getsubmittedsuggestions/exploration/translate_content', {
'limit': constants.OPPORTUNITIES_PAGE_SIZE,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
})

self.assertEqual(len(response['suggestions']), 0)
Expand All @@ -2496,7 +2498,8 @@ def test_exploration_handler_returns_data(self) -> None:
response = self.get_json(
'/getsubmittedsuggestions/exploration/translate_content', {
'limit': constants.OPPORTUNITIES_PAGE_SIZE,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
})
self.assertEqual(len(response['suggestions']), 1)
self.assertEqual(len(response['target_id_to_opportunity_dict']), 1)
Expand All @@ -2505,7 +2508,8 @@ def test_exploration_handler_returns_data(self) -> None:
response = self.get_json(
'/getsubmittedsuggestions/topic/translate_content', {
'limit': constants.OPPORTUNITIES_PAGE_SIZE,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
})
self.assertEqual(response, {})

Expand All @@ -2515,7 +2519,8 @@ def test_skill_handler_returns_data(self) -> None:
response = self.get_json(
'/getsubmittedsuggestions/skill/add_question', {
'limit': constants.OPPORTUNITIES_PAGE_SIZE,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
})
self.assertEqual(len(response['suggestions']), 1)
self.assertEqual(len(response['target_id_to_opportunity_dict']), 1)
Expand All @@ -2524,7 +2529,8 @@ def test_skill_handler_returns_data(self) -> None:
response = self.get_json(
'/getsubmittedsuggestions/topic/add_question', {
'limit': constants.OPPORTUNITIES_PAGE_SIZE,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
})
self.assertEqual(response, {})

Expand All @@ -2537,7 +2543,8 @@ def test_question_suggestions_data_for_deleted_opportunities(
response = self.get_json(
'/getsubmittedsuggestions/skill/add_question', {
'limit': constants.OPPORTUNITIES_PAGE_SIZE,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
})
self.assertEqual(len(response['suggestions']), 1)
self.assertEqual(len(response['target_id_to_opportunity_dict']), 1)
Expand All @@ -2554,7 +2561,8 @@ def test_translation_suggestions_data_for_deleted_opportunities(
response = self.get_json(
'/getsubmittedsuggestions/exploration/translate_content', {
'limit': constants.OPPORTUNITIES_PAGE_SIZE,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
})
self.assertEqual(len(response['suggestions']), 1)
self.assertEqual(len(response['target_id_to_opportunity_dict']), 1)
Expand Down Expand Up @@ -2597,7 +2605,8 @@ def test_translation_suggestions_fetches_extra_page_if_filtered_result_is_empty(
response = self.get_json(
'/getsubmittedsuggestions/exploration/translate_content', {
'limit': 1,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
})

# The new translation suggestion is returned first, but because it is
Expand All @@ -2615,14 +2624,16 @@ def test_handler_with_invalid_suggestion_type_raise_error(self) -> None:
response = self.get_json(
'/getsubmittedsuggestions/exploration/translate_content', {
'limit': constants.OPPORTUNITIES_PAGE_SIZE,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
})
self.assertEqual(len(response['suggestions']), 1)

self.get_json(
'/getsubmittedsuggestions/exploration/invalid_suggestion_type', {
'limit': constants.OPPORTUNITIES_PAGE_SIZE,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
},
expected_status_int=400)

Expand All @@ -2632,14 +2643,16 @@ def test_handler_with_invalid_target_type_raise_error(self) -> None:
response = self.get_json(
'/getsubmittedsuggestions/exploration/translate_content', {
'limit': constants.OPPORTUNITIES_PAGE_SIZE,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
})
self.assertEqual(len(response['suggestions']), 1)

self.get_json(
'/getsubmittedsuggestions/invalid_target_type/translate_content', {
'limit': constants.OPPORTUNITIES_PAGE_SIZE,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
}, expected_status_int=400)


Expand Down Expand Up @@ -2794,7 +2807,8 @@ def test_exploration_handler_returns_data_with_no_exploration_id(
response = self.get_json(
'/getreviewablesuggestions/exploration/translate_content', {
'limit': constants.OPPORTUNITIES_PAGE_SIZE,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
})
self.assertEqual(len(response['suggestions']), 0)
self.assertEqual(response['next_offset'], 0)
Expand All @@ -2806,7 +2820,8 @@ def test_exploration_handler_returns_data_with_valid_exploration_id(
'/getreviewablesuggestions/exploration/translate_content', params={
'exploration_id': self.EXP_ID,
'limit': constants.OPPORTUNITIES_PAGE_SIZE,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
})
self.assertEqual(len(response['suggestions']), 1)
self.assertEqual(response['next_offset'], 1)
Expand Down Expand Up @@ -2893,7 +2908,8 @@ def test_exploration_handler_does_not_return_obsolete_suggestions(
'/getreviewablesuggestions/exploration/translate_content', params={
'exploration_id': exp_100.id,
'limit': constants.OPPORTUNITIES_PAGE_SIZE,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
})
self.assertEqual(len(response['suggestions']), 1)
self.assertEqual(response['next_offset'], 1)
Expand Down Expand Up @@ -2926,7 +2942,8 @@ def test_exploration_handler_does_not_return_obsolete_suggestions(
'/getreviewablesuggestions/exploration/translate_content', params={
'exploration_id': exp_100.id,
'limit': constants.OPPORTUNITIES_PAGE_SIZE,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
})
self.assertEqual(len(response['suggestions']), 0)
self.assertEqual(response['next_offset'], 1)
Expand All @@ -2935,15 +2952,17 @@ def test_topic_translate_handler_returns_no_data(self) -> None:
response = self.get_json(
'/getreviewablesuggestions/topic/translate_content', {
'limit': constants.OPPORTUNITIES_PAGE_SIZE,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
})
self.assertEqual(response, {})

def test_skill_handler_returns_data(self) -> None:
response = self.get_json(
'/getreviewablesuggestions/skill/add_question', {
'limit': constants.OPPORTUNITIES_PAGE_SIZE,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
})
self.assertEqual(len(response['suggestions']), 1)
suggestion = response['suggestions'][0]
Expand Down Expand Up @@ -2984,15 +3003,17 @@ def test_topic_question_handler_returns_no_data(self) -> None:
response = self.get_json(
'/getreviewablesuggestions/topic/add_question', {
'limit': constants.OPPORTUNITIES_PAGE_SIZE,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
})
self.assertEqual(response, {})

def test_handler_with_invalid_suggestion_type_raise_error(self) -> None:
self.get_json(
'/getreviewablesuggestions/exploration/invalid_suggestion_type', {
'limit': constants.OPPORTUNITIES_PAGE_SIZE,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
},
expected_status_int=404
)
Expand All @@ -3001,7 +3022,8 @@ def test_handler_with_invalid_target_type_raise_error(self) -> None:
self.get_json(
'/getreviewablesuggestions/invalid_target_type/translate_content', {
'limit': constants.OPPORTUNITIES_PAGE_SIZE,
'offset': 0
'offset': 0,
'sort_key': constants.SUGGESTIONS_SORT_KEY_DATE
},
expected_status_int=400
)
Loading