Skip to content

Commit

Permalink
fix(options): 🚑 fix select validators
Browse files Browse the repository at this point in the history
previously, the instances of the Select classes were being created before the CONFIGURATION input getters were executed, which meant that the instance returned by the getter didn't have a validator registered

hence, there was no input validation, as this.validator was undefined
  • Loading branch information
JamesNZL committed Jul 17, 2022
1 parent e5eeeea commit cf053b4
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/options/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Storage } from '../apis/storage';
import { OAuth2 } from '../apis/oauth';

import { SavedFields } from './';
import { EmojiField, InputFieldValidator } from './validator';
import { EmojiField, InputFieldValidator, RequiredNotionDatabaseIdField, RequiredStringField, StringField } from './validator';
import { CONFIGURATION, SupportedTypes } from './configuration';

import { Element, Button, Select, KeyValueGroup } from '../elements';
Expand Down Expand Up @@ -133,43 +133,52 @@ const OAuth2Button = <const>{
};

const DatabaseSelect = <const>{
element: Select.getInstance<OptionsSelectId>({ id: 'database-id' }),
element: Select.getInstance<OptionsSelectId>({
id: 'database-id',
Validator: RequiredNotionDatabaseIdField,
}),
refreshButton: Button.getInstance<OptionsButtonId>({ id: 'refresh-database-select' }),
propertySelects: {
// TODO: add validators
name: PropertySelect.getInstance<OptionsSelectId>({
id: 'notion-property-name',
type: 'title',
Validator: RequiredStringField,
fieldKey: 'notion.propertyNames.name',
}),
category: PropertySelect.getInstance<OptionsSelectId>({
id: 'notion-property-category',
type: 'select',
Validator: StringField,
fieldKey: 'notion.propertyNames.category',
}),
course: PropertySelect.getInstance<OptionsSelectId>({
id: 'notion-property-course',
type: 'select',
Validator: StringField,
fieldKey: 'notion.propertyNames.course',
}),
url: PropertySelect.getInstance<OptionsSelectId>({
id: 'notion-property-url',
type: 'url',
Validator: StringField,
fieldKey: 'notion.propertyNames.url',
}),
available: PropertySelect.getInstance<OptionsSelectId>({
id: 'notion-property-available',
type: 'date',
Validator: StringField,
fieldKey: 'notion.propertyNames.available',
}),
due: PropertySelect.getInstance<OptionsSelectId>({
id: 'notion-property-due',
type: 'date',
Validator: StringField,
fieldKey: 'notion.propertyNames.due',
}),
span: PropertySelect.getInstance<OptionsSelectId>({
id: 'notion-property-span',
type: 'date',
Validator: StringField,
fieldKey: 'notion.propertyNames.span',
}),
},
Expand All @@ -178,6 +187,7 @@ const DatabaseSelect = <const>{
return SelectPropertyValueSelect.getInstance<OptionsSelectId>({
id: 'notion-category-canvas',
type: 'select',
Validator: StringField,
fieldKey: 'notion.propertyValues.categoryCanvas',
getDatabaseId: DatabaseSelect.element.validate.bind(DatabaseSelect.element),
propertySelect: DatabaseSelect.propertySelects.category,
Expand Down

0 comments on commit cf053b4

Please sign in to comment.