Skip to content

Commit

Permalink
fix: Constructor validation using the zones to correctly match value. (
Browse files Browse the repository at this point in the history
…#243)

The constructor validation was not using the validation zones which was missing the value check since it was not using the `_data` portion of the constructor value.
  • Loading branch information
Zoramite authored Nov 3, 2021
1 parent 732481b commit a8d7054
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 19 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"webpack-merge": "^5.8.0"
},
"dependencies": {
"@blinkk/selective-edit": "^3.2.2",
"@blinkk/selective-edit": "^3.2.3",
"@toast-ui/editor": "^3.1.1",
"bent": "^7.3.12",
"codemirror": "^5.63.3",
Expand Down
2 changes: 1 addition & 1 deletion src/ts/editor/ui/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {LazyUiParts} from './parts';
import {OnboardingStatus} from '../api';
import {EVENT_RENDER as SELECTIVE_EVENT_RENDER} from '@blinkk/selective-edit/dist/selective/events';
import TimeAgo from 'javascript-time-ago';
import en from 'javascript-time-ago/locale/en.json';
import en from '../../timeago-locale-en.json';
import {templateLoading} from '../template';

// Set the default locale for the time ago globally.
Expand Down
24 changes: 19 additions & 5 deletions src/ts/projectType/generic/field/constructor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,9 @@ export class AutocompleteConstructorField
* Template for showing a preview specific to the value of the field.
*/
templateValuePreview(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
editor: SelectiveEditor,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
data: DeepObject
): TemplateResult {
return html``;
Expand All @@ -219,10 +221,22 @@ export class AutocompleteConstructorField
* @param errorMessage Error message shown when the value is not valid.
*/
updateValidation(validValues: Array<string | RegExp>, errorMessage: string) {
this.config.validation = (this.config.validation ||
[]) as Array<RuleConfig>;
if (!this.config.validation) {
// If there is no validation, default to a zone based to support the constructor _data.
this.config.validation = {} as Record<string, Array<RuleConfig>>;
this.config.validation[DEFAULT_ZONE_KEY] = [];
} else if (DataType.isArray(this.config.validation)) {
// If there are non-zone based validation, convert it to use the zone.
const originalValidation = this.config.validation as Array<RuleConfig>;
this.config.validation = {} as Record<string, Array<RuleConfig>>;
this.config.validation[DEFAULT_ZONE_KEY] = originalValidation;
}
const validationZone = (
this.config.validation as Record<string, Array<RuleConfig>>
)[DEFAULT_ZONE_KEY];

const existingIndex = this.listItemValidationRule
? this.config.validation.indexOf(this.listItemValidationRule)
? validationZone.indexOf(this.listItemValidationRule)
: -1;

// Validate the field to ensure that the document is
Expand All @@ -237,10 +251,10 @@ export class AutocompleteConstructorField

if (existingIndex >= 0) {
// Replace the existing rule.
this.config.validation[existingIndex] = this.listItemValidationRule;
validationZone[existingIndex] = this.listItemValidationRule;
} else {
// Add as new rule.
this.config.validation.push(this.listItemValidationRule);
validationZone.push(this.listItemValidationRule);
}

// Reset the compiled rules.
Expand Down
1 change: 1 addition & 0 deletions src/ts/timeago-locale-en.json
32 changes: 20 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,14 @@
"@babel/helper-validator-identifier" "^7.15.7"
to-fast-properties "^2.0.0"

"@blinkk/selective-edit@^3.2.2":
version "3.2.2"
resolved "https://registry.yarnpkg.com/@blinkk/selective-edit/-/selective-edit-3.2.2.tgz#0b1c3fb70e4ba76c71adc2d5f968aa67e52dbbad"
integrity sha512-1gUfu7haGgI+BKTL5zxNTxerIkXS1DPCXOgD4iaqUf+IDLF549eCBplRE5D2TjWt0jmmJ/G3ROzLzL1Wl90mEA==
"@blinkk/selective-edit@^3.2.3":
version "3.2.3"
resolved "https://registry.yarnpkg.com/@blinkk/selective-edit/-/selective-edit-3.2.3.tgz#72406fd56d9e2ca1f81dcca5fa81d576a90c836c"
integrity sha512-QS+hpAhHT2RswjSzlLqAym3aOPoAg82sz3JSIu51a0XSZvNvdm3yhJHrmbFMQ1dE8OpJeH1ph1mHHAPzYr9w3w==
dependencies:
eslint-plugin-node "^11.1.0"
json-stable-stringify "^1.0.1"
lit-html "^1.4.1"
lit-html "^2.0.1"
lodash.clonedeep "^4.5.0"
lodash.merge "^4.6.2"

Expand Down Expand Up @@ -608,6 +609,11 @@
"@types/mime" "^1"
"@types/node" "*"

"@types/trusted-types@^2.0.2":
version "2.0.2"
resolved "https://registry.yarnpkg.com/@types/trusted-types/-/trusted-types-2.0.2.tgz#fc25ad9943bcac11cceb8168db4f275e0e72e756"
integrity sha512-F5DIZ36YVLE+PN+Zwws4kJogq47hNgX3Nx6WyDJ3kcplxyke3XIzB8uK5n/Lpm1HBsbGzd6nmGehL8cPekP+Tg==

"@types/yauzl@^2.9.1":
version "2.9.2"
resolved "https://registry.yarnpkg.com/@types/yauzl/-/yauzl-2.9.2.tgz#c48e5d56aff1444409e39fa164b0b4d4552a7b7a"
Expand Down Expand Up @@ -1976,9 +1982,9 @@ ee-first@1.1.1:
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=

electron-to-chromium@^1.3.886:
version "1.3.887"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.887.tgz#b36aeed12a28aaa19460a467823f5bbe1f3c6f06"
integrity sha512-QQUumrEjFDKSVYVdaeBmFdyQGoaV+fCSMyWHvfx/u22bRHSTeBQYt6P4jMY+gFd4kgKB9nqk7RMtWkDB49OYPA==
version "1.3.888"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.888.tgz#243204af9b4c928ac45e47dbbe7bc44c30e65bf0"
integrity sha512-5iD1zgyPpFER4kJ716VsA4MxQ6x405dxdFNCEK2mITL075VHO5ResjY0xzQUZguCww/KlBxCA6JmBA9sDt1PRw==

emittery@^0.8.0:
version "0.8.1"
Expand Down Expand Up @@ -3473,10 +3479,12 @@ lines-and-columns@^1.1.6:
resolved "https://registry.yarnpkg.com/lines-and-columns/-/lines-and-columns-1.1.6.tgz#1c00c743b433cd0a4e80758f7b64a57440d9ff00"
integrity sha1-HADHQ7QzzQpOgHWPe2SldEDZ/wA=

lit-html@^1.4.1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/lit-html/-/lit-html-1.4.1.tgz#0c6f3ee4ad4eb610a49831787f0478ad8e9ae5e0"
integrity sha512-B9btcSgPYb1q4oSOb/PrOT6Z/H+r6xuNzfH4lFli/AWhYwdtrgQkQWBbIc6mdnf6E2IL3gDXdkkqNktpU0OZQA==
lit-html@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/lit-html/-/lit-html-2.0.1.tgz#63241015efa07bc9259b6f96f04abd052d2a1f95"
integrity sha512-KF5znvFdXbxTYM/GjpdOOnMsjgRcFGusTnB54ixnCTya5zUR0XqrDRj29ybuLS+jLXv1jji6Y8+g4W7WP8uL4w==
dependencies:
"@types/trusted-types" "^2.0.2"

load-json-file@^5.2.0:
version "5.3.0"
Expand Down

0 comments on commit a8d7054

Please sign in to comment.