From 4a0b7c22e837c121e3081564be9842cec216bd9e Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Sat, 18 Nov 2023 08:11:52 +0100 Subject: [PATCH] feat: make canister stop start generic Signed-off-by: David Dal Busco --- .../CanisterStart.svelte} | 33 ++++++++++++----- .../CanisterStop.svelte} | 36 +++++++++++++------ .../canister/CanisterStopStart.svelte | 28 +++++++++++++++ .../modals/CanisterDeleteModal.svelte | 2 +- .../satellites/SatelliteActions.svelte | 4 +-- .../satellites/SatelliteStopStart.svelte | 28 --------------- .../src/lib/components/ui/Text.svelte | 15 ++++++++ src/frontend/src/lib/i18n/en.json | 24 ++++++------- src/frontend/src/lib/i18n/it.json | 24 ++++++------- src/frontend/src/lib/i18n/zh-cn.json | 24 ++++++------- src/frontend/src/lib/types/i18n.d.ts | 22 ++++++------ src/frontend/src/lib/utils/i18n.utils.ts | 13 +++++-- 12 files changed, 154 insertions(+), 99 deletions(-) rename src/frontend/src/lib/components/{satellites/SatelliteStart.svelte => canister/CanisterStart.svelte} (56%) rename src/frontend/src/lib/components/{satellites/SatelliteStop.svelte => canister/CanisterStop.svelte} (52%) create mode 100644 src/frontend/src/lib/components/canister/CanisterStopStart.svelte delete mode 100644 src/frontend/src/lib/components/satellites/SatelliteStopStart.svelte create mode 100644 src/frontend/src/lib/components/ui/Text.svelte diff --git a/src/frontend/src/lib/components/satellites/SatelliteStart.svelte b/src/frontend/src/lib/components/canister/CanisterStart.svelte similarity index 56% rename from src/frontend/src/lib/components/satellites/SatelliteStart.svelte rename to src/frontend/src/lib/components/canister/CanisterStart.svelte index d7089d98c..c5f766179 100644 --- a/src/frontend/src/lib/components/satellites/SatelliteStart.svelte +++ b/src/frontend/src/lib/components/canister/CanisterStart.svelte @@ -1,7 +1,6 @@ + +{#if nonNullish(canister) && status === 'stopped' && sync === 'synced'} +
+{:else if nonNullish(canister) && status === 'running' && sync === 'synced'} +
+{/if} + + diff --git a/src/frontend/src/lib/components/modals/CanisterDeleteModal.svelte b/src/frontend/src/lib/components/modals/CanisterDeleteModal.svelte index a5aef3f5b..8ccba139f 100644 --- a/src/frontend/src/lib/components/modals/CanisterDeleteModal.svelte +++ b/src/frontend/src/lib/components/modals/CanisterDeleteModal.svelte @@ -94,7 +94,7 @@ steps = 'error'; toasts.error({ - text: $i18n.errors.satellite_delete, + text: $i18n.errors.canister_delete, detail: err }); } diff --git a/src/frontend/src/lib/components/satellites/SatelliteActions.svelte b/src/frontend/src/lib/components/satellites/SatelliteActions.svelte index 1b18e3bfe..34dd1ac54 100644 --- a/src/frontend/src/lib/components/satellites/SatelliteActions.svelte +++ b/src/frontend/src/lib/components/satellites/SatelliteActions.svelte @@ -1,7 +1,7 @@ - -{#if status === 'stopped' && sync === 'synced'} -
-{:else if status === 'running' && sync === 'synced'} -
-{/if} - - diff --git a/src/frontend/src/lib/components/ui/Text.svelte b/src/frontend/src/lib/components/ui/Text.svelte new file mode 100644 index 000000000..1ca5f5fca --- /dev/null +++ b/src/frontend/src/lib/components/ui/Text.svelte @@ -0,0 +1,15 @@ + + +{@html i18nFormat(i18nText({ i18n: $i18n, labelKey: key }), [ + { + placeholder, + value + } +])} diff --git a/src/frontend/src/lib/i18n/en.json b/src/frontend/src/lib/i18n/en.json index 9a059677a..329533df7 100644 --- a/src/frontend/src/lib/i18n/en.json +++ b/src/frontend/src/lib/i18n/en.json @@ -66,7 +66,15 @@ "cycles_to_retain": "T Cycles to retain", "cycles_to_transfer": "{0} T Cycles will be transferred to your mission control.", "delete_info": "Do you want to delete your {0}? This action is irreversible.", - "invalid_cycles_to_retain": "Invalid amount of cycles to retain" + "invalid_cycles_to_retain": "Invalid amount of cycles to retain", + "stop_title": "Stop {0}", + "stop_info": "Do you want to stop your {0}?", + "stop_explanation": "Please note that a stopped {0} continues to consume cycles for the memory it occupies, including any remaining outstanding responses, until the cycle balance reaches 0. After that, it will be deleted.", + "stop_error": "Additionally, be aware that stopping the {0} may result in error messages being displayed in the console.", + "stop_success": "{0} stopped.", + "start_tile": "Restart {0}", + "start_info": "Do you want to resume your {0}?", + "start_success": "{0} resumed." }, "sign_in": { "title": "Launch your first satellite", @@ -93,14 +101,6 @@ "loading_satellites": "Loading your satellites", "overview": "Overview", "id": "Satellite ID", - "stop_title": "Stop satellite", - "stop_info": "Do you want to stop your satellite?", - "stop_explanation": "Please note that a stopped satellite continues to consume cycles for the memory it occupies, including any remaining outstanding responses, until the cycle balance reaches 0. After that, it will be deleted.", - "stop_error": "Additionally, be aware that stopping the satellite may result in error messages being displayed in the console.", - "stop_success": "Satellite stopped.", - "start_tile": "Restart satellite", - "start_info": "Do you want to resume your satellite?", - "start_success": "Satellite resumed.", "delete_success": "Satellite deleted." }, "mission_control": { @@ -230,9 +230,9 @@ "satellite_no_found": "Satellite not found. Return to start to find your satellites.", "satellite_name_update": "Unexpected error(s) while trying to rename your satellite.", "satellite_missing_name": "A name must be provided.", - "satellite_stop": "Unexpected error(s) while trying to stop the satellite", - "satellite_start": "Unexpected error(s) while trying to start the satellite", - "satellite_delete": "Unexpected error(s) while trying to delete the satellite", + "canister_stop": "Unexpected error(s) while trying to stop the smart contract", + "canister_start": "Unexpected error(s) while trying to start the smart contract", + "canister_delete": "Unexpected error(s) while trying to delete the smart contract", "ledger_balance_credits": "Unexpected error(s) while getting your mission control balance and credits.", "load_credits": "Cannot load your current credits status.", "hosting_missing_domain_name": "A domain name must be provided.", diff --git a/src/frontend/src/lib/i18n/it.json b/src/frontend/src/lib/i18n/it.json index d2e2d3f09..3b85fb246 100644 --- a/src/frontend/src/lib/i18n/it.json +++ b/src/frontend/src/lib/i18n/it.json @@ -66,7 +66,15 @@ "cycles_to_retain": "T Cycles to retain", "cycles_to_transfer": "{0} T Cycles will be transferred to your mission control.", "delete_info": "Do you want to delete your {0}? This action is irreversible.", - "invalid_cycles_to_retain": "Invalid amount of cycles to retain" + "invalid_cycles_to_retain": "Invalid amount of cycles to retain", + "stop_title": "Stop {0}", + "stop_info": "Do you want to stop your {0}?", + "stop_explanation": "Please note that a stopped {0} continues to consume cycles for the memory it occupies, including any remaining outstanding responses, until the cycle balance reaches 0. After that, it will be deleted.", + "stop_error": "Additionally, be aware that stopping the {0} may result in error messages being displayed in the console.", + "stop_success": "{0} stopped.", + "start_tile": "Restart {0}", + "start_info": "Do you want to resume your {0}?", + "start_success": "{0} resumed." }, "sign_in": { "title": "Lancia il tuo primo satellite", @@ -93,14 +101,6 @@ "loading_satellites": "Caricando i tuoi satelliti", "overview": "Panoramica", "id": "Satellite ID", - "stop_title": "Stop satellite", - "stop_info": "Do you want to stop your satellite?", - "stop_explanation": "Please note that a stopped satellite continues to consume cycles for the memory it occupies, including any remaining outstanding responses, until the cycle balance reaches 0. After that, it will be deleted.", - "stop_error": "Additionally, be aware that stopping the satellite may result in error messages being displayed in the console.", - "stop_success": "Satellite stopped.", - "start_tile": "Restart satellite", - "start_info": "Do you want to resume your satellite?", - "start_success": "Satellite resumed.", "delete_success": "Satellite deleted." }, "mission_control": { @@ -230,9 +230,9 @@ "satellite_no_found": "Satellite non trovato.Torna all'inizio per trovare i tuoi satelliti.", "satellite_name_update": "Unexpected error(s) while trying to rename your satellite.", "satellite_missing_name": "A name must be provided.", - "satellite_stop": "Unexpected error(s) while trying to stop the satellite", - "satellite_start": "Unexpected error(s) while trying to start the satellite", - "satellite_delete": "Unexpected error(s) while trying to delete the satellite", + "canister_stop": "Unexpected error(s) while trying to stop the smart contract", + "canister_start": "Unexpected error(s) while trying to start the smart contract", + "canister_delete": "Unexpected error(s) while trying to delete the smart contract", "ledger_balance_credits": "Errore/i imprevisto/i durante il caricamento del saldo del tuo mission control e dei crediti.", "load_credits": "Cannot load your current credits status.", "hosting_missing_domain_name": "E' obbligatorio scegliere un nome a dominio", diff --git a/src/frontend/src/lib/i18n/zh-cn.json b/src/frontend/src/lib/i18n/zh-cn.json index 0d048e2aa..511ae9370 100644 --- a/src/frontend/src/lib/i18n/zh-cn.json +++ b/src/frontend/src/lib/i18n/zh-cn.json @@ -66,7 +66,15 @@ "cycles_to_retain": "T Cycles to retain", "cycles_to_transfer": "{0} T Cycles will be transferred to your mission control.", "delete_info": "Do you want to delete your {0}? This action is irreversible.", - "invalid_cycles_to_retain": "Invalid amount of cycles to retain" + "invalid_cycles_to_retain": "Invalid amount of cycles to retain", + "stop_title": "停止 {0}", + "stop_info": "确认要停止你的 {0}?", + "stop_explanation": "请注意,停止的{0}仍然会消耗cycles用于内存的使用,包括其他必要的响应知道cycle归零,之后它将会被删除", + "stop_error": "此外,停止的{0}可能导致控制台显示错误", + "stop_success": "{0} 已停止.", + "start_tile": "重启 {0}", + "start_info": "你想恢复你的 {0}?", + "start_success": "{0} 已恢复." }, "sign_in": { "title": "创建你的第一个satellite", @@ -93,14 +101,6 @@ "loading_satellites": "加载你的satellites", "overview": "概要", "id": "Satellite ID", - "stop_title": "停止 satellite", - "stop_info": "确认要停止你的 satellite?", - "stop_explanation": "请注意,停止的satellite仍然会消耗cycles用于内存的使用,包括其他必要的响应知道cycle归零,之后它将会被删除", - "stop_error": "此外,停止的satellate可能导致控制台显示错误", - "stop_success": "Satellite 已停止.", - "start_tile": "重启 satellite", - "start_info": "你想恢复你的 satellite?", - "start_success": "Satellite 已恢复.", "delete_success": "Satellite deleted." }, "mission_control": { @@ -230,9 +230,9 @@ "satellite_no_found": "Satellite没找到,返回 开始去找你的 satellites.", "satellite_name_update": "试图修改你的 satellite 名字出现异常.", "satellite_missing_name": "必须提供一个名字.", - "satellite_stop": "停止 satellite 中遇到异常错误", - "satellite_start": "启动 satellite 过程中遇到异常错误", - "satellite_delete": "Unexpected error(s) while trying to delete the satellite", + "canister_stop": "停止 smart contract 中遇到异常错误", + "canister_start": "启动 smart contract 过程中遇到异常错误", + "canister_delete": "Unexpected error(s) while trying to delete the smart contract", "ledger_balance_credits": "获取你的 mission control 余额和积分时出现未知错误.", "load_credits": "无法加载你当前credit状态.", "hosting_missing_domain_name": "必须提供一个域名.", diff --git a/src/frontend/src/lib/types/i18n.d.ts b/src/frontend/src/lib/types/i18n.d.ts index 30e88d415..a723a7909 100644 --- a/src/frontend/src/lib/types/i18n.d.ts +++ b/src/frontend/src/lib/types/i18n.d.ts @@ -71,6 +71,14 @@ interface I18nCanisters { cycles_to_transfer: string; delete_info: string; invalid_cycles_to_retain: string; + stop_title: string; + stop_info: string; + stop_explanation: string; + stop_error: string; + stop_success: string; + start_tile: string; + start_info: string; + start_success: string; } interface I18nSign_in { @@ -99,14 +107,6 @@ interface I18nSatellites { loading_satellites: string; overview: string; id: string; - stop_title: string; - stop_info: string; - stop_explanation: string; - stop_error: string; - stop_success: string; - start_tile: string; - start_info: string; - start_success: string; delete_success: string; } @@ -245,9 +245,9 @@ interface I18nErrors { satellite_no_found: string; satellite_name_update: string; satellite_missing_name: string; - satellite_stop: string; - satellite_start: string; - satellite_delete: string; + canister_stop: string; + canister_start: string; + canister_delete: string; ledger_balance_credits: string; load_credits: string; hosting_missing_domain_name: string; diff --git a/src/frontend/src/lib/utils/i18n.utils.ts b/src/frontend/src/lib/utils/i18n.utils.ts index b018c9dfa..9d015d1ad 100644 --- a/src/frontend/src/lib/utils/i18n.utils.ts +++ b/src/frontend/src/lib/utils/i18n.utils.ts @@ -14,9 +14,16 @@ export const i18nFormat = ( return text; }; -export const groupLabel = (labelKey: string): string | undefined => { +export const i18nText = ({ i18n, labelKey }: { i18n: I18n; labelKey: string }): string => { const [group, key] = labelKey.split('.'); - const labels = get(i18n); - const obj = keyOf({ obj: labels, key: group }); + const obj = keyOf({ obj: i18n, key: group }); return keyOf({ obj, key }); }; + +export const i18nCapitalize = (text: string): string => { + const [firstLetter, ...rest] = text; + return `${firstLetter.toUpperCase()}${rest.join('')}`; +}; + +export const groupLabel = (labelKey: string): string | undefined => + i18nText({ i18n: get(i18n), labelKey });