Commit abf58f3a authored by Jose Vargas's avatar Jose Vargas

Remove redundant queries and refactor

This removes redundant queries and
makes multiple related queries live in
a single GraphQL file, this also removes
DOMContentLoaded calls
parent 8b54a3f3
...@@ -3,12 +3,10 @@ import AdminRunnersFilteredSearchTokenKeys from '~/filtered_search/admin_runners ...@@ -3,12 +3,10 @@ import AdminRunnersFilteredSearchTokenKeys from '~/filtered_search/admin_runners
import { FILTERED_SEARCH } from '~/pages/constants'; import { FILTERED_SEARCH } from '~/pages/constants';
import { initInstallRunner } from '~/pages/shared/mount_runner_instructions'; import { initInstallRunner } from '~/pages/shared/mount_runner_instructions';
document.addEventListener('DOMContentLoaded', () => { initFilteredSearch({
initFilteredSearch({ page: FILTERED_SEARCH.ADMIN_RUNNERS,
page: FILTERED_SEARCH.ADMIN_RUNNERS, filteredSearchTokenKeys: AdminRunnersFilteredSearchTokenKeys,
filteredSearchTokenKeys: AdminRunnersFilteredSearchTokenKeys, useDefaultState: true,
useDefaultState: true,
});
initInstallRunner();
}); });
initInstallRunner();
...@@ -6,18 +6,16 @@ import { FILTERED_SEARCH } from '~/pages/constants'; ...@@ -6,18 +6,16 @@ import { FILTERED_SEARCH } from '~/pages/constants';
import initSharedRunnersForm from '~/group_settings/mount_shared_runners'; import initSharedRunnersForm from '~/group_settings/mount_shared_runners';
import { initInstallRunner } from '~/pages/shared/mount_runner_instructions'; import { initInstallRunner } from '~/pages/shared/mount_runner_instructions';
document.addEventListener('DOMContentLoaded', () => { // Initialize expandable settings panels
// Initialize expandable settings panels initSettingsPanels();
initSettingsPanels();
initFilteredSearch({ initFilteredSearch({
page: FILTERED_SEARCH.ADMIN_RUNNERS, page: FILTERED_SEARCH.ADMIN_RUNNERS,
filteredSearchTokenKeys: GroupRunnersFilteredSearchTokenKeys, filteredSearchTokenKeys: GroupRunnersFilteredSearchTokenKeys,
anchor: FILTERED_SEARCH.GROUP_RUNNERS_ANCHOR, anchor: FILTERED_SEARCH.GROUP_RUNNERS_ANCHOR,
useDefaultState: false, useDefaultState: false,
});
initSharedRunnersForm();
initVariableList();
initInstallRunner();
}); });
initSharedRunnersForm();
initVariableList();
initInstallRunner();
...@@ -6,32 +6,30 @@ import initDeployFreeze from '~/deploy_freeze'; ...@@ -6,32 +6,30 @@ import initDeployFreeze from '~/deploy_freeze';
import initSettingsPipelinesTriggers from '~/ci_settings_pipeline_triggers'; import initSettingsPipelinesTriggers from '~/ci_settings_pipeline_triggers';
import { initInstallRunner } from '~/pages/shared/mount_runner_instructions'; import { initInstallRunner } from '~/pages/shared/mount_runner_instructions';
document.addEventListener('DOMContentLoaded', () => { // Initialize expandable settings panels
// Initialize expandable settings panels initSettingsPanels();
initSettingsPanels();
const runnerToken = document.querySelector('.js-secret-runner-token'); const runnerToken = document.querySelector('.js-secret-runner-token');
if (runnerToken) { if (runnerToken) {
const runnerTokenSecretValue = new SecretValues({ const runnerTokenSecretValue = new SecretValues({
container: runnerToken, container: runnerToken,
});
runnerTokenSecretValue.init();
}
initVariableList();
// hide extra auto devops settings based checkbox state
const autoDevOpsExtraSettings = document.querySelector('.js-extra-settings');
const instanceDefaultBadge = document.querySelector('.js-instance-default-badge');
document.querySelector('.js-toggle-extra-settings').addEventListener('click', event => {
const { target } = event;
if (instanceDefaultBadge) instanceDefaultBadge.style.display = 'none';
autoDevOpsExtraSettings.classList.toggle('hidden', !target.checked);
}); });
runnerTokenSecretValue.init();
}
registrySettingsApp(); initVariableList();
initDeployFreeze();
initSettingsPipelinesTriggers(); // hide extra auto devops settings based checkbox state
initInstallRunner(); const autoDevOpsExtraSettings = document.querySelector('.js-extra-settings');
const instanceDefaultBadge = document.querySelector('.js-instance-default-badge');
document.querySelector('.js-toggle-extra-settings').addEventListener('click', event => {
const { target } = event;
if (instanceDefaultBadge) instanceDefaultBadge.style.display = 'none';
autoDevOpsExtraSettings.classList.toggle('hidden', !target.checked);
}); });
registrySettingsApp();
initDeployFreeze();
initSettingsPipelinesTriggers();
initInstallRunner();
...@@ -5,9 +5,9 @@ import InstallRunnerInstructions from '~/vue_shared/components/runner_instructio ...@@ -5,9 +5,9 @@ import InstallRunnerInstructions from '~/vue_shared/components/runner_instructio
Vue.use(VueApollo); Vue.use(VueApollo);
export function initInstallRunner() { export function initInstallRunner(componentId = 'js-install-runner') {
const installRunnerEl = document.getElementById('js-install-runner'); const installRunnerEl = document.getElementById(componentId);
const { projectPath, groupPath } = installRunnerEl.dataset || {}; const { projectPath, groupPath } = installRunnerEl?.dataset;
if (installRunnerEl) { if (installRunnerEl) {
const defaultClient = createDefaultClient(); const defaultClient = createDefaultClient();
......
query getProjectId($projectPath: ID!) {
project(fullPath: $projectPath) {
id
}
}
query getRunnerPlatforms { query getRunnerPlatforms($projectPath: ID!, $groupPath: ID!) {
runnerPlatforms { runnerPlatforms {
nodes { nodes {
name name
...@@ -11,4 +11,10 @@ query getRunnerPlatforms { ...@@ -11,4 +11,10 @@ query getRunnerPlatforms {
} }
} }
} }
project(fullPath: $projectPath) {
id
}
group(fullPath: $groupPath) {
id
}
} }
query runnerSetupInstructions($platform: String!, $architecture: String!, $projectId: ID!) { query runnerSetupInstructions(
runnerSetup(platform: $platform, architecture: $architecture, projectId: $projectId) { $platform: String!
$architecture: String!
$projectId: ID!
$groupId: ID!
) {
runnerSetup(
platform: $platform
architecture: $architecture
projectId: $projectId
groupId: $groupId
) {
installInstructions installInstructions
registerInstructions registerInstructions
} }
......
query runnerSetupInstructionsGroup($platform: String!, $architecture: String!) {
runnerSetup(platform: $platform, architecture: $architecture) {
installInstructions
registerInstructions
}
}
query runnerSetupInstructionsGroup($platform: String!, $architecture: String!, $groupId: ID!) {
runnerSetup(platform: $platform, architecture: $architecture, groupId: $groupId) {
installInstructions
registerInstructions
}
}
...@@ -12,10 +12,6 @@ import { ...@@ -12,10 +12,6 @@ import {
import { __, s__ } from '~/locale'; import { __, s__ } from '~/locale';
import getRunnerPlatforms from './graphql/queries/get_runner_platforms.query.graphql'; import getRunnerPlatforms from './graphql/queries/get_runner_platforms.query.graphql';
import getRunnerSetupInstructions from './graphql/queries/get_runner_setup.query.graphql'; import getRunnerSetupInstructions from './graphql/queries/get_runner_setup.query.graphql';
import getRunnerSetupInstructionsGroup from './graphql/queries/get_runner_setup_group.query.graphql';
import getRunnerSetupInstructionsAdmin from './graphql/queries/get_runner_setup_admin.query.graphql';
import getProjectId from './graphql/queries/get_project_id.query.graphql';
import getGroupId from './graphql/queries/get_group_id.query.graphql';
export default { export default {
components: { components: {
...@@ -41,36 +37,16 @@ export default { ...@@ -41,36 +37,16 @@ export default {
apollo: { apollo: {
runnerPlatforms: { runnerPlatforms: {
query: getRunnerPlatforms, query: getRunnerPlatforms,
update(data) {
return data?.runnerPlatforms?.nodes;
},
error() {
this.showAlert = true;
},
},
projectId: {
query: getProjectId,
variables() { variables() {
return { return {
projectPath: this.projectPath, projectPath: this.projectPath,
};
},
update(data) {
return data?.project?.id;
},
error() {
this.showAlert = true;
},
},
groupId: {
query: getGroupId,
variables() {
return {
groupPath: this.groupPath, groupPath: this.groupPath,
}; };
}, },
update(data) { update(data) {
return data?.group?.id; this.groupId = data.group?.id;
this.projectId = data.project?.id;
return data?.runnerPlatforms?.nodes;
}, },
error() { error() {
this.showAlert = true; this.showAlert = true;
...@@ -90,17 +66,11 @@ export default { ...@@ -90,17 +66,11 @@ export default {
}; };
}, },
computed: { computed: {
closeButton() {
return {
text: __('Close'),
attributes: [{ variant: 'default' }],
};
},
isPlatformSelected() { isPlatformSelected() {
return Object.keys(this.selectedPlatform).length > 0; return Object.keys(this.selectedPlatform).length > 0;
}, },
instructionsEmpty() { instructionsEmpty() {
return this.instructions == null || Object.keys(this.instructions).length === 0; return this.instructions && Object.keys(this.instructions).length === 0;
}, },
}, },
methods: { methods: {
...@@ -108,38 +78,21 @@ export default { ...@@ -108,38 +78,21 @@ export default {
this.selectedPlatform = this.runnerPlatforms.find(platform => platform.name === name); this.selectedPlatform = this.runnerPlatforms.find(platform => platform.name === name);
this.selectedPlatformArchitectures = this.selectedPlatform?.architectures?.nodes; this.selectedPlatformArchitectures = this.selectedPlatform?.architectures?.nodes;
[this.selectedArchitecture] = this.selectedPlatformArchitectures; [this.selectedArchitecture] = this.selectedPlatformArchitectures;
this.selectArchitecture(this.selectedArchitecture.name); this.selectArchitecture(this.selectedArchitecture);
}, },
selectArchitecture(name) { selectArchitecture(architecture) {
this.selectedArchitecture = this.selectedPlatformArchitectures.find( this.selectedArchitecture = architecture;
architecture => architecture.name === name,
);
this.$apollo.addSmartQuery('instructions', { this.$apollo.addSmartQuery('instructions', {
variables() { variables() {
const vars = { return {
platform: this.selectedPlatform.name, platform: this.selectedPlatform.name,
architecture: this.selectedArchitecture.name, architecture: this.selectedArchitecture.name,
projectId: this.projectId ? this.projectId : '',
groupId: this.groupId ? this.groupId : '',
}; };
if (this.projectId) {
vars.projectId = this.projectId;
}
if (this.groupId) {
vars.groupId = this.groupId;
}
return vars;
},
query() {
if (this.projectId) {
return getRunnerSetupInstructions;
} else if (this.groupId) {
return getRunnerSetupInstructionsGroup;
}
return getRunnerSetupInstructionsAdmin;
}, },
query: getRunnerSetupInstructions,
update(data) { update(data) {
return data?.runnerSetup; return data?.runnerSetup;
}, },
...@@ -155,14 +108,18 @@ export default { ...@@ -155,14 +108,18 @@ export default {
modalId: 'installation-instructions-modal', modalId: 'installation-instructions-modal',
i18n: { i18n: {
installARunner: __('Install a Runner'), installARunner: __('Install a Runner'),
architecture: __('Architecture'), architecture: s__('Runners|Architecture'),
downloadInstallBinary: s__('Runners|Download and Install Binary'), downloadInstallBinary: s__('Runners|Download and Install Binary'),
downloadLatestBinary: s__('Runners|Download Latest Binary'), downloadLatestBinary: s__('Runners|Download Latest Binary'),
registerRunner: s__('Runners|Register Runner'), registerRunner: s__('Runners|Register Runner'),
method: __('Method'), method: __('Method'),
genericError: __('An error has occurred'), fetchError: s__('An error has occurred fetching instructions'),
instructions: __('Show Runner installation instructions'), instructions: __('Show Runner installation instructions'),
}, },
closeButton: {
text: __('Close'),
attributes: [{ variant: 'default' }],
},
}; };
</script> </script>
<template> <template>
...@@ -173,10 +130,10 @@ export default { ...@@ -173,10 +130,10 @@ export default {
<gl-modal <gl-modal
:modal-id="$options.modalId" :modal-id="$options.modalId"
:title="$options.i18n.installARunner" :title="$options.i18n.installARunner"
:action-secondary="closeButton" :action-secondary="$options.closeButton"
> >
<gl-alert v-if="showAlert" variant="danger" @dismiss="toggleAlert(false)"> <gl-alert v-if="showAlert" variant="danger" @dismiss="toggleAlert(false)">
{{ $options.i18n.genericError }} {{ $options.i18n.fetchError }}
</gl-alert> </gl-alert>
<h5>{{ __('Environment') }}</h5> <h5>{{ __('Environment') }}</h5>
<gl-button-group class="gl-mb-5"> <gl-button-group class="gl-mb-5">
...@@ -198,7 +155,7 @@ export default { ...@@ -198,7 +155,7 @@ export default {
v-for="architecture in selectedPlatformArchitectures" v-for="architecture in selectedPlatformArchitectures"
:key="architecture.name" :key="architecture.name"
data-testid="architecture-dropdown-item" data-testid="architecture-dropdown-item"
@click="selectArchitecture(architecture.name)" @click="selectArchitecture(architecture)"
> >
{{ architecture.name }} {{ architecture.name }}
</gl-dropdown-item> </gl-dropdown-item>
......
...@@ -2810,6 +2810,9 @@ msgstr "" ...@@ -2810,6 +2810,9 @@ msgstr ""
msgid "An error has occurred" msgid "An error has occurred"
msgstr "" msgstr ""
msgid "An error has occurred fetching instructions"
msgstr ""
msgid "An error occured while making the changes: %{error}" msgid "An error occured while making the changes: %{error}"
msgstr "" msgstr ""
...@@ -3418,9 +3421,6 @@ msgstr "" ...@@ -3418,9 +3421,6 @@ msgstr ""
msgid "April" msgid "April"
msgstr "" msgstr ""
msgid "Architecture"
msgstr ""
msgid "Architecture not found for OS" msgid "Architecture not found for OS"
msgstr "" msgstr ""
......
...@@ -89,6 +89,8 @@ export const mockGraphqlRunnerPlatforms = { ...@@ -89,6 +89,8 @@ export const mockGraphqlRunnerPlatforms = {
], ],
__typename: 'RunnerPlatformConnection', __typename: 'RunnerPlatformConnection',
}, },
project: { id: 'gid://gitlab/Project/1', __typename: 'Project' },
group: null,
}, },
}; };
...@@ -103,17 +105,3 @@ export const mockGraphqlInstructions = { ...@@ -103,17 +105,3 @@ export const mockGraphqlInstructions = {
}, },
}, },
}; };
export const mockGraphqlProjectId = {
data: {
project: {
id: 'gid://gitlab/Project/1',
},
},
};
export const mockGraphqlGroupId = {
data: {
group: null,
},
};
...@@ -3,16 +3,9 @@ import VueApollo from 'vue-apollo'; ...@@ -3,16 +3,9 @@ import VueApollo from 'vue-apollo';
import createMockApollo from 'jest/helpers/mock_apollo_helper'; import createMockApollo from 'jest/helpers/mock_apollo_helper';
import RunnerInstructions from '~/vue_shared/components/runner_instructions/runner_instructions.vue'; import RunnerInstructions from '~/vue_shared/components/runner_instructions/runner_instructions.vue';
import getRunnerPlatforms from '~/vue_shared/components/runner_instructions/graphql/queries/get_runner_platforms.query.graphql'; import getRunnerPlatforms from '~/vue_shared/components/runner_instructions/graphql/queries/get_runner_platforms.query.graphql';
import getProjectId from '~/vue_shared/components/runner_instructions/graphql/queries/get_project_id.query.graphql';
import getGroupId from '~/vue_shared/components/runner_instructions/graphql/queries/get_group_id.query.graphql';
import getRunnerSetupInstructions from '~/vue_shared/components/runner_instructions/graphql/queries/get_runner_setup.query.graphql'; import getRunnerSetupInstructions from '~/vue_shared/components/runner_instructions/graphql/queries/get_runner_setup.query.graphql';
import { import { mockGraphqlRunnerPlatforms, mockGraphqlInstructions } from './mock_data';
mockGraphqlRunnerPlatforms,
mockGraphqlProjectId,
mockGraphqlInstructions,
mockGraphqlGroupId,
} from './mock_data';
const projectPath = 'gitlab-org/gitlab'; const projectPath = 'gitlab-org/gitlab';
const localVue = createLocalVue(); const localVue = createLocalVue();
...@@ -33,8 +26,6 @@ describe('RunnerInstructions component', () => { ...@@ -33,8 +26,6 @@ describe('RunnerInstructions component', () => {
const requestHandlers = [ const requestHandlers = [
[getRunnerPlatforms, jest.fn().mockResolvedValue(mockGraphqlRunnerPlatforms)], [getRunnerPlatforms, jest.fn().mockResolvedValue(mockGraphqlRunnerPlatforms)],
[getRunnerSetupInstructions, jest.fn().mockResolvedValue(mockGraphqlInstructions)], [getRunnerSetupInstructions, jest.fn().mockResolvedValue(mockGraphqlInstructions)],
[getProjectId, jest.fn().mockResolvedValue(mockGraphqlProjectId)],
[getGroupId, jest.fn().mockResolvedValue(mockGraphqlGroupId)],
]; ];
fakeApollo = createMockApollo(requestHandlers); fakeApollo = createMockApollo(requestHandlers);
......
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