refactor: Use identifier instead of name

feat: Create EditorIdentifier enum
This commit is contained in:
Aman Harwara
2021-10-01 20:39:52 +05:30
parent f6c019b63c
commit c48d9f2230

View File

@@ -20,22 +20,38 @@ type Props = {
application: WebApplication; application: WebApplication;
}; };
const getEditorIconType = (name: string): IconType | null => { enum EditorIdentifier {
switch (name) { PlainEditor = 'plain-editor',
case 'Bold Editor': BoldEditor = 'org.standardnotes.bold-editor',
case 'Plus Editor': CodeEditor = 'org.standardnotes.code-editor',
return 'rich-text'; MarkdownBasic = 'org.standardnotes.simple-markdown-editor',
case 'TokenVault': MarkdownMath = 'org.standardnotes.fancy-markdown-editor',
return 'authenticator'; MarkdownMinimist = 'org.standardnotes.minimal-markdown-editor',
case 'Secure Spreadsheets': MarkdownPro = 'org.standardnotes.advanced-markdown-editor',
return 'spreadsheets'; PlusEditor = 'org.standardnotes.plus-editor',
case 'Task Editor': SecureSpreadsheets = 'org.standardnotes.standard-sheets',
return 'tasks'; TaskEditor = 'org.standardnotes.simple-task-editor',
case 'Code Editor': TokenVault = 'org.standardnotes.token-vault',
return 'code';
} }
if (name.includes('Markdown')) {
const getEditorIconType = (identifier: string): IconType | null => {
switch (identifier) {
case EditorIdentifier.BoldEditor:
case EditorIdentifier.PlusEditor:
return 'rich-text';
case EditorIdentifier.MarkdownBasic:
case EditorIdentifier.MarkdownMath:
case EditorIdentifier.MarkdownMinimist:
case EditorIdentifier.MarkdownPro:
return 'markdown'; return 'markdown';
case EditorIdentifier.TokenVault:
return 'authenticator';
case EditorIdentifier.SecureSpreadsheets:
return 'spreadsheets';
case EditorIdentifier.TaskEditor:
return 'tasks';
case EditorIdentifier.CodeEditor:
return 'code';
} }
return null; return null;
}; };
@@ -87,11 +103,12 @@ export const Defaults: FunctionComponent<Props> = ({ application }) => {
return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1; return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1;
}) })
.map((editor) => { .map((editor) => {
const iconType = getEditorIconType(editor.name); const identifier = editor.package_info.identifier;
const iconType = getEditorIconType(identifier);
return { return {
label: editor.name, label: editor.name,
value: editor.package_info.identifier, value: identifier,
...(iconType ? { icon: iconType } : null), ...(iconType ? { icon: iconType } : null),
}; };
}); });