-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Limit VM name length to max k8s label length
- Loading branch information
Showing
8 changed files
with
103 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { MAX_K8S_NAME_LENGTH } from '@kubevirt-utils/utils/constants'; | ||
|
||
export const validateVMNameLength = (vmName: string): boolean => | ||
vmName.length <= MAX_K8S_NAME_LENGTH; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/views/catalog/wizard/tabs/overview/components/VMNameModal/utils/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { t } from '@kubevirt-utils/hooks/useKubevirtTranslation'; | ||
import { validateVMNameLength } from '@kubevirt-utils/resources/vm/utils/helpers'; | ||
import { MAX_K8S_NAME_LENGTH } from '@kubevirt-utils/utils/constants'; | ||
import { isEmpty } from '@kubevirt-utils/utils/utils'; | ||
import { ValidatedOptions } from '@patternfly/react-core'; | ||
|
||
export const isValidVMName = (vmName: string) => { | ||
const nameMissing = isEmpty(vmName); | ||
const nameTooLong = !validateVMNameLength(vmName); | ||
|
||
return nameMissing || nameTooLong ? ValidatedOptions.error : ValidatedOptions.default; | ||
}; | ||
|
||
export const getHelperTextMessage = (vmName: string): string => { | ||
const nameMissing = isEmpty(vmName); | ||
const nameTooLong = !validateVMNameLength(vmName); | ||
|
||
if (nameMissing) return t('VirtualMachine name can not be empty.'); | ||
if (nameTooLong) | ||
return t('Maximum name length is {{ maxNameLength }} characters', { | ||
maxNameLength: MAX_K8S_NAME_LENGTH, | ||
}); | ||
|
||
return t('Please provide name to VirtualMachine.'); | ||
}; |