Commit ccd20df3 authored by Andrew Fontaine's avatar Andrew Fontaine

Fetch specific scope for environment folder

If the user is looking at stopped environments, this ensures the scope
is passed to the HTTP call and that stopped environments in folders are
fetched as well.
parent 5fd785d6
...@@ -19,6 +19,10 @@ export default { ...@@ -19,6 +19,10 @@ export default {
type: Object, type: Object,
required: true, required: true,
}, },
scope: {
type: String,
required: true,
},
}, },
data() { data() {
return { visible: false, interval: undefined }; return { visible: false, interval: undefined };
...@@ -27,7 +31,7 @@ export default { ...@@ -27,7 +31,7 @@ export default {
folder: { folder: {
query: folderQuery, query: folderQuery,
variables() { variables() {
return { environment: this.nestedEnvironment.latest }; return { environment: this.nestedEnvironment.latest, scope: this.scope };
}, },
pollInterval() { pollInterval() {
return this.interval; return this.interval;
...@@ -52,7 +56,7 @@ export default { ...@@ -52,7 +56,7 @@ export default {
return this.visible ? this.$options.i18n.collapse : this.$options.i18n.expand; return this.visible ? this.$options.i18n.collapse : this.$options.i18n.expand;
}, },
count() { count() {
return this.folder?.availableCount ?? 0; return this.folder?.[`${this.scope}Count`] ?? 0;
}, },
folderClass() { folderClass() {
return { 'gl-font-weight-bold': this.visible }; return { 'gl-font-weight-bold': this.visible };
......
query getEnvironmentFolder($environment: NestedLocalEnvironment) { query getEnvironmentFolder($environment: NestedLocalEnvironment, $scope: String) {
folder(environment: $environment) @client { folder(environment: $environment, scope: $scope) @client {
availableCount availableCount
environments environments
stoppedCount stoppedCount
......
...@@ -59,8 +59,8 @@ export const resolvers = (endpoint) => ({ ...@@ -59,8 +59,8 @@ export const resolvers = (endpoint) => ({
}; };
}); });
}, },
folder(_, { environment: { folderPath } }) { folder(_, { environment: { folderPath }, scope }) {
return axios.get(folderPath, { params: { per_page: 3 } }).then((res) => ({ return axios.get(folderPath, { params: { scope, per_page: 3 } }).then((res) => ({
availableCount: res.data.available_count, availableCount: res.data.available_count,
environments: res.data.environments.map(mapEnvironment), environments: res.data.environments.map(mapEnvironment),
stoppedCount: res.data.stopped_count, stoppedCount: res.data.stopped_count,
......
...@@ -124,10 +124,11 @@ describe('~/frontend/environments/graphql/resolvers', () => { ...@@ -124,10 +124,11 @@ describe('~/frontend/environments/graphql/resolvers', () => {
}); });
describe('folder', () => { describe('folder', () => {
it('should fetch the folder url passed to it', async () => { it('should fetch the folder url passed to it', async () => {
mock.onGet(ENDPOINT, { params: { per_page: 3 } }).reply(200, folder); mock.onGet(ENDPOINT, { params: { per_page: 3, scope: 'available' } }).reply(200, folder);
const environmentFolder = await mockResolvers.Query.folder(null, { const environmentFolder = await mockResolvers.Query.folder(null, {
environment: { folderPath: ENDPOINT }, environment: { folderPath: ENDPOINT },
scope: 'available',
}); });
expect(environmentFolder).toEqual(resolvedFolder); expect(environmentFolder).toEqual(resolvedFolder);
......
...@@ -30,7 +30,10 @@ describe('~/environments/components/new_environments_folder.vue', () => { ...@@ -30,7 +30,10 @@ describe('~/environments/components/new_environments_folder.vue', () => {
const createWrapper = (propsData, apolloProvider) => const createWrapper = (propsData, apolloProvider) =>
mountExtended(EnvironmentsFolder, { mountExtended(EnvironmentsFolder, {
apolloProvider, apolloProvider,
propsData, propsData: {
scope: 'available',
...propsData,
},
stubs: { transition: stubTransition() }, stubs: { transition: stubTransition() },
provide: { helpPagePath: '/help' }, provide: { helpPagePath: '/help' },
}); });
......
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