From aed19935170ca2b86a2c1fa4515ae7c606930e32 Mon Sep 17 00:00:00 2001 From: vichansson Date: Thu, 1 Aug 2024 17:26:19 +0300 Subject: [PATCH] M #-: fix vm cache validation (#3184) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Victor Hansson Co-authored-by: Tino Vázquez --- .../BackupForm/Steps/DatastoresTable/index.js | 4 +- .../src/client/components/Tables/Vms/row.js | 13 +- src/fireedge/src/client/features/OneApi/vm.js | 183 ++++++++++++++---- 3 files changed, 157 insertions(+), 43 deletions(-) diff --git a/src/fireedge/src/client/components/Forms/Vm/BackupForm/Steps/DatastoresTable/index.js b/src/fireedge/src/client/components/Forms/Vm/BackupForm/Steps/DatastoresTable/index.js index eeff2ff1a34..36e343eaf67 100644 --- a/src/fireedge/src/client/components/Forms/Vm/BackupForm/Steps/DatastoresTable/index.js +++ b/src/fireedge/src/client/components/Forms/Vm/BackupForm/Steps/DatastoresTable/index.js @@ -20,7 +20,7 @@ import { DatastoresTable } from 'client/components/Tables' import { SCHEMA } from 'client/components/Forms/Vm/BackupForm/Steps/DatastoresTable/schema' import { Step } from 'client/utils' -import { T } from 'client/constants' +import { T, VM_EXTENDED_POOL } from 'client/constants' export const STEP_ID = 'datastore' @@ -66,7 +66,7 @@ const DatastoreStep = (app) => ({ resolver: SCHEMA, defaultDisabled: { statePaths: [ - 'oneApi.queries.getVms(undefined).data', + `oneApi.queries.getVms({"extended":${VM_EXTENDED_POOL}}).data`, 'general.selectedIds', ], condition: (vmsData, selectedIds) => diff --git a/src/fireedge/src/client/components/Tables/Vms/row.js b/src/fireedge/src/client/components/Tables/Vms/row.js index 255d9257d17..81d644b885d 100644 --- a/src/fireedge/src/client/components/Tables/Vms/row.js +++ b/src/fireedge/src/client/components/Tables/Vms/row.js @@ -18,7 +18,7 @@ import { memo, useCallback, useMemo } from 'react' import { ConsoleButton } from 'client/components/Buttons' import { VirtualMachineCard } from 'client/components/Cards' -import { VM_ACTIONS } from 'client/constants' +import { VM_ACTIONS, VM_EXTENDED_POOL } from 'client/constants' import { useGeneral } from 'client/features/General' import vmApi, { useUpdateUserTemplateMutation } from 'client/features/OneApi/vm' import { jsonToXml } from 'client/models/Helper' @@ -33,10 +33,13 @@ const Row = memo( const [update] = useUpdateUserTemplateMutation() - const state = vmApi.endpoints.getVms.useQueryState(undefined, { - selectFromResult: ({ data = [] }) => - data.find((vm) => +vm.ID === +original.ID), - }) + const state = vmApi.endpoints.getVms.useQueryState( + { extended: VM_EXTENDED_POOL }, + { + selectFromResult: ({ data = [] }) => + data.find((vm) => +vm.ID === +original.ID), + } + ) const memoVm = useMemo(() => state ?? original, [state, original]) diff --git a/src/fireedge/src/client/features/OneApi/vm.js b/src/fireedge/src/client/features/OneApi/vm.js index 514dc2c01e4..23f839a1736 100644 --- a/src/fireedge/src/client/features/OneApi/vm.js +++ b/src/fireedge/src/client/features/OneApi/vm.js @@ -112,7 +112,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, transformResponse: (data) => data?.VM ?? {}, - providesTags: (_, __, { id }) => [{ type: VM, id }], + providesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], async onQueryStarted({ id }, { dispatch, queryFulfilled }) { try { const { data: resourceFromQuery } = await queryFulfilled @@ -362,7 +365,11 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }, VM_POOL], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + VM_POOL, + ], }), actionVm: builder.mutation({ /** @@ -384,7 +391,11 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }, VM_POOL], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + VM_POOL, + ], }), migrate: builder.mutation({ /** @@ -409,7 +420,11 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }, VM_POOL], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + VM_POOL, + ], }), saveAsDisk: builder.mutation({ /** @@ -432,7 +447,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), createDiskSnapshot: builder.mutation({ /** @@ -451,7 +469,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), deleteDiskSnapshot: builder.mutation({ /** @@ -470,7 +491,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), revertDiskSnapshot: builder.mutation({ /** @@ -489,7 +513,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), renameDiskSnapshot: builder.mutation({ /** @@ -509,7 +536,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), attachDisk: builder.mutation({ /** @@ -528,7 +558,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), detachDisk: builder.mutation({ /** @@ -546,7 +579,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), resizeDisk: builder.mutation({ /** @@ -566,7 +602,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), attachNic: builder.mutation({ /** @@ -585,7 +624,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), detachNic: builder.mutation({ /** @@ -603,7 +645,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), updateNic: builder.mutation({ /** @@ -623,7 +668,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), attachSecurityGroup: builder.mutation({ /** @@ -643,7 +691,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), detachSecurityGroup: builder.mutation({ /** @@ -663,7 +714,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), changeVmPermissions: builder.mutation({ /** @@ -690,7 +744,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], async onQueryStarted(params, { dispatch, queryFulfilled }) { try { const patchVm = dispatch( @@ -723,7 +780,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], async onQueryStarted(params, { getState, dispatch, queryFulfilled }) { try { const patchVm = dispatch( @@ -754,7 +814,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], async onQueryStarted(params, { dispatch, queryFulfilled }) { try { const patchVm = dispatch( @@ -796,7 +859,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), revertVmSnapshot: builder.mutation({ /** @@ -814,7 +880,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), deleteVmSnapshot: builder.mutation({ /** @@ -832,7 +901,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), resize: builder.mutation({ /** @@ -851,7 +923,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), updateUserTemplate: builder.mutation({ /** @@ -873,7 +948,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], async onQueryStarted(params, { dispatch, queryFulfilled }) { try { const patchVm = dispatch( @@ -915,7 +993,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), recover: builder.mutation({ /** @@ -938,7 +1019,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), backup: builder.mutation({ /** @@ -957,7 +1041,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), restore: builder.mutation({ /** @@ -977,7 +1064,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), lockVm: builder.mutation({ /** @@ -996,7 +1086,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], async onQueryStarted(params, { dispatch, queryFulfilled }) { try { const patchVm = dispatch( @@ -1037,7 +1130,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], async onQueryStarted(params, { dispatch, queryFulfilled }) { try { const patchVm = dispatch( @@ -1079,7 +1175,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), updateScheduledAction: builder.mutation({ /** @@ -1098,7 +1197,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), deleteScheduledAction: builder.mutation({ /** @@ -1116,7 +1218,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), attachPci: builder.mutation({ /** @@ -1135,7 +1240,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), detachPci: builder.mutation({ /** @@ -1153,7 +1261,10 @@ const vmApi = oneApi.injectEndpoints({ return { params, command } }, - invalidatesTags: (_, __, { id }) => [{ type: VM, id }], + invalidatesTags: (_, __, { id }) => [ + { type: VM, id }, + { type: VM_POOL, id }, + ], }), }), })