From 2cb2e9860a3d9c8cc9ffcc5b7ca47381ca14b1d2 Mon Sep 17 00:00:00 2001 From: agatha197 Date: Thu, 22 Aug 2024 15:38:00 +0900 Subject: [PATCH] refactor: resource preset page --- .../src/components/ContainerRegistryList.tsx | 6 +- .../components/KeypairResourcePolicyList.tsx | 2 + react/src/components/ResourcePresetList.tsx | 239 ++++++++++++++ .../components/ResourcePresetSettingModal.tsx | 298 ++++++++++++++++++ react/src/pages/EnvironmentPage.tsx | 55 +--- 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 +- 26 files changed, 602 insertions(+), 61 deletions(-) create mode 100644 react/src/components/ResourcePresetList.tsx create mode 100644 react/src/components/ResourcePresetSettingModal.tsx diff --git a/react/src/components/ContainerRegistryList.tsx b/react/src/components/ContainerRegistryList.tsx index d54f66b387..e5d0b285bb 100644 --- a/react/src/components/ContainerRegistryList.tsx +++ b/react/src/components/ContainerRegistryList.tsx @@ -246,7 +246,11 @@ const ContainerRegistryList: React.FC<{ direction="row" justify="end" gap={'sm'} - style={{ padding: token.paddingSM }} + style={{ + padding: token.paddingContentVertical, + paddingLeft: token.paddingContentHorizontalSM, + paddingRight: token.paddingContentHorizontalSM, + }} > + + + localeCompare(a.name, b.name), + }, + { + title: t('resourcePreset.Resources'), + dataIndex: 'resource_slots', + render: (text) => ( + + {!_.isEmpty(text) + ? _.map(JSON.parse(text), (value, key) => ( + + )) + : '-'} + + ), + }, + { + title: t('resourcePreset.SharedMemory'), + dataIndex: 'shared_memory', + render: (text) => + text ? iSizeToSize(text + '', 'g')?.number : '-', + sorter: (a, b) => a.shared_memory - b.shared_memory, + }, + { + title: t('general.Control'), + key: 'control', + fixed: 'right', + render: (text, record) => ( + + + + + // @ts-ignore + iSizeToSize('300p', 'p').number + ) { + return Promise.reject( + new Error( + 'Memory size should be less than 300 PiB', + ), + ); + } + return Promise.resolve(); + }, + }, + ]} + > + {_.includes(resourceSlotKey, 'mem') ? ( + + ) : ( + + )} + + + ))} + + ), + )} + + ({ + validator(__, value) { + if ( + value && + getFieldValue('resource_slots')?.mem && + (iSizeToSize(getFieldValue('resource_slots')?.mem, 'b') + ?.number ?? 0) < + (iSizeToSize(value, 'b')?.number ?? 0) + ) { + return Promise.reject( + t('resourcePreset.MemoryShouldBeLargerThanSHMEM'), + ); + } + return Promise.resolve(); + }, + }), + ]} + > + + + + + + + + ); +}; + +export default ResourcePresetSettingModal; diff --git a/react/src/pages/EnvironmentPage.tsx b/react/src/pages/EnvironmentPage.tsx index f2bcc9db29..ef40098185 100644 --- a/react/src/pages/EnvironmentPage.tsx +++ b/react/src/pages/EnvironmentPage.tsx @@ -1,7 +1,7 @@ import ContainerRegistryList from '../components/ContainerRegistryList'; -import Flex from '../components/Flex'; +import FlexActivityIndicator from '../components/FlexActivityIndicator'; +import ResourcePresetList from '../components/ResourcePresetList'; import { useSuspendedBackendaiClient } from '../hooks'; -import { theme } from 'antd'; import Card from 'antd/es/card/Card'; import { Suspense } from 'react'; import { useTranslation } from 'react-i18next'; @@ -16,7 +16,6 @@ const EnvironmentPage = () => { const isSupportContainerRegistryGraphQL = baiClient.supports( 'container-registry-gql', ); - const { token } = theme.useToken(); return ( { }, }} > - - {/* @ts-ignore */} - - - - {/* @ts-ignore */} - - - - - {isSupportContainerRegistryGraphQL ? ( - curTabKey === 'registry' ? ( - - - - ) : null - ) : ( + }> + {curTabKey === 'image' ? ( // @ts-ignore - - )} - + + ) : null} + {curTabKey === 'preset' && } + {curTabKey === 'registry' ? ( + isSupportContainerRegistryGraphQL ? ( + + ) : ( + // @ts-ignore + + ) + ) : null} + ); }; diff --git a/resources/i18n/de.json b/resources/i18n/de.json index 38981cb8f4..93681412ec 100644 --- a/resources/i18n/de.json +++ b/resources/i18n/de.json @@ -871,7 +871,8 @@ "SharedMemory": "Gemeinsamer Speicher (GB)", "NoResourcePresetToDisplay": "Keine Ressourcenvoreinstellungen anzeigen", "Deleted": "Die Ressourcenvoreinstellung wurde erfolgreich gelöscht.", - "SHMEMShouldBeSmallerThanMemory": "Gemeinsamer Speicher muss kleiner sein als der Speicher" + "SHMEMShouldBeSmallerThanMemory": "Gemeinsamer Speicher muss kleiner sein als der Speicher", + "DeleteResourcePreset": "Ressourcenvoreinstellung löschen" }, "usersettings": { "General": "Allgemeines", diff --git a/resources/i18n/el.json b/resources/i18n/el.json index 8566415cf4..db2b4fbc4e 100644 --- a/resources/i18n/el.json +++ b/resources/i18n/el.json @@ -871,7 +871,8 @@ "SharedMemory": "Κοινή μνήμη (GB)", "NoResourcePresetToDisplay": "Δεν εμφανίζονται Προεπιλογές πόρων", "Deleted": "Η προεπιλογή πόρων διαγράφηκε επιτυχώς.", - "SHMEMShouldBeSmallerThanMemory": "Η κοινόχρηστη μνήμη πρέπει να είναι μικρότερη από τη μνήμη" + "SHMEMShouldBeSmallerThanMemory": "Η κοινόχρηστη μνήμη πρέπει να είναι μικρότερη από τη μνήμη", + "DeleteResourcePreset": "Διαγραφή προκαθορισμένων πόρων" }, "usersettings": { "General": "Γενικός", diff --git a/resources/i18n/en.json b/resources/i18n/en.json index 63f24f330a..251d06074e 100644 --- a/resources/i18n/en.json +++ b/resources/i18n/en.json @@ -996,7 +996,8 @@ "MinimumShmemUnit": "The minimum unit for shared memory is 0.01 GB.", "RAM": "RAM (GB)", "SharedMemory": "Shared memory (GB)", - "SHMEMShouldBeSmallerThanMemory": "Shared memory must be smaller than memory" + "SHMEMShouldBeSmallerThanMemory": "Shared memory must be smaller than memory", + "DeleteResourcePreset": "Delete resource preset" }, "usersettings": { "General": "General", diff --git a/resources/i18n/es.json b/resources/i18n/es.json index 91459d886a..e068d754f1 100644 --- a/resources/i18n/es.json +++ b/resources/i18n/es.json @@ -978,7 +978,8 @@ "Resources": "Recursos", "SharedMemory": "Memoria compartida (GB)", "Updated": "Preajuste de recursos actualizado", - "SHMEMShouldBeSmallerThanMemory": "La memoria compartida debe ser menor que la memoria" + "SHMEMShouldBeSmallerThanMemory": "La memoria compartida debe ser menor que la memoria", + "DeleteResourcePreset": "Eliminar recurso preestablecido" }, "session": { "Agent": "Agente", diff --git a/resources/i18n/fi.json b/resources/i18n/fi.json index 2c6989cafe..520db5acf0 100644 --- a/resources/i18n/fi.json +++ b/resources/i18n/fi.json @@ -975,7 +975,8 @@ "Resources": "Resurssit", "SharedMemory": "Jaettu muisti (GB)", "Updated": "Resurssien esiasetus päivitetty", - "SHMEMShouldBeSmallerThanMemory": "Jaetun muistin on oltava pienempi kuin muistin" + "SHMEMShouldBeSmallerThanMemory": "Jaetun muistin on oltava pienempi kuin muistin", + "DeleteResourcePreset": "Poista resurssin esiasetus" }, "session": { "Agent": "Agentti", diff --git a/resources/i18n/fr.json b/resources/i18n/fr.json index 99438d0a2c..b13480fe74 100644 --- a/resources/i18n/fr.json +++ b/resources/i18n/fr.json @@ -871,7 +871,8 @@ "SharedMemory": "Mémoire partagée (Go)", "Deleted": "Le préréglage des ressources a été supprimé avec succès.", "NoResourcePresetToDisplay": "Pas de préréglages de ressources à afficher", - "SHMEMShouldBeSmallerThanMemory": "La mémoire partagée doit être plus petite que la mémoire" + "SHMEMShouldBeSmallerThanMemory": "La mémoire partagée doit être plus petite que la mémoire", + "DeleteResourcePreset": "Supprimer le préréglage de ressources" }, "usersettings": { "General": "Général", diff --git a/resources/i18n/id.json b/resources/i18n/id.json index 2fc0d8f12d..e51c910fbf 100644 --- a/resources/i18n/id.json +++ b/resources/i18n/id.json @@ -872,7 +872,8 @@ "SharedMemory": "Memori bersama (GB)", "Deleted": "Preset sumber daya berhasil dihapus.", "NoResourcePresetToDisplay": "Tidak ada Preset Sumber Daya yang akan ditampilkan", - "SHMEMShouldBeSmallerThanMemory": "Memori bersama harus lebih kecil dari memori" + "SHMEMShouldBeSmallerThanMemory": "Memori bersama harus lebih kecil dari memori", + "DeleteResourcePreset": "Hapus preset sumber daya" }, "usersettings": { "General": "Umum", diff --git a/resources/i18n/it.json b/resources/i18n/it.json index bbfed05eb0..296d7cf27f 100644 --- a/resources/i18n/it.json +++ b/resources/i18n/it.json @@ -872,7 +872,8 @@ "SharedMemory": "Memoria condivisa (GB)", "NoResourcePresetToDisplay": "Nessuna preimpostazione di risorse da visualizzare", "Deleted": "La preimpostazione della risorsa è stata eliminata con successo.", - "SHMEMShouldBeSmallerThanMemory": "La memoria condivisa deve essere più piccola della memoria" + "SHMEMShouldBeSmallerThanMemory": "La memoria condivisa deve essere più piccola della memoria", + "DeleteResourcePreset": "Elimina la preimpostazione della risorsa" }, "usersettings": { "General": "Generale", diff --git a/resources/i18n/ja.json b/resources/i18n/ja.json index 3169ee47d9..076fb73cb9 100644 --- a/resources/i18n/ja.json +++ b/resources/i18n/ja.json @@ -871,7 +871,8 @@ "SharedMemory": "共有メモリ(GB)", "NoResourcePresetToDisplay": "リソースプリセット情報がありません。", "Deleted": "リソースプリセットの削除に成功しました", - "SHMEMShouldBeSmallerThanMemory": "共有メモリはメモリより小さくなければならない" + "SHMEMShouldBeSmallerThanMemory": "共有メモリはメモリより小さくなければならない", + "DeleteResourcePreset": "リソースプリセットの削除" }, "usersettings": { "General": "一般", diff --git a/resources/i18n/ko.json b/resources/i18n/ko.json index 890c4fdc0e..01b89bb3dc 100644 --- a/resources/i18n/ko.json +++ b/resources/i18n/ko.json @@ -983,7 +983,8 @@ "MinimumShmemUnit": "공유메모리 최소 단위는 0.01 GB 입니다.", "RAM": "메모리 (GB)", "SharedMemory": "공유메모리 (GB)", - "Deleted": "자원 프리셋을 성공적으로 삭제하였습니다" + "Deleted": "자원 프리셋을 성공적으로 삭제하였습니다", + "DeleteResourcePreset": "자원 프리셋 삭제" }, "usersettings": { "General": "일반", diff --git a/resources/i18n/mn.json b/resources/i18n/mn.json index 12dadba00b..d88f168f6e 100644 --- a/resources/i18n/mn.json +++ b/resources/i18n/mn.json @@ -873,7 +873,8 @@ "SharedMemory": "Хуваалцсан санах ой (GB)", "Deleted": "Нөөцийн урьдчилсан тохируулгыг амжилттай устгалаа.", "NoResourcePresetToDisplay": "Харуулах нөөцийн урьдчилсан тохиргоо байхгүй", - "SHMEMShouldBeSmallerThanMemory": "Хуваалцсан санах ой санах ойноос бага байх ёстой" + "SHMEMShouldBeSmallerThanMemory": "Хуваалцсан санах ой санах ойноос бага байх ёстой", + "DeleteResourcePreset": "Урьдчилсан нөөцийг устгах" }, "usersettings": { "General": "Ерөнхий", diff --git a/resources/i18n/ms.json b/resources/i18n/ms.json index 2b6d7a0773..6b69c15b2f 100644 --- a/resources/i18n/ms.json +++ b/resources/i18n/ms.json @@ -871,7 +871,8 @@ "SharedMemory": "Memori bersama (GB)", "NoResourcePresetToDisplay": "Tiada Pratetap Sumber untuk dipaparkan", "Deleted": "Pratetap sumber berjaya dipadamkan.", - "SHMEMShouldBeSmallerThanMemory": "Memori yang dikongsi mestilah lebih kecil daripada memori" + "SHMEMShouldBeSmallerThanMemory": "Memori yang dikongsi mestilah lebih kecil daripada memori", + "DeleteResourcePreset": "Padamkan pratetap sumber" }, "usersettings": { "General": "Am", diff --git a/resources/i18n/pl.json b/resources/i18n/pl.json index 6e3d2971c0..3bf7a7d2fa 100644 --- a/resources/i18n/pl.json +++ b/resources/i18n/pl.json @@ -871,7 +871,8 @@ "SharedMemory": "Pamięć współdzielona (GB)", "NoResourcePresetToDisplay": "Brak ustawień wstępnych zasobów do wyświetlenia", "Deleted": "Ustawienie wstępne zasobu zostało pomyślnie usunięte.", - "SHMEMShouldBeSmallerThanMemory": "Pamięć współdzielona musi być mniejsza niż pamięć" + "SHMEMShouldBeSmallerThanMemory": "Pamięć współdzielona musi być mniejsza niż pamięć", + "DeleteResourcePreset": "Usuń ustawienie wstępne zasobu" }, "usersettings": { "General": "Generał", diff --git a/resources/i18n/pt-BR.json b/resources/i18n/pt-BR.json index 850bbd1a52..c4ef54c772 100644 --- a/resources/i18n/pt-BR.json +++ b/resources/i18n/pt-BR.json @@ -871,7 +871,8 @@ "SharedMemory": "Memória compartilhada (GB)", "NoResourcePresetToDisplay": "Não há predefinições de recursos a apresentar", "Deleted": "A predefinição de recurso foi eliminada com êxito.", - "SHMEMShouldBeSmallerThanMemory": "A memória partilhada deve ser mais pequena do que a memória" + "SHMEMShouldBeSmallerThanMemory": "A memória partilhada deve ser mais pequena do que a memória", + "DeleteResourcePreset": "Excluir predefinição de recurso" }, "usersettings": { "General": "Em geral", diff --git a/resources/i18n/pt.json b/resources/i18n/pt.json index 8d7cdc83ee..b394ba81c4 100644 --- a/resources/i18n/pt.json +++ b/resources/i18n/pt.json @@ -871,7 +871,8 @@ "SharedMemory": "Memória compartilhada (GB)", "NoResourcePresetToDisplay": "Não há predefinições de recursos a apresentar", "Deleted": "A predefinição de recurso foi eliminada com êxito.", - "SHMEMShouldBeSmallerThanMemory": "A memória partilhada deve ser mais pequena do que a memória" + "SHMEMShouldBeSmallerThanMemory": "A memória partilhada deve ser mais pequena do que a memória", + "DeleteResourcePreset": "Excluir predefinição de recurso" }, "usersettings": { "General": "Em geral", diff --git a/resources/i18n/ru.json b/resources/i18n/ru.json index 146de7cfe2..b831c4ce58 100644 --- a/resources/i18n/ru.json +++ b/resources/i18n/ru.json @@ -871,7 +871,8 @@ "SharedMemory": "Общая память (ГБ)", "Deleted": "Предварительная настройка ресурса успешно удалена.", "NoResourcePresetToDisplay": "Отсутствие отображения предустановок ресурсов", - "SHMEMShouldBeSmallerThanMemory": "Общая память должна быть меньше памяти" + "SHMEMShouldBeSmallerThanMemory": "Общая память должна быть меньше памяти", + "DeleteResourcePreset": "Удалить набор ресурсов" }, "usersettings": { "General": "Общий", diff --git a/resources/i18n/th.json b/resources/i18n/th.json index cff23542dd..4adea5bf1f 100644 --- a/resources/i18n/th.json +++ b/resources/i18n/th.json @@ -996,7 +996,8 @@ "MinimumShmemUnit": "หน่วยต่ำสุดสำหรับหน่วยความจำร่วมคือ 0.01 GB", "RAM": "RAM (GB)", "SharedMemory": "หน่วยความจำร่วม (GB)", - "SHMEMShouldBeSmallerThanMemory": "หน่วยความจำร่วมต้องน้อยกว่าหน่วยความจำ" + "SHMEMShouldBeSmallerThanMemory": "หน่วยความจำร่วมต้องน้อยกว่าหน่วยความจำ", + "DeleteResourcePreset": "ลบการตั้งค่าทรัพยากรล่วงหน้า" }, "usersettings": { "General": "ทั่วไป", diff --git a/resources/i18n/tr.json b/resources/i18n/tr.json index 2b5aa23a39..35eb9cc2cc 100644 --- a/resources/i18n/tr.json +++ b/resources/i18n/tr.json @@ -871,7 +871,8 @@ "SharedMemory": "Paylaşılan bellek (GB)", "NoResourcePresetToDisplay": "Görüntülenecek Kaynak Ön Ayarı yok", "Deleted": "Kaynak ön ayarı başarıyla silindi.", - "SHMEMShouldBeSmallerThanMemory": "Paylaşılan bellek, bellekten daha küçük olmalıdır" + "SHMEMShouldBeSmallerThanMemory": "Paylaşılan bellek, bellekten daha küçük olmalıdır", + "DeleteResourcePreset": "Kaynak ön ayarını sil" }, "usersettings": { "General": "Genel", diff --git a/resources/i18n/vi.json b/resources/i18n/vi.json index 70dc9a2e35..da2f410971 100644 --- a/resources/i18n/vi.json +++ b/resources/i18n/vi.json @@ -871,7 +871,8 @@ "SharedMemory": "Bộ nhớ dùng chung (GB)", "NoResourcePresetToDisplay": "Không có cài đặt trước tài nguyên nào để hiển thị", "Deleted": "Cài đặt trước tài nguyên đã được xóa thành công.", - "SHMEMShouldBeSmallerThanMemory": "Bộ nhớ dùng chung phải nhỏ hơn bộ nhớ" + "SHMEMShouldBeSmallerThanMemory": "Bộ nhớ dùng chung phải nhỏ hơn bộ nhớ", + "DeleteResourcePreset": "Xóa cài đặt trước tài nguyên" }, "usersettings": { "General": "Chung", diff --git a/resources/i18n/zh-CN.json b/resources/i18n/zh-CN.json index 93e0ec0591..6f1eac9348 100644 --- a/resources/i18n/zh-CN.json +++ b/resources/i18n/zh-CN.json @@ -871,7 +871,8 @@ "SharedMemory": "共享内存 (GB)", "NoResourcePresetToDisplay": "无资源预置显示", "Deleted": "资源预置已成功删除。", - "SHMEMShouldBeSmallerThanMemory": "共享内存必须小于内存" + "SHMEMShouldBeSmallerThanMemory": "共享内存必须小于内存", + "DeleteResourcePreset": "删除资源预设" }, "usersettings": { "General": "一般的", diff --git a/resources/i18n/zh-TW.json b/resources/i18n/zh-TW.json index 7d902c94eb..c3dc6a228e 100644 --- a/resources/i18n/zh-TW.json +++ b/resources/i18n/zh-TW.json @@ -870,7 +870,8 @@ "SharedMemory": "共享內存 (GB)", "NoResourcePresetToDisplay": "无资源预置显示", "Deleted": "资源预置已成功删除。", - "SHMEMShouldBeSmallerThanMemory": "共享内存必须小于内存" + "SHMEMShouldBeSmallerThanMemory": "共享内存必须小于内存", + "DeleteResourcePreset": "刪除資源預設" }, "usersettings": { "General": "一般的",