From d933aec29c1d74858741934b59760f8c63a5216d Mon Sep 17 00:00:00 2001 From: Jong Eun Lee Date: Thu, 5 Sep 2024 12:26:53 +0800 Subject: [PATCH] feat: add max validation rule for CPU and memory in Form.Item. --- .../ResourceAllocationFormItems.tsx | 33 +++++++++++++++++++ resources/i18n/de.json | 3 +- resources/i18n/el.json | 3 +- resources/i18n/en.json | 3 +- resources/i18n/es.json | 3 +- resources/i18n/fi.json | 3 +- resources/i18n/fr.json | 3 +- resources/i18n/id.json | 3 +- resources/i18n/it.json | 3 +- resources/i18n/ja.json | 3 +- resources/i18n/ko.json | 3 +- resources/i18n/mn.json | 3 +- resources/i18n/ms.json | 3 +- resources/i18n/pl.json | 3 +- resources/i18n/pt-BR.json | 3 +- resources/i18n/pt.json | 3 +- resources/i18n/ru.json | 3 +- resources/i18n/th.json | 3 +- resources/i18n/tr.json | 3 +- resources/i18n/vi.json | 3 +- resources/i18n/zh-CN.json | 3 +- resources/i18n/zh-TW.json | 3 +- 22 files changed, 75 insertions(+), 21 deletions(-) diff --git a/react/src/components/ResourceAllocationFormItems.tsx b/react/src/components/ResourceAllocationFormItems.tsx index 3b68bbbf11..473fb800a5 100644 --- a/react/src/components/ResourceAllocationFormItems.tsx +++ b/react/src/components/ResourceAllocationFormItems.tsx @@ -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) => { @@ -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) => { diff --git a/resources/i18n/de.json b/resources/i18n/de.json index 6f469208a5..6acc79689d 100644 --- a/resources/i18n/de.json +++ b/resources/i18n/de.json @@ -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", diff --git a/resources/i18n/el.json b/resources/i18n/el.json index 6ab2879a32..c98adf84a4 100644 --- a/resources/i18n/el.json +++ b/resources/i18n/el.json @@ -511,7 +511,8 @@ "NSelected": "Επιλεγμένο {{count}} στοιχείο(α)", "Extend": "Επεκτείνω", "RemainingLoginSessionTime": "Χρόνος μέχρι την αυτόματη αποσύνδεση", - "Change": "Αλλαγή" + "Change": "Αλλαγή", + "MaxValueNotification": "{{name}} πρέπει να είναι το μέγιστο {{max}}" }, "credential": { "Permission": "Αδεια", diff --git a/resources/i18n/en.json b/resources/i18n/en.json index a5298a4062..cb189d6a95 100644 --- a/resources/i18n/en.json +++ b/resources/i18n/en.json @@ -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", diff --git a/resources/i18n/es.json b/resources/i18n/es.json index a9d734efc4..d13a6a48a5 100644 --- a/resources/i18n/es.json +++ b/resources/i18n/es.json @@ -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...", diff --git a/resources/i18n/fi.json b/resources/i18n/fi.json index dc0cd9c889..a42ecb842a 100644 --- a/resources/i18n/fi.json +++ b/resources/i18n/fi.json @@ -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...", diff --git a/resources/i18n/fr.json b/resources/i18n/fr.json index fe11c3c068..6d9fe294f3 100644 --- a/resources/i18n/fr.json +++ b/resources/i18n/fr.json @@ -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", diff --git a/resources/i18n/id.json b/resources/i18n/id.json index cfaac8d229..7169e1718c 100644 --- a/resources/i18n/id.json +++ b/resources/i18n/id.json @@ -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", diff --git a/resources/i18n/it.json b/resources/i18n/it.json index f69744dd8e..dcc4a4df8f 100644 --- a/resources/i18n/it.json +++ b/resources/i18n/it.json @@ -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", diff --git a/resources/i18n/ja.json b/resources/i18n/ja.json index 60dd7e0d16..369b9985f6 100644 --- a/resources/i18n/ja.json +++ b/resources/i18n/ja.json @@ -511,7 +511,8 @@ "NSelected": "選択された{{count}}項目(複数可)", "Extend": "伸ばす", "RemainingLoginSessionTime": "自動ログアウトまでの時間", - "Change": "変更" + "Change": "変更", + "MaxValueNotification": "{{ name }}最大値は{{ max }}です" }, "credential": { "Permission": "許可", diff --git a/resources/i18n/ko.json b/resources/i18n/ko.json index 81238bf883..d467f0e9ad 100644 --- a/resources/i18n/ko.json +++ b/resources/i18n/ko.json @@ -623,7 +623,8 @@ "NSelected": "{{count}}개 선택됨", "Extend": "연장", "RemainingLoginSessionTime": "자동 로그아웃까지 남은 시간", - "Change": "변경" + "Change": "변경", + "MaxValueNotification": "{{ name }} 최대 값은 {{ max }}입니다" }, "credential": { "Permission": "권한", diff --git a/resources/i18n/mn.json b/resources/i18n/mn.json index a2b830ebe4..3775af198b 100644 --- a/resources/i18n/mn.json +++ b/resources/i18n/mn.json @@ -513,7 +513,8 @@ "NSelected": "Сонгосон {{count}} зүйл(үүд)", "Extend": "Сунгах", "RemainingLoginSessionTime": "Автоматаар гарах хүртэл хугацаа", - "Change": "Өөрчлөх" + "Change": "Өөрчлөх", + "MaxValueNotification": "{{name}} хамгийн ихдээ {{max}} байх ёстой" }, "credential": { "Permission": "Зөвшөөрөл", diff --git a/resources/i18n/ms.json b/resources/i18n/ms.json index a9f1f024ff..e27df90b93 100644 --- a/resources/i18n/ms.json +++ b/resources/i18n/ms.json @@ -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", diff --git a/resources/i18n/pl.json b/resources/i18n/pl.json index 4004c065d9..09166eeb90 100644 --- a/resources/i18n/pl.json +++ b/resources/i18n/pl.json @@ -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", diff --git a/resources/i18n/pt-BR.json b/resources/i18n/pt-BR.json index e74290a6cd..7663ab2660 100644 --- a/resources/i18n/pt-BR.json +++ b/resources/i18n/pt-BR.json @@ -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", diff --git a/resources/i18n/pt.json b/resources/i18n/pt.json index afa8f2b069..72c90f3a23 100644 --- a/resources/i18n/pt.json +++ b/resources/i18n/pt.json @@ -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", diff --git a/resources/i18n/ru.json b/resources/i18n/ru.json index cc73da7a6c..f6a620fcce 100644 --- a/resources/i18n/ru.json +++ b/resources/i18n/ru.json @@ -511,7 +511,8 @@ "NSelected": "Выбранный {{count}} элемент(ы)", "Extend": "Продлевать", "RemainingLoginSessionTime": "Время до автоматического выхода из системы", - "Change": "Изменить" + "Change": "Изменить", + "MaxValueNotification": "{{name}} должен быть максимальным {{max}}" }, "credential": { "Permission": "Разрешение", diff --git a/resources/i18n/th.json b/resources/i18n/th.json index e516ad3add..0ce9a15d7b 100644 --- a/resources/i18n/th.json +++ b/resources/i18n/th.json @@ -634,7 +634,8 @@ "Disabled": "ปิดใช้งาน", "Extend": "ขยาย", "RemainingLoginSessionTime": "เวลาจนกระทั่งออกจากระบบอัตโนมัติ", - "Change": "เปลี่ยน" + "Change": "เปลี่ยน", + "MaxValueNotification": "{{name}} ต้องมีค่าสูงสุด {{max}}" }, "credential": { "Permission": "สิทธิ์", diff --git a/resources/i18n/tr.json b/resources/i18n/tr.json index bcc7e7cb42..c53ed222f1 100644 --- a/resources/i18n/tr.json +++ b/resources/i18n/tr.json @@ -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", diff --git a/resources/i18n/vi.json b/resources/i18n/vi.json index ca33a543e2..44834fee69 100644 --- a/resources/i18n/vi.json +++ b/resources/i18n/vi.json @@ -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", diff --git a/resources/i18n/zh-CN.json b/resources/i18n/zh-CN.json index 7fb1100b5f..cd5c2f71d7 100644 --- a/resources/i18n/zh-CN.json +++ b/resources/i18n/zh-CN.json @@ -511,7 +511,8 @@ "NSelected": "已选择的 {{count}} 项目", "Extend": "延长", "RemainingLoginSessionTime": "自动注销前的时间", - "Change": "改变" + "Change": "改变", + "MaxValueNotification": "{{name}} 必须是最大值 {{max}}" }, "credential": { "Permission": "允许", diff --git a/resources/i18n/zh-TW.json b/resources/i18n/zh-TW.json index 7935c09a8f..e67239f469 100644 --- a/resources/i18n/zh-TW.json +++ b/resources/i18n/zh-TW.json @@ -511,7 +511,8 @@ "NSelected": "已选择的 {{count}} 项目", "Extend": "延長", "RemainingLoginSessionTime": "自动注销前的时间", - "Change": "改变" + "Change": "改变", + "MaxValueNotification": "{{name}} 必须是最大值 {{max}}" }, "credential": { "Permission": "允許",