From b600e08b4643264de4b2ca2cdcc5d8e88758060f Mon Sep 17 00:00:00 2001 From: zaelgohary Date: Mon, 15 Apr 2024 17:28:49 +0200 Subject: [PATCH] Refactor Dashboard to use grid store instead of initializing grid multiple times --- .../contracts_list/contracts_table.vue | 10 +++++----- .../src/components/deployment_data_dialog.vue | 10 +++++----- .../src/components/deposit_dialog.vue | 10 +++++++--- .../playground/src/components/funds_card.vue | 11 +++++++---- .../manage_caprover_worker_dialog.vue | 13 +++++++------ .../src/components/manage_gateway_dialog.vue | 13 ++++--------- .../src/components/manage_k8s_worker_dialog.vue | 11 +++++------ .../src/components/select_gateway_node.vue | 10 ++++------ .../src/components/tf_notification.vue | 1 - .../src/components/withdraw_dialog.vue | 11 +++++++---- .../dashboard/components/reserve_action_btn.vue | 9 ++++++--- packages/playground/src/dashboard/dao_view.vue | 11 +++++++---- packages/playground/src/utils/contracts.ts | 2 +- packages/playground/src/weblets/freeflow.vue | 10 +++++----- packages/playground/src/weblets/full_vm.vue | 11 ++++++++--- packages/playground/src/weblets/micro_vm.vue | 12 +++++++----- packages/playground/src/weblets/tf_algorand.vue | 10 +++++++--- packages/playground/src/weblets/tf_caprover.vue | 10 +++++++--- .../playground/src/weblets/tf_casperlabs.vue | 9 +++++---- .../src/weblets/tf_contracts_list.vue | 14 +++++++------- .../playground/src/weblets/tf_discourse.vue | 9 +++++---- .../playground/src/weblets/tf_funkwhale.vue | 9 +++++---- .../playground/src/weblets/tf_kubernetes.vue | 12 +++++++----- .../playground/src/weblets/tf_mattermost.vue | 10 ++++++---- .../playground/src/weblets/tf_nextcloud.vue | 9 +++++---- .../playground/src/weblets/tf_node_pilot.vue | 11 +++++++---- packages/playground/src/weblets/tf_owncloud.vue | 10 +++++----- packages/playground/src/weblets/tf_peertube.vue | 10 +++++----- .../playground/src/weblets/tf_presearch.vue | 12 +++++++----- packages/playground/src/weblets/tf_subsquid.vue | 9 +++++---- packages/playground/src/weblets/tf_taiga.vue | 9 +++++---- packages/playground/src/weblets/tf_umbrel.vue | 11 ++++++++--- .../playground/src/weblets/tf_wordpress.vue | 17 ++++++++--------- 33 files changed, 189 insertions(+), 147 deletions(-) diff --git a/packages/playground/src/components/contracts_list/contracts_table.vue b/packages/playground/src/components/contracts_list/contracts_table.vue index 3649f7474e..92d7462427 100644 --- a/packages/playground/src/components/contracts_list/contracts_table.vue +++ b/packages/playground/src/components/contracts_list/contracts_table.vue @@ -172,7 +172,7 @@ const props = defineProps({ required: true, }, grid: { - type: Object as PropType>, + type: Object as PropType, required: true, }, loading: { @@ -232,7 +232,7 @@ async function showDetails(value: any) { loadingContractId.value = contractId; try { - const deployment = await props.grid.value?.zos.getDeployment({ contractId }); + const deployment = await props.grid?.zos.getDeployment({ contractId }); return layout.value.openDialog(deployment, false, true); } catch (e) { failedContractId.value = contractId; @@ -248,12 +248,12 @@ async function contractLockDetails(item: any) { contractStateDialog.value = true; loadingShowDetails.value = true; selectedItem.value = item; - await props.grid.value?.contracts + await props.grid?.contracts .contractLock({ id: item.contractId }) .then((data: ContractLock) => { contractLocked.value = data; }) - .catch(err => { + .catch((err: any) => { layout.value.setStatus( "failed", normalizeError(err, `Failed to fetch the contract ${item.contractId} lock details.`), @@ -279,7 +279,7 @@ async function onDelete() { deleting.value = true; try { - await props.grid.value?.contracts.batchCancelContracts({ + await props.grid?.contracts.batchCancelContracts({ ids: selectedContracts.value.map(c => c.contractId), }); contracts.value = contracts.value.filter(c => !selectedContracts.value.includes(c)); diff --git a/packages/playground/src/components/deployment_data_dialog.vue b/packages/playground/src/components/deployment_data_dialog.vue index 64d92ba4c5..00298b377a 100644 --- a/packages/playground/src/components/deployment_data_dialog.vue +++ b/packages/playground/src/components/deployment_data_dialog.vue @@ -164,6 +164,8 @@ const contract = computed(() => contracts.value?.[activeTab.value] ?? {}); const code = computed(() => JSON.stringify(props.data || {}, undefined, 2)); const html = computed(() => hljs.highlight(code.value, { language: "json" }).value); const profileManager = useProfileManager(); +const gridStore = useGrid(); +const grid = gridStore.client as GridClient; function copy() { navigator.clipboard.writeText(code.value); @@ -196,7 +198,6 @@ function getValue(key: string) { async function getGrafanaUrl() { isLoading.value = true; - const grid = await getGrid(profileManager.profile!); if (grid) { if (contract.value.type !== ContractType.NAME) { const nodeId = await grid.capacity.getNodeIdFromContractId({ @@ -213,8 +214,6 @@ getGrafanaUrl(); async function getGPUInfo() { loadingCard.value = true; - - const grid = await getGrid(profileManager.profile!); if (grid) { const nodeId = await grid.capacity.getNodeIdFromContractId({ contractId: contract.value.contractId, @@ -302,13 +301,14 @@ function getTooltipText(contract: any, index: number) {