Skip to content

Commit 0479703

Browse files
authored
Fix reload domains function (#4069)
* Fix reload domains function * Remove the unnecessary getNodePageCount request * Restore `pageCountTask` * Remove unwanted checks and vars * Reload nodes instead of just loading node in case interfaces changed
1 parent 8e351b1 commit 0479703

File tree

1 file changed

+33
-29
lines changed

1 file changed

+33
-29
lines changed

packages/playground/src/components/node_selector/TfDomainName.vue

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,11 @@
104104
<script lang="ts">
105105
import { type FarmInfo, Features, type FilterOptions, type NodeInfo } from "@threefold/grid_client";
106106
import { noop } from "lodash";
107-
import { computed, getCurrentInstance, nextTick, onUnmounted, type PropType, ref, watch } from "vue";
108-
import { onMounted } from "vue";
109-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
110-
import type { VInput } from "vuetify/components/VInput";
107+
import { computed, getCurrentInstance, nextTick, onMounted, onUnmounted, type PropType, ref, watch } from "vue";
111108
112109
import { type InputValidatorService, useInputRef } from "@/hooks/input_validator";
113110
114-
import { useAsync, usePagination, useWatchDeep } from "../../hooks";
111+
import { useAsync, usePagination } from "../../hooks";
115112
import { useForm, useFormRef, ValidatorStatus } from "../../hooks/form_validator";
116113
import { useGrid } from "../../stores";
117114
import type { DomainInfo, NetworkFeatures, SelectionDetailsFilters } from "../../types/nodeSelector";
@@ -157,9 +154,10 @@ export default {
157154
const pagination = usePagination();
158155
159156
const enableCustomDomain = ref(false);
157+
const size = ref(window.env.PAGE_SIZE);
160158
const filters = computed<FilterOptions>(() => ({
161159
gateway: true,
162-
size: window.env.PAGE_SIZE,
160+
size: size.value,
163161
page: Math.max(1, pagination.value.page),
164162
farmId: enableCustomDomain.value ? props.farm?.farmId : undefined,
165163
availableFor: gridStore.client?.twinId,
@@ -170,47 +168,52 @@ export default {
170168
const loadDomains = () => domainsTask.value.run(gridStore, filters.value);
171169
172170
const domainInput = useInputRef();
173-
const reloadDomains = async (_filters: FilterOptions = filters.value) => {
171+
const reloadDomains = async () => {
174172
domainInput.value?.reset();
175173
if (selectedDomain.value) {
176174
selectedDomain.value = null;
177175
bindModelValue();
178176
}
179-
await pageCountTask.value.run(gridStore, _filters);
177+
await pageCountTask.value.run(gridStore, filters.value);
180178
pagination.value.reset(pageCountTask.value.data as number);
181-
await nextTick();
182179
loadedDomains.value = [];
180+
await nextTick();
183181
return loadDomains();
184182
};
185-
let previousFilters = JSON.stringify(filters.value);
186-
useWatchDeep(
187-
filters,
188-
newFilters => {
189-
const currentFilters = JSON.stringify(newFilters);
190-
if (currentFilters !== previousFilters) {
191-
reloadDomains();
192-
previousFilters = currentFilters;
193-
}
183+
184+
watch(
185+
[() => props.farm?.farmId, () => gridStore.client?.twinId, () => props.interfaces],
186+
() => {
187+
reloadDomains();
194188
},
195-
{ immediate: true, deep: true, ignoreFields: ["page"] },
189+
{ deep: true },
196190
);
191+
192+
onMounted(() => {
193+
loadDomains();
194+
});
195+
197196
const customDomain = ref("");
198197
const domainFormRef = useFormRef();
199198
200199
const disableSelectedDomain = computed(() => enableCustomDomain.value && props.filters.ipv4 === true);
201200
const useFQDN = computed(() => enableCustomDomain.value && (props.useFqdn || props.filters.ipv4 === false));
202201
203-
const domain = computed<DomainInfo>(() => {
204-
return {
205-
selectedDomain: disableSelectedDomain.value ? null : selectedDomain.value,
206-
enableSelectedDomain: !disableSelectedDomain.value,
207-
enabledCustomDomain: enableCustomDomain.value,
208-
customDomain: enableCustomDomain.value ? customDomain.value : "",
209-
useFQDN: useFQDN.value,
210-
};
211-
});
202+
const domain = computed<DomainInfo>(() => ({
203+
selectedDomain: disableSelectedDomain.value ? null : selectedDomain.value,
204+
enableSelectedDomain: !disableSelectedDomain.value,
205+
enabledCustomDomain: enableCustomDomain.value,
206+
customDomain: enableCustomDomain.value ? customDomain.value : "",
207+
useFQDN: useFQDN.value,
208+
}));
212209
213-
useWatchDeep(domain, bindModelValue, { immediate: true, deep: true });
210+
watch(
211+
domain,
212+
newDomain => {
213+
bindModelValue(newDomain);
214+
},
215+
{ immediate: true },
216+
);
214217
215218
onUnmounted(() => {
216219
bindModelValue();
@@ -278,6 +281,7 @@ export default {
278281
selectedDomain,
279282
loadDomains,
280283
reloadDomains,
284+
size,
281285
282286
domainFormRef,
283287
domainInput,

0 commit comments

Comments
 (0)