-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add endpoint retrieving default card options (#1461)
Will be used to keep all of the card options in one place.
- Loading branch information
Showing
6 changed files
with
259 additions
and
11 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
src/controllers/SettingsController/SettingsController.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,74 @@ | ||
import SettingsService, { IServiceSettings } from '../../services/SettingsService'; | ||
import SettingsController from './SettingsController'; | ||
import { SettingsInitializer } from '../../data_layer/public/Settings'; | ||
|
||
class FakeSettingsService implements IServiceSettings { | ||
create(settings: SettingsInitializer): Promise<number[]> { | ||
return Promise.resolve([]); | ||
} | ||
delete(owner: string, id: string): Promise<void> { | ||
return Promise.resolve() | ||
} | ||
|
||
getById(id: string): Promise<SettingsInitializer> { | ||
return Promise.resolve({ | ||
object_id: "1", | ||
owner: "1", | ||
payload: "payload" | ||
}) | ||
} | ||
} | ||
|
||
describe("SettingsController", () => { | ||
|
||
test("returns default settings for client", () => { | ||
const settingsController = new SettingsController(new FakeSettingsService()); | ||
const defaultOptions = settingsController.getDefaultSettingsCardOptions('client'); | ||
|
||
expect(defaultOptions).toStrictEqual( | ||
{ | ||
"add-notion-link": "false", | ||
"use-notion-id": "true", | ||
"all": "true", | ||
"paragraph": "false", | ||
"cherry": "false", | ||
"avocado": "false", | ||
"tags": "false", | ||
"cloze": "true", | ||
"enable-input": "false", | ||
"basic-reversed": "false", | ||
"reversed": "false", | ||
"no-underline": "false", | ||
"max-one-toggle-per-card": "true", | ||
"remove-mp3-links": "true", | ||
"perserve-newlines": "true" | ||
} | ||
); | ||
}) | ||
|
||
test("returns default settings for server", () => { | ||
const settingsController = new SettingsController(new FakeSettingsService()); | ||
const defaultOptions = settingsController.getDefaultSettingsCardOptions('server'); | ||
|
||
expect(defaultOptions).toStrictEqual( | ||
{ | ||
'add-notion-link': 'false', | ||
'use-notion-id': 'true', | ||
"all": 'true', | ||
"paragraph": 'false', | ||
"cherry": 'false', | ||
"avocado": 'false', | ||
"tags": 'true', | ||
"cloze": 'true', | ||
'enable-input': 'false', | ||
'basic-reversed': 'false', | ||
"reversed": 'false', | ||
'no-underline': 'false', | ||
'max-one-toggle-per-card': 'true', | ||
'perserve-newlines': 'false', | ||
'page-emoji': 'first-emoji', | ||
} | ||
); | ||
}) | ||
|
||
}) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
export class CardOption { | ||
key: string; | ||
|
||
label: string; | ||
|
||
value: boolean; | ||
|
||
description: string; | ||
|
||
constructor( | ||
key: string, | ||
label: string, | ||
description: string, | ||
defaultValue: boolean | ||
) { | ||
this.key = key; | ||
this.label = label; | ||
this.description = description; | ||
this.value = defaultValue; | ||
} | ||
} | ||
|
||
const supportedOptions = (): CardOption[] => { | ||
const v = [ | ||
new CardOption( | ||
'add-notion-link', | ||
'Add Notion Link', | ||
'Add a link to the Notion page where the toggle was created. Please use this with the (Use Notion ID) to avoid duplicates.', | ||
false | ||
), | ||
new CardOption( | ||
'use-notion-id', | ||
'Use Notion ID', | ||
'By default we create a new id from your fields. This can cause duplicates and in those cases you want to enable the Notion ID which is more reliable and avoid duplicates.', | ||
true | ||
), | ||
new CardOption( | ||
'all', | ||
'Use All Toggle Lists', | ||
'By default we only check for toggle lists in the first page. Use this option to retreive toggle lists from anywhere in the page.', | ||
true | ||
), | ||
new CardOption( | ||
'paragraph', | ||
'Use Plain Text for Back', | ||
'This option will remove formatting and get the text content only.', | ||
false | ||
), | ||
new CardOption( | ||
'cherry', | ||
'Enable Cherry Picking Using 🍒 Emoji', | ||
'This will Only create flashcards from the toggle lists that include 🍒 in the toggle (header or body)', | ||
false | ||
), | ||
new CardOption( | ||
'avocado', | ||
"Only Create Flashcards From Toggles That Don't Have The 🥑 Emoji", | ||
"This option enables you to ignore certain toggles when creating flashcards from pages that you don't want to change too much.", | ||
false | ||
), | ||
new CardOption( | ||
'tags', | ||
'Treat Strikethrough as Tags', | ||
'This will go treat the strikethroughs in the page as global ones. The ones inside of a toggle will be treated as locally to the toggle.', | ||
false | ||
), | ||
new CardOption( | ||
'cloze', | ||
'Cloze Deletion', | ||
'Create cloze flashcards from code blocks.', | ||
true | ||
), | ||
new CardOption( | ||
'enable-input', | ||
'Treat Bold Text as Input', | ||
'Words marked as bold will be removed and you will have to enter them in when reviewing the card. This is useful when you need to type out the answer.', | ||
false | ||
), | ||
new CardOption( | ||
'basic-reversed', | ||
'Basic and Reversed', | ||
'Create the question and answer flashcards but also reversed ones. Where the answer and question change places.', | ||
false | ||
), | ||
new CardOption( | ||
'reversed', | ||
'Just the Reversed Flashcards', | ||
'Only create flashcards from the reverse. This is useful when you want to say show an image first.', | ||
false | ||
), | ||
new CardOption( | ||
'no-underline', | ||
'Remove Underlines', | ||
'Disable underline. This is an option that was created due to changes in the way Notion handles underlines.', | ||
false | ||
), | ||
new CardOption( | ||
'max-one-toggle-per-card', | ||
'Maximum One Toggle Per Card', | ||
"This will limit to 1 card so you don't see too many toggles in one card. When you combine this with 'Use all toggle lists' you can create flashcards from everything in your upload, regardless of how deeply nested they are.", | ||
true | ||
), | ||
new CardOption( | ||
'remove-mp3-links', | ||
'Remove the MP3 Links Created From Audio Files', | ||
"Due to backwards-compatability we leave links untouched but this option let's you remove mp3 links", | ||
true | ||
), | ||
new CardOption( | ||
'perserve-newlines', | ||
'Preserve Newlines in the Toggle Header and Body', | ||
'This will allow you to use SHIFT-Enter in the toggles to create multiple lines for all card types (Basic, Cloze, etc.)', | ||
true | ||
), | ||
]; | ||
|
||
return v.filter(Boolean); | ||
}; | ||
|
||
export default supportedOptions; |
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