Commit 64d174b2 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch '326682-move-devops-adoption-apollo-query-calls-to-smart-queries' into 'master'

Move DevOps Adoption groups query call to smart query

See merge request gitlab-org/gitlab!73543
parents 44ee4b9d 9bcc2a4d
...@@ -52,7 +52,6 @@ export default { ...@@ -52,7 +52,6 @@ export default {
data() { data() {
return { return {
hasSubgroups: undefined, hasSubgroups: undefined,
isLoadingGroups: false,
isLoadingEnableGroup: false, isLoadingEnableGroup: false,
requestCount: 0, requestCount: 0,
openModal: false, openModal: false,
...@@ -68,6 +67,7 @@ export default { ...@@ -68,6 +67,7 @@ export default {
adoptionTabClicked: false, adoptionTabClicked: false,
devopsScoreTabClicked: false, devopsScoreTabClicked: false,
selectedTab: 0, selectedTab: 0,
groupsSearchTerm: '',
}; };
}, },
apollo: { apollo: {
...@@ -94,6 +94,25 @@ export default { ...@@ -94,6 +94,25 @@ export default {
this.handleError(I18N_ENABLED_NAMESPACE_QUERY_ERROR, error); this.handleError(I18N_ENABLED_NAMESPACE_QUERY_ERROR, error);
}, },
}, },
groups: {
query: getGroupsQuery,
context: {
isSingleRequest: true,
},
variables() {
return {
search: this.groupsSearchTerm,
};
},
result({ data }) {
if (this.hasSubgroups === undefined) {
this.hasSubgroups = data.groups?.nodes?.length > 0;
}
},
error(error) {
this.handleError(I18N_GROUPS_QUERY_ERROR, error);
},
},
}, },
computed: { computed: {
isAdmin() { isAdmin() {
...@@ -116,7 +135,7 @@ export default { ...@@ -116,7 +135,7 @@ export default {
}, },
isLoading() { isLoading() {
return ( return (
this.isLoadingGroups || this.$apollo.queries.groups.loading ||
this.isLoadingEnableGroup || this.isLoadingEnableGroup ||
this.$apollo.queries.devopsAdoptionEnabledNamespaces.loading this.$apollo.queries.devopsAdoptionEnabledNamespaces.loading
); );
...@@ -142,7 +161,6 @@ export default { ...@@ -142,7 +161,6 @@ export default {
}, },
}, },
created() { created() {
this.fetchGroups();
this.selectTab(); this.selectTab();
this.startPollingTableData(); this.startPollingTableData();
}, },
...@@ -202,30 +220,8 @@ export default { ...@@ -202,30 +220,8 @@ export default {
this.errors.push(message); this.errors.push(message);
Sentry.captureException(error); Sentry.captureException(error);
}, },
fetchGroups(searchTerm = '') { setGroupsSearchTerm(searchTerm = '') {
this.searchTerm = searchTerm; this.groupsSearchTerm = searchTerm;
this.isLoadingGroups = true;
this.$apollo
.query({
query: getGroupsQuery,
context: {
isSingleRequest: true,
},
variables: {
search: searchTerm,
},
})
.then(({ data }) => {
this.groups = data.groups;
if (this.hasSubgroups === undefined) {
this.hasSubgroups = this.groups?.nodes?.length > 0;
}
this.isLoadingGroups = false;
})
.catch((error) => this.handleError(I18N_GROUPS_QUERY_ERROR, error));
}, },
addEnabledNamespacesToCache(enabledNamespaces) { addEnabledNamespacesToCache(enabledNamespaces) {
const { cache } = this.$apollo.getClient(); const { cache } = this.$apollo.getClient();
...@@ -310,12 +306,12 @@ export default { ...@@ -310,12 +306,12 @@ export default {
:has-group-data="hasGroupData" :has-group-data="hasGroupData"
:cols="tab.cols" :cols="tab.cols"
:enabled-namespaces="devopsAdoptionEnabledNamespaces" :enabled-namespaces="devopsAdoptionEnabledNamespaces"
:search-term="searchTerm" :search-term="groupsSearchTerm"
:groups="availableGroups" :groups="availableGroups"
:is-loading-groups="isLoadingGroups" :is-loading-groups="$apollo.queries.groups.loading"
:has-subgroups="hasSubgroups" :has-subgroups="hasSubgroups"
@enabledNamespacesRemoved="deleteEnabledNamespacesFromCache" @enabledNamespacesRemoved="deleteEnabledNamespacesFromCache"
@fetchGroups="fetchGroups" @fetchGroups="setGroupsSearchTerm"
@enabledNamespacesAdded="addEnabledNamespacesToCache" @enabledNamespacesAdded="addEnabledNamespacesToCache"
@trackModalOpenState="trackModalOpenState" @trackModalOpenState="trackModalOpenState"
/> />
...@@ -332,12 +328,12 @@ export default { ...@@ -332,12 +328,12 @@ export default {
align="right" align="right"
> >
<devops-adoption-add-dropdown <devops-adoption-add-dropdown
:search-term="searchTerm" :search-term="groupsSearchTerm"
:groups="availableGroups" :groups="availableGroups"
:enabled-namespaces="devopsAdoptionEnabledNamespaces" :enabled-namespaces="devopsAdoptionEnabledNamespaces"
:is-loading-groups="isLoadingGroups" :is-loading-groups="$apollo.queries.groups.loading"
:has-subgroups="hasSubgroups" :has-subgroups="hasSubgroups"
@fetchGroups="fetchGroups" @fetchGroups="setGroupsSearchTerm"
@enabledNamespacesAdded="addEnabledNamespacesToCache" @enabledNamespacesAdded="addEnabledNamespacesToCache"
@enabledNamespacesRemoved="deleteEnabledNamespacesFromCache" @enabledNamespacesRemoved="deleteEnabledNamespacesFromCache"
/> />
......
...@@ -176,6 +176,29 @@ describe('DevopsAdoptionApp', () => { ...@@ -176,6 +176,29 @@ describe('DevopsAdoptionApp', () => {
expect(Sentry.captureException.mock.calls[0][0].networkError).toBe(NETWORK_ERROR); expect(Sentry.captureException.mock.calls[0][0].networkError).toBe(NETWORK_ERROR);
}); });
}); });
describe('refetches data when groupsSearchTerm is updated', () => {
beforeEach(async () => {
groupsSpy = promiseFactory(STATE_WITH_DATA, RESOURCE_TYPE_GROUP);
const mockApollo = createMockApolloProvider({ groupsSpy });
wrapper = createComponent({ mockApollo });
await waitForPromises();
});
it.each`
name | component
${'DevopsAdoptionSection'} | ${DevopsAdoptionSection}
${'DevopsAdoptionAddDropdown'} | ${DevopsAdoptionAddDropdown}
`('from $name', async ({ component }) => {
expect(groupsSpy).toHaveBeenCalledTimes(1);
wrapper.findComponent(component).vm.$emit('fetchGroups', 'group');
await waitForPromises();
expect(groupsSpy).toHaveBeenCalledTimes(2);
});
});
}); });
describe('enabled namespaces data', () => { describe('enabled namespaces data', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment