Correct semantic check for feature name and type
This commit is contained in:
Родитель
e1aea66034
Коммит
18e91819e5
|
@ -14,7 +14,7 @@ import {
|
|||
WEB_DEV_VIEWS,
|
||||
} from './form-field-enums';
|
||||
|
||||
import {checkMilestoneStartEnd} from './utils.js';
|
||||
import {checkFeatureNameAndType, checkMilestoneStartEnd} from './utils.js';
|
||||
|
||||
/* Patterns from https://www.oreilly.com/library/view/regular-expressions-cookbook/9781449327453/ch04s01.html
|
||||
* Removing single quote ('), backtick (`), and pipe (|) since they are risky unless properly escaped everywhere.
|
||||
|
@ -110,21 +110,10 @@ export const ALL_FIELDS = {
|
|||
<li>CSS Flexbox: intrinsic size algorithm</li>
|
||||
<li>Permissions-Policy header</li>
|
||||
</ul>`,
|
||||
check: (value, getFieldValue) => {
|
||||
// if the name includes "deprecate" or "remove",
|
||||
// the feature_type should be "Feature deprecation".
|
||||
const name = (value || '').toLowerCase();
|
||||
if (name.includes('deprecat') || name.includes('remov')) {
|
||||
const featureType = Number(getFieldValue('feature_type_radio_group') ?? 0);
|
||||
if (featureType !== FEATURE_TYPES.FEATURE_TYPE_DEPRECATION_ID[0]) {
|
||||
return {
|
||||
warning: `Feature name should contain "deprecate" or "remove"
|
||||
if and only if the feature type is "Feature deprecation"`,
|
||||
};
|
||||
}
|
||||
}
|
||||
check: (_value, getFieldValue) => {
|
||||
return checkFeatureNameAndType(getFieldValue);
|
||||
},
|
||||
dependents: ['feature_type_radio_group'],
|
||||
dependents: ['feature_type', 'feature_type_radio_group'],
|
||||
},
|
||||
|
||||
'summary': {
|
||||
|
@ -270,6 +259,10 @@ export const ALL_FIELDS = {
|
|||
<p style="color: red"><strong>Note:</strong> The feature type field
|
||||
cannot be changed. If this field needs to be modified, a new feature
|
||||
would need to be created.</p>`,
|
||||
check: (_value, getFieldValue) => {
|
||||
return checkFeatureNameAndType(getFieldValue);
|
||||
},
|
||||
dependents: ['name'],
|
||||
},
|
||||
|
||||
'feature_type_radio_group': {
|
||||
|
@ -284,17 +277,8 @@ export const ALL_FIELDS = {
|
|||
<p style="color: red"><strong>Note:</strong> The feature type field
|
||||
cannot be changed. If this field needs to be modified, a new feature
|
||||
would need to be created.</p>`,
|
||||
check: (value, getFieldValue) => {
|
||||
const featureType = Number(value ?? 0);
|
||||
if (featureType === FEATURE_TYPES.FEATURE_TYPE_DEPRECATION_ID[0]) {
|
||||
const name = (getFieldValue('name') || '').toLowerCase();
|
||||
if (!(name.includes('deprecat') || name.includes('remov'))) {
|
||||
return {
|
||||
warning: `Feature name should contain "deprecate" or "remove"
|
||||
if and only if the feature type is "Feature deprecation"`,
|
||||
};
|
||||
}
|
||||
}
|
||||
check: (_value, getFieldValue) => {
|
||||
return checkFeatureNameAndType(getFieldValue);
|
||||
},
|
||||
dependents: ['name'],
|
||||
},
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
import {markupAutolinks} from './autolink.js';
|
||||
import {nothing, html} from 'lit';
|
||||
import {STAGE_FIELD_NAME_MAPPING} from './form-field-enums';
|
||||
import {STAGE_FIELD_NAME_MAPPING, FEATURE_TYPES} from './form-field-enums';
|
||||
|
||||
let toastEl;
|
||||
|
||||
|
@ -400,3 +400,26 @@ export function checkMilestoneStartEnd(startEndPair, getFieldValue) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function checkFeatureNameAndType(getFieldValue) {
|
||||
const name = (getFieldValue('name') || '').toLowerCase();
|
||||
const featureType = Number(getFieldValue('feature_type') || '0');
|
||||
const deprecationName =
|
||||
(name.includes('deprecat') || name.includes('remov'));
|
||||
const deprecationType =
|
||||
(featureType === FEATURE_TYPES.FEATURE_TYPE_DEPRECATION_ID[0]);
|
||||
if (deprecationName !== deprecationType) {
|
||||
if (deprecationName) {
|
||||
return {
|
||||
warning: `If the feature name contains "deprecate" or "remove",
|
||||
the feature type should be "Feature deprecation"`,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
warning: `If the feature type is "Feature deprecation",
|
||||
the feature name should contain "deprecate" or "remove"`,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче