Skip to content

Commit

Permalink
Fix validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgelenas committed Sep 15, 2024
1 parent b30e176 commit c8c2f1d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,4 @@ npm-debug.log.*
__pycache__
r2
crowdin_env.sh
purge.sh
27 changes: 11 additions & 16 deletions src/ui/views/ConfiguratorView/UserDefinesValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,22 @@ export default class UserDefinesValidator {

// if any regulatory domain options were present to the user it means that
// at least one of them has to be enabled
const regulatoryDomainKeys = Array.from(regulatoryDomains.values()).flat();
const regulatoryDefines = data.filter(({ key }) =>
regulatoryDomainKeys.includes(key)
);
const enabledRegulatoryDefines = data.filter(({ enabled }) => enabled);
if (regulatoryDefines.length > 0 && enabledRegulatoryDefines.length === 0) {
results.push(
new Error('You must choose a regulatory domain for your device')
);
}

regulatoryDomains.forEach(
(categoryUserDefines: UserDefineKey[], categoryName: string) => {
console.log('categoryUserDefines', categoryUserDefines);
const enabledDefines = data.filter(
({ key, enabled }) => categoryUserDefines.includes(key) && enabled
// check if we have any options present from the category
const userDefinesFilterByCategory = data.filter(({ key }) =>
categoryUserDefines.includes(key)
);
const enabledUserDefines = userDefinesFilterByCategory.filter(
({ enabled }) => enabled
);
if (enabledDefines.length > 1) {
if (
userDefinesFilterByCategory.length > 0 &&
enabledUserDefines.length === 0
) {
results.push(
new Error(
`You must choose single regulatory domain for your device in ${categoryName} band`
`You must choose regulatory domain for your device in ${categoryName} band`
)
);
}
Expand Down

0 comments on commit c8c2f1d

Please sign in to comment.