Skip to content

Commit

Permalink
feat: add max validation rule for CPU and memory in Form.Item.
Browse files Browse the repository at this point in the history
  • Loading branch information
yomybaby authored and ironAiken2 committed Sep 5, 2024
1 parent 1f8a044 commit d933aec
Show file tree
Hide file tree
Showing 22 changed files with 75 additions and 21 deletions.
33 changes: 33 additions & 0 deletions react/src/components/ResourceAllocationFormItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,10 @@ const ResourceAllocationFormItems: React.FC<
min: resourceLimits.cpu?.min,
// TODO: set message
},
{
type: 'number',
max: resourceLimits.cpu?.max,
},
{
warningOnly: true,
validator: async (rule, value: number) => {
Expand Down Expand Up @@ -586,6 +590,35 @@ const ResourceAllocationFormItems: React.FC<
{
required: true,
},
{
validator: async (rule, value: string) => {
if (
_.isString(value) &&
resourceLimits.mem?.max &&
compareNumberWithUnits(
value,
resourceLimits.mem?.max,
) > 0
) {
return Promise.reject(
t('general.MaxValueNotification', {
name: t('session.launcher.Memory'),
max:
_.toUpper(
resourceLimits.mem?.max || '0g',
) + 'iB',
}),
// t('session.launcher.MinMemory', {
// size: _.toUpper(
// resourceLimits.mem?.min || '0g',
// ),
// }),
);
} else {
return Promise.resolve();
}
},
},
{
// TODO: min of mem should be shmem + image's mem limit??
validator: async (rule, value: string) => {
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@
"NSelected": "Ausgewählte(r) {{count}} Artikel",
"Extend": "Verlängern",
"RemainingLoginSessionTime": "Zeit bis zur automatischen Abmeldung",
"Change": "Ändern Sie"
"Change": "Ändern Sie",
"MaxValueNotification": "{{name}} muss maximal {{max}} sein"
},
"credential": {
"Permission": "Genehmigung",
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/el.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@
"NSelected": "Επιλεγμένο {{count}} στοιχείο(α)",
"Extend": "Επεκτείνω",
"RemainingLoginSessionTime": "Χρόνος μέχρι την αυτόματη αποσύνδεση",
"Change": "Αλλαγή"
"Change": "Αλλαγή",
"MaxValueNotification": "{{name}} πρέπει να είναι το μέγιστο {{max}}"
},
"credential": {
"Permission": "Αδεια",
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,8 @@
"NSelected": "Selected {{count}} item(s)",
"Extend": "Extend",
"RemainingLoginSessionTime": "Time until auto logout",
"Change": "Change"
"Change": "Change",
"MaxValueNotification": "{{name}} must be maximum {{max}}"
},
"credential": {
"Permission": "Permission",
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@
"NSelected": "Elemento(s) {{cuenta}} seleccionado(s)",
"Extend": "Extender",
"RemainingLoginSessionTime": "Tiempo hasta el cierre de sesión automático",
"Change": "Cambia"
"Change": "Cambia",
"MaxValueNotification": "{{name}} debe ser máximo {{max}}"
},
"import": {
"CleanUpImportTask": "Tarea de importación de limpieza...",
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/fi.json
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,8 @@
"NSelected": "Valittu {{count}} kohde(t)",
"Extend": "Laajenna",
"RemainingLoginSessionTime": "Aika automaattiseen uloskirjautumiseen asti",
"Change": "Muuta"
"Change": "Muuta",
"MaxValueNotification": "{{name}} on oltava maksimi {{max}}"
},
"import": {
"CleanUpImportTask": "Tuontitehtävän siivous...",
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@
"NSelected": "Élément(s) sélectionné(s) {{count}}",
"Extend": "Étendre",
"RemainingLoginSessionTime": "Délai avant déconnexion automatique",
"Change": "Changer"
"Change": "Changer",
"MaxValueNotification": "{{nom}} doit être maximum {{max}}"
},
"credential": {
"Permission": "Autorisation",
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/id.json
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,8 @@
"NSelected": "Item {{hitung}} yang dipilih",
"Extend": "Memperpanjang",
"RemainingLoginSessionTime": "Waktu Hingga Keluar Otomatis",
"Change": "Perubahan"
"Change": "Perubahan",
"MaxValueNotification": "{{nama}} harus maksimal {{max}}"
},
"credential": {
"Permission": "Izin",
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,8 @@
"NSelected": "Articolo/i selezionato/i {{count}}",
"Extend": "Estendere",
"RemainingLoginSessionTime": "Tempo fino alla disconnessione automatica",
"Change": "Cambiamento"
"Change": "Cambiamento",
"MaxValueNotification": "{{nome}} deve essere massimo {{max}}"
},
"credential": {
"Permission": "Autorizzazione",
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@
"NSelected": "選択された{{count}}項目(複数可)",
"Extend": "伸ばす",
"RemainingLoginSessionTime": "自動ログアウトまでの時間",
"Change": "変更"
"Change": "変更",
"MaxValueNotification": "{{ name }}最大値は{{ max }}です"
},
"credential": {
"Permission": "許可",
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,8 @@
"NSelected": "{{count}}개 선택됨",
"Extend": "연장",
"RemainingLoginSessionTime": "자동 로그아웃까지 남은 시간",
"Change": "변경"
"Change": "변경",
"MaxValueNotification": "{{ name }} 최대 값은 {{ max }}입니다"
},
"credential": {
"Permission": "권한",
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/mn.json
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,8 @@
"NSelected": "Сонгосон {{count}} зүйл(үүд)",
"Extend": "Сунгах",
"RemainingLoginSessionTime": "Автоматаар гарах хүртэл хугацаа",
"Change": "Өөрчлөх"
"Change": "Өөрчлөх",
"MaxValueNotification": "{{name}} хамгийн ихдээ {{max}} байх ёстой"
},
"credential": {
"Permission": "Зөвшөөрөл",
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/ms.json
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,8 @@
"Disabled": "Dilumpuhkan",
"NSelected": "{{count}} item yang dipilih",
"Extend": "Panjangkan",
"Change": "Berubah"
"Change": "Berubah",
"MaxValueNotification": "{{nama}} mestilah maksimum {{maks}}"
},
"credential": {
"Permission": "Kebenaran",
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@
"NSelected": "Wybrane elementy {{count}}",
"Extend": "Rozszerzyć",
"RemainingLoginSessionTime": "Czas do automatycznego wylogowania",
"Change": "Zmiana"
"Change": "Zmiana",
"MaxValueNotification": "{{name}} musi być maksymalna {{max}}."
},
"credential": {
"Permission": "Pozwolenie",
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@
"NSelected": "Item(ns) {{contagem}} selecionado(s)",
"Extend": "Ampliar",
"RemainingLoginSessionTime": "Tempo até ao encerramento automático da sessão",
"Change": "Alterar"
"Change": "Alterar",
"MaxValueNotification": "{{nome}} deve ser o máximo {{max}}"
},
"credential": {
"Permission": "Permissão",
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@
"NSelected": "Item(ns) {{contagem}} selecionado(s)",
"Extend": "Ampliar",
"RemainingLoginSessionTime": "Tempo até ao encerramento automático da sessão",
"Change": "Alterar"
"Change": "Alterar",
"MaxValueNotification": "{{nome}} deve ser o máximo {{max}}"
},
"credential": {
"Permission": "Permissão",
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@
"NSelected": "Выбранный {{count}} элемент(ы)",
"Extend": "Продлевать",
"RemainingLoginSessionTime": "Время до автоматического выхода из системы",
"Change": "Изменить"
"Change": "Изменить",
"MaxValueNotification": "{{name}} должен быть максимальным {{max}}"
},
"credential": {
"Permission": "Разрешение",
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/th.json
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,8 @@
"Disabled": "ปิดใช้งาน",
"Extend": "ขยาย",
"RemainingLoginSessionTime": "เวลาจนกระทั่งออกจากระบบอัตโนมัติ",
"Change": "เปลี่ยน"
"Change": "เปลี่ยน",
"MaxValueNotification": "{{name}} ต้องมีค่าสูงสุด {{max}}"
},
"credential": {
"Permission": "สิทธิ์",
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/tr.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@
"NSelected": "Seçilen {{count}} öğe(ler)",
"Extend": "Uzatmak",
"RemainingLoginSessionTime": "Otomatik Çıkışa Kadar Geçen Süre",
"Change": "Değişim"
"Change": "Değişim",
"MaxValueNotification": "{{name}} maksimum {{max}} olmalıdır"
},
"credential": {
"Permission": "izin",
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/vi.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@
"NSelected": "Đã chọn {{count}} mục",
"Extend": "Mở rộng",
"RemainingLoginSessionTime": "Thời gian cho đến khi tự động đăng xuất",
"Change": "Thay đổi"
"Change": "Thay đổi",
"MaxValueNotification": "{{name}} phải tối đa {{max}}"
},
"credential": {
"Permission": "Sự cho phép",
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@
"NSelected": "已选择的 {{count}} 项目",
"Extend": "延长",
"RemainingLoginSessionTime": "自动注销前的时间",
"Change": "改变"
"Change": "改变",
"MaxValueNotification": "{{name}} 必须是最大值 {{max}}"
},
"credential": {
"Permission": "允许",
Expand Down
3 changes: 2 additions & 1 deletion resources/i18n/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,8 @@
"NSelected": "已选择的 {{count}} 项目",
"Extend": "延長",
"RemainingLoginSessionTime": "自动注销前的时间",
"Change": "改变"
"Change": "改变",
"MaxValueNotification": "{{name}} 必须是最大值 {{max}}"
},
"credential": {
"Permission": "允許",
Expand Down

0 comments on commit d933aec

Please sign in to comment.