-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
馃З feat order by suggestion score (#4731)
- [x] Order by suggestion score. ![Screenshot 2024-04-23 at 09 09 57](https://github.com/argilla-io/argilla/assets/7398909/bcdf446d-2ec1-449e-91bc-420982ac0a81) ![Screenshot 2024-04-23 at 09 09 53](https://github.com/argilla-io/argilla/assets/7398909/0b6212f5-69c7-495a-b736-064b814c7b1b)
- Loading branch information
1 parent
b35c843
commit 2c1a792
Showing
10 changed files
with
199 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
frontend/v1/domain/entities/question/QuestionSetting.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { QuestionSetting } from "./QuestionSetting"; | ||
|
||
describe("QuestionSetting", () => { | ||
describe("suggestionFirst", () => { | ||
test("return true when options_order is suggestion", () => { | ||
const setting = new QuestionSetting({ options_order: "suggestion" }); | ||
expect(setting.suggestionFirst).toBeTruthy(); | ||
}); | ||
test("return false when options_order is natural", () => { | ||
const setting = new QuestionSetting({ options_order: "natural" }); | ||
expect(setting.suggestionFirst).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe("isEqual", () => { | ||
test("return false when options_order is different", () => { | ||
const setting = new QuestionSetting({ options_order: "suggestion" }); | ||
const setting2 = new QuestionSetting({ options_order: "natural" }); | ||
expect(setting.isEqual(setting2)).toBeFalsy(); | ||
}); | ||
|
||
test("return false when use_markdown is different", () => { | ||
const setting = new QuestionSetting({ use_markdown: true }); | ||
const setting2 = new QuestionSetting({ use_markdown: false }); | ||
expect(setting.isEqual(setting2)).toBeFalsy(); | ||
}); | ||
|
||
test("return false when visible_options is different", () => { | ||
const setting = new QuestionSetting({ visible_options: 1 }); | ||
const setting2 = new QuestionSetting({ visible_options: 2 }); | ||
expect(setting.isEqual(setting2)).toBeFalsy(); | ||
}); | ||
|
||
test("return false when options are different", () => { | ||
const setting = new QuestionSetting({ options: ["a"] }); | ||
const setting2 = new QuestionSetting({ options: ["b"] }); | ||
expect(setting.isEqual(setting2)).toBeFalsy(); | ||
}); | ||
|
||
test("return false if options are in different positions", () => { | ||
const setting = new QuestionSetting({ options: ["a", "b"] }); | ||
const setting2 = new QuestionSetting({ options: ["b", "a"] }); | ||
expect(setting.isEqual(setting2)).toBeFalsy(); | ||
}); | ||
|
||
test("return true when all properties are the same", () => { | ||
const setting = new QuestionSetting({ | ||
options_order: "suggestion", | ||
use_markdown: true, | ||
visible_options: 1, | ||
options: ["a"], | ||
}); | ||
const setting2 = new QuestionSetting({ | ||
options_order: "suggestion", | ||
use_markdown: true, | ||
visible_options: 1, | ||
options: ["a"], | ||
}); | ||
expect(setting.isEqual(setting2)).toBeTruthy(); | ||
}); | ||
}); | ||
|
||
describe("shouldShowVisibleOptions", () => { | ||
test("return false when options are less than 3", () => { | ||
const setting = new QuestionSetting({ options: ["a", "b"] }); | ||
expect(setting.shouldShowVisibleOptions).toBeFalsy(); | ||
}); | ||
|
||
test("return false when visible_options is not present", () => { | ||
const setting = new QuestionSetting({ options: ["a", "b", "c"] }); | ||
expect(setting.shouldShowVisibleOptions).toBeFalsy(); | ||
}); | ||
|
||
test("return true when options are more than 3 and visible_options is present", () => { | ||
const setting = new QuestionSetting({ | ||
options: ["a", "b", "c", "d"], | ||
visible_options: 3, | ||
}); | ||
expect(setting.shouldShowVisibleOptions).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
export class QuestionSetting { | ||
type: | ||
| "text" | ||
| "ranking" | ||
| "multi_label_selection" | ||
| "label_selection" | ||
| "span"; | ||
|
||
use_markdown: boolean; | ||
visible_options: number; | ||
allow_overlapping: boolean; | ||
allow_character_annotation: boolean; | ||
field: string; | ||
options: any; | ||
options_order: "natural" | "suggestion"; | ||
|
||
constructor(private readonly settings: any) { | ||
this.type = settings.type; | ||
|
||
this.use_markdown = settings.use_markdown; | ||
this.visible_options = settings.visible_options; | ||
this.options = settings.options; | ||
this.options_order = settings.options_order; | ||
this.allow_overlapping = settings.allow_overlapping; | ||
this.allow_character_annotation = settings.allow_character_annotation; | ||
this.field = settings.field; | ||
} | ||
|
||
get suggestionFirst() { | ||
if (!this.options_order) return undefined; | ||
|
||
return this.options_order === "suggestion"; | ||
} | ||
|
||
set suggestionFirst(value: boolean) { | ||
this.options_order = value ? "suggestion" : "natural"; | ||
} | ||
|
||
get shouldShowVisibleOptions() { | ||
return this.options?.length > 3 && "visible_options" in this.settings; | ||
} | ||
|
||
isEqual(setting: QuestionSetting) { | ||
return ( | ||
this.use_markdown === setting.use_markdown && | ||
this.visible_options === setting.visible_options && | ||
this.options_order === setting.options_order && | ||
JSON.stringify(this.options) === JSON.stringify(setting.options) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters