Skip to content

Commit

Permalink
fix(entity-consumers): optimize consumer data fetching in `<AddConsum…
Browse files Browse the repository at this point in the history
…erModal />` (#935)

Previously, `<AddConsumerModal />` and `<AddToGroupModal />` triggers `loadItems`
during `onBeforeMount`, leading to premature and unnecessary data fetching,
especially in scenarios where only browsing the list is required.

This fetching strategy also resulted in outdated, non-refreshable data.
To resolve this, `loadItems` has been shifted to a `watch` block, ensuring timely
and relevant data fetching.

Additionally, the sandbox page now references `VITE_KONG_MANAGER_CONSUMER_GROUP_ID`
for dynamic consumer group ID handling, replacing the previously hardcoded value.
  • Loading branch information
nekolab authored Nov 22, 2023
1 parent e5739af commit b2f8cc5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions .env.development.local.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ VITE_KONNECT_CONTROL_PLANE_ID=

# Kong Manager Consumer Id
VITE_KONG_MANAGER_CONSUMER_ID=
VITE_KONG_MANAGER_CONSUMER_GROUP_ID=

# Konnect Consumer Id
VITE_KONNECT_CONSUMER_ID=
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const kongManagerConfig = ref<KongManagerConsumerGroupListConfig>({
apiBaseUrl: '/kong-manager', // For local dev server proxy
isExactMatch: false,
// Uncomment to test Consumer -> Consumer Groups
// consumerId: 'b20b1848-6640-4200-9102-73a184de976e',
// consumerId: import.meta.env.VITE_KONG_MANAGER_CONSUMER_ID,
// consumerUsername: 'c-1',
createRoute: { name: 'create-consumer-group' },
getViewRoute: (id: string) => ({ name: 'view-consumer-group', params: { id } }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

<script setup lang="ts">
import type { PropType } from 'vue'
import { computed, ref, watch, onBeforeMount } from 'vue'
import { computed, ref, watch } from 'vue'
import type {
KongManagerConsumerGroupListConfig,
KonnectConsumerGroupListConfig,
Expand Down Expand Up @@ -253,10 +253,11 @@ watch(availableConsumerGroups, () => {
consumerGroupsSelectKey.value++
}, { immediate: true, deep: true })
onBeforeMount(async () => {
// load consumer groups
await loadItems()
})
watch(() => props.visible, () => {
if (props.visible) {
loadItems() // load consumer groups
}
}, { immediate: true })
</script>

<style lang="scss" scoped>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const kongManagerConfig = ref<KongManagerConsumerListConfig>({
isExactMatch: false,
createRoute: { name: 'create-consumer' },
// Uncomment to test Consumer Groups -> Consumers
consumerGroupId: '0de87974-352c-4054-8969-238cdd82a57f',
// consumerGroupId: import.meta.env.VITE_KONG_MANAGER_CONSUMER_GROUP_ID,
// consumerGroupName: 'Group 1',
getViewRoute: (id: string) => ({ name: 'view-consumer', params: { id } }),
getEditRoute: (id: string) => ({ name: 'edit-consumer', params: { id } }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@

<script setup lang="ts">
import type { PropType } from 'vue'
import { computed, ref, watch, onBeforeMount } from 'vue'
import { computed, ref, watch } from 'vue'
import type {
KongManagerConsumerListConfig,
KonnectConsumerListConfig,
Expand Down Expand Up @@ -268,10 +268,11 @@ watch(availableConsumers, () => {
consumersSelectKey.value++
}, { immediate: true, deep: true })
onBeforeMount(async () => {
// load consumers
await loadItems()
})
watch(() => props.visible, () => {
if (props.visible) {
loadItems() // load consumers
}
}, { immediate: true })
</script>

<style lang="scss" scoped>
Expand Down

0 comments on commit b2f8cc5

Please sign in to comment.