Skip to content

Commit

Permalink
Made annotation text search independent of character case and Addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielDervishi committed Jul 21, 2023
1 parent d0c5f57 commit a1116ac
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
6 changes: 3 additions & 3 deletions app/assets/javascripts/Components/Modals/filter_modal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,14 @@ export class FilterModal extends React.Component {
<input
id="annotation"
type={"text"}
value={this.props.filterData.annotationValue}
value={this.props.filterData.annotationText}
onChange={e =>
this.props.mutateFilterData({
...this.props.filterData,
annotationValue: e.target.value,
annotationText: e.target.value,
})
}
placeholder={I18n.t("to")}
placeholder={I18n.t("results.filters.text_box_placeholder")}
/>
</label>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/Components/Result/result.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const INITIAL_ANNOTATION_MODAL_STATE = {

const INITIAL_FILTER_MODAL_STATE = {
ascBool: true,
orderBy: I18n.t("activerecord.attributes.group.group_name"),
annotationValue: "",
orderBy: "Group Name",
annotationText: "",
tas: [],
tags: [],
section: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe("FilterModal", () => {
filterData: {
ascBool: true,
orderBy: "Group Name",
annotationValue: "",
annotationText: "",
tas: ["a", "b"],
tags: ["a", "b"],
section: "",
Expand Down
10 changes: 5 additions & 5 deletions app/models/grouping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -743,8 +743,8 @@ def get_random_incomplete(current_role)

# Takes in a collection of results specified by +results+, and filters them using +filter_data+. Assumes
# +filter_data+ is not nil.
# +filter_data['annotationValue']+ is a string specifying some annotation text to filter by. To avoid this filtering
# option don't set +filter_data['annotationValue']+ (or set it to nil/'').
# +filter_data['annotationText']+ is a string specifying some annotation text to filter by. To avoid this filtering
# option don't set +filter_data['annotationText']+ (or set it to nil/'').
# +filter_data['section']+ is a string specifying the name of the section to filter by. To avoid this filtering
# option don't set +filter_data['section']+ (or set it to nil/'').
# +filter_data['markingStateValue']+ is a string specifying the marking state to filter by; valid strings
Expand All @@ -762,10 +762,10 @@ def get_random_incomplete(current_role)
# Note: min.to_f <= max.to_f. To not filter by total extra mark, pass in an empty hash or dont specify
# +filter_data['TotalExtraMarkRange']+.
def filter_results(current_role, results, filter_data)
if filter_data['annotationValue'].present?
if filter_data['annotationText'].present?
results = results.joins(annotations: :annotation_text)
.where('annotation_texts.content LIKE ?',
"%#{AnnotationText.sanitize_sql_like(filter_data['annotationValue'])}%")
.where('lower(annotation_texts.content) LIKE ?',
"%#{AnnotationText.sanitize_sql_like(filter_data['annotationText'].downcase)}%")
end
if filter_data['section'].present?
results = results.joins(grouping: :section).where('section.name': filter_data['section'])
Expand Down
12 changes: 6 additions & 6 deletions spec/controllers/results_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def self.test_unauthorized(route_name)
it 'should return a response with next_grouping and next_result set to nil' do
get :next_grouping, params: { course_id: course.id, grouping_id: grouping3.id,
id: grouping3.current_result.id,
direction: 1, filterData: { annotationValue: 'aa_' } }
direction: 1, filterData: { annotationText: 'aa_' } }
expect(response.parsed_body['next_grouping']).to be_nil
expect(response.parsed_body['next_result']).to be_nil
end
Expand All @@ -81,25 +81,25 @@ def self.test_unauthorized(route_name)
it 'should return a response with the next filtered group' do
get :next_grouping, params: { course_id: course.id, grouping_id: grouping1.id,
id: grouping1.current_result.id,
direction: 1, filterData: { annotationValue: 'aa_' } }
direction: 1, filterData: { annotationText: 'aa_' } }
expect(response.parsed_body['next_grouping']['id']).to eq(grouping3.id)
expect(response.parsed_body['next_result']['id']).to eq(grouping3.current_result.id)
end

it 'shouldn\'t return the next non-filtered group' do
get :next_grouping, params: { course_id: course.id, grouping_id: grouping1.id,
id: grouping1.current_result.id,
direction: 1, filterData: { annotationValue: 'aa_' } }
direction: 1, filterData: { annotationText: 'aa_' } }
expect(response.parsed_body['next_grouping']['id']).not_to eq(grouping2.id)
expect(response.parsed_body['next_result']['id']).not_to eq(grouping2.current_result.id)
end
end

context 'when annotationValue contains special characters (in the context of a like clause)' do
context 'when annotationText contains special characters (in the context of a like clause)' do
it 'should sanitize the string and return the next relevant result' do
get :next_grouping, params: { course_id: course.id, grouping_id: grouping1.id,
id: grouping1.current_result.id,
direction: 1, filterData: { annotationValue: 'aa_' } }
direction: 1, filterData: { annotationText: 'aa_' } }
expect(response.parsed_body['next_grouping']['id']).to eq(grouping3.id)
expect(response.parsed_body['next_result']['id']).to eq(grouping3.current_result.id)
end
Expand All @@ -109,7 +109,7 @@ def self.test_unauthorized(route_name)
it 'should return the next result containing the substring in one of its annotations' do
get :next_grouping, params: { course_id: course.id, grouping_id: grouping1.id,
id: grouping1.current_result.id,
direction: 1, filterData: { annotationValue: 'a' } }
direction: 1, filterData: { annotationText: 'a' } }
expect(response.parsed_body['next_grouping']['id']).to eq(grouping3.id)
expect(response.parsed_body['next_result']['id']).to eq(grouping3.current_result.id)
end
Expand Down

0 comments on commit a1116ac

Please sign in to comment.