Commit 574ce362 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '337177-geo-relative-urls' into 'master'

Geo Node Form Regression - Relative URLs broken

See merge request gitlab-org/gitlab!67253
parents 1e4d2527 99a11efd
<script> <script>
import { GlButton } from '@gitlab/ui'; import { GlButton } from '@gitlab/ui';
import { mapActions, mapGetters } from 'vuex'; import { mapActions, mapGetters, mapState } from 'vuex';
import { visitUrl } from '~/lib/utils/url_utility'; import { visitUrl } from '~/lib/utils/url_utility';
import GeoNodeFormCapacities from './geo_node_form_capacities.vue'; import GeoNodeFormCapacities from './geo_node_form_capacities.vue';
import GeoNodeFormCore from './geo_node_form_core.vue'; import GeoNodeFormCore from './geo_node_form_core.vue';
...@@ -50,6 +50,7 @@ export default { ...@@ -50,6 +50,7 @@ export default {
}, },
computed: { computed: {
...mapGetters(['formHasError']), ...mapGetters(['formHasError']),
...mapState(['nodesPath']),
}, },
created() { created() {
if (this.node) { if (this.node) {
...@@ -59,7 +60,7 @@ export default { ...@@ -59,7 +60,7 @@ export default {
methods: { methods: {
...mapActions(['saveGeoNode']), ...mapActions(['saveGeoNode']),
redirect() { redirect() {
visitUrl('/admin/geo/nodes'); visitUrl(this.nodesPath);
}, },
addSyncOption({ key, value }) { addSyncOption({ key, value }) {
this.nodeData[key].push(value); this.nodeData[key].push(value);
......
...@@ -9,17 +9,17 @@ Vue.use(Translate); ...@@ -9,17 +9,17 @@ Vue.use(Translate);
export default () => { export default () => {
const el = document.getElementById('js-geo-node-form'); const el = document.getElementById('js-geo-node-form');
const {
dataset: { selectiveSyncTypes, syncShardsOptions, nodeData, nodesPath },
} = el;
return new Vue({ return new Vue({
el, el,
store: createStore(), store: createStore(nodesPath),
components: { components: {
GeoNodeFormApp, GeoNodeFormApp,
}, },
render(createElement) { render(createElement) {
const {
dataset: { selectiveSyncTypes, syncShardsOptions, nodeData },
} = this.$options.el;
let node; let node;
if (nodeData) { if (nodeData) {
node = JSON.parse(nodeData); node = JSON.parse(nodeData);
......
...@@ -40,9 +40,9 @@ export const fetchSyncNamespaces = ({ dispatch }, search) => { ...@@ -40,9 +40,9 @@ export const fetchSyncNamespaces = ({ dispatch }, search) => {
}; };
export const requestSaveGeoNode = ({ commit }) => commit(types.REQUEST_SAVE_GEO_NODE); export const requestSaveGeoNode = ({ commit }) => commit(types.REQUEST_SAVE_GEO_NODE);
export const receiveSaveGeoNodeSuccess = ({ commit }) => { export const receiveSaveGeoNodeSuccess = ({ commit, state }) => {
commit(types.RECEIVE_SAVE_GEO_NODE_COMPLETE); commit(types.RECEIVE_SAVE_GEO_NODE_COMPLETE);
visitUrl('/admin/geo/nodes'); visitUrl(state.nodesPath);
}; };
export const receiveSaveGeoNodeError = ({ commit }, data) => { export const receiveSaveGeoNodeError = ({ commit }, data) => {
let errorMessage = __('There was an error saving this Geo Node.'); let errorMessage = __('There was an error saving this Geo Node.');
......
...@@ -7,11 +7,11 @@ import createState from './state'; ...@@ -7,11 +7,11 @@ import createState from './state';
Vue.use(Vuex); Vue.use(Vuex);
const createStore = () => const createStore = (nodesPath) =>
new Vuex.Store({ new Vuex.Store({
actions, actions,
mutations, mutations,
getters, getters,
state: createState(), state: createState(nodesPath),
}); });
export default createStore; export default createStore;
import { VALIDATION_FIELD_KEYS } from '../constants'; import { VALIDATION_FIELD_KEYS } from '../constants';
const createState = () => ({ const createState = (nodesPath) => ({
nodesPath,
isLoading: false, isLoading: false,
synchronizationNamespaces: [], synchronizationNamespaces: [],
formErrors: Object.values(VALIDATION_FIELD_KEYS).reduce( formErrors: Object.values(VALIDATION_FIELD_KEYS).reduce(
......
...@@ -14,7 +14,7 @@ export default { ...@@ -14,7 +14,7 @@ export default {
GlButton, GlButton,
}, },
computed: { computed: {
...mapState(['formErrors']), ...mapState(['formErrors', 'nodesPath']),
...mapGetters(['formHasError']), ...mapGetters(['formHasError']),
...mapComputed([ ...mapComputed([
{ key: 'timeout', updateFn: 'setTimeout' }, { key: 'timeout', updateFn: 'setTimeout' },
...@@ -24,7 +24,7 @@ export default { ...@@ -24,7 +24,7 @@ export default {
methods: { methods: {
...mapActions(['updateGeoSettings', 'setFormError']), ...mapActions(['updateGeoSettings', 'setFormError']),
redirect() { redirect() {
visitUrl('/admin/geo/nodes'); visitUrl(this.nodesPath);
}, },
checkTimeout() { checkTimeout() {
this.setFormError({ this.setFormError({
......
...@@ -8,9 +8,13 @@ Vue.use(Translate); ...@@ -8,9 +8,13 @@ Vue.use(Translate);
export default () => { export default () => {
const el = document.getElementById('js-geo-settings-form'); const el = document.getElementById('js-geo-settings-form');
const {
dataset: { nodesPath },
} = el;
return new Vue({ return new Vue({
el, el,
store: createStore(), store: createStore(nodesPath),
components: { components: {
GeoSettingsApp, GeoSettingsApp,
}, },
......
...@@ -7,10 +7,10 @@ import createState from './state'; ...@@ -7,10 +7,10 @@ import createState from './state';
Vue.use(Vuex); Vue.use(Vuex);
export default () => export default (nodesPath) =>
new Vuex.Store({ new Vuex.Store({
actions, actions,
mutations, mutations,
getters, getters,
state: createState(), state: createState(nodesPath),
}); });
import { DEFAULT_TIMEOUT, DEFAULT_ALLOWED_IP, FORM_VALIDATION_FIELDS } from '../constants'; import { DEFAULT_TIMEOUT, DEFAULT_ALLOWED_IP, FORM_VALIDATION_FIELDS } from '../constants';
export default () => ({ export default (nodesPath) => ({
nodesPath,
isLoading: false, isLoading: false,
timeout: DEFAULT_TIMEOUT, timeout: DEFAULT_TIMEOUT,
allowedIp: DEFAULT_ALLOWED_IP, allowedIp: DEFAULT_ALLOWED_IP,
......
...@@ -3,4 +3,5 @@ ...@@ -3,4 +3,5 @@
#js-geo-node-form{ data: { "selective-sync-types" => selective_sync_types_json, #js-geo-node-form{ data: { "selective-sync-types" => selective_sync_types_json,
"sync-shards-options" => repository_storages_options_json, "sync-shards-options" => repository_storages_options_json,
"node-data" => @serialized_node } } "node-data" => @serialized_node,
"nodes-path" => admin_geo_nodes_path } }
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
= render partial: 'admin/geo/shared/license_alert' = render partial: 'admin/geo/shared/license_alert'
- if Gitlab::Geo.license_allows? - if Gitlab::Geo.license_allows?
#js-geo-settings-form #js-geo-settings-form{ data: { "nodes-path" => admin_geo_nodes_path } }
- else - else
= render 'shared/empty_states/geo' = render 'shared/empty_states/geo'
...@@ -4,9 +4,14 @@ import GeoNodeForm from 'ee/geo_node_form/components/geo_node_form.vue'; ...@@ -4,9 +4,14 @@ import GeoNodeForm from 'ee/geo_node_form/components/geo_node_form.vue';
import GeoNodeFormCapacities from 'ee/geo_node_form/components/geo_node_form_capacities.vue'; import GeoNodeFormCapacities from 'ee/geo_node_form/components/geo_node_form_capacities.vue';
import GeoNodeFormCore from 'ee/geo_node_form/components/geo_node_form_core.vue'; import GeoNodeFormCore from 'ee/geo_node_form/components/geo_node_form_core.vue';
import GeoNodeFormSelectiveSync from 'ee/geo_node_form/components/geo_node_form_selective_sync.vue'; import GeoNodeFormSelectiveSync from 'ee/geo_node_form/components/geo_node_form_selective_sync.vue';
import store from 'ee/geo_node_form/store'; import initStore from 'ee/geo_node_form/store';
import { visitUrl } from '~/lib/utils/url_utility'; import { visitUrl } from '~/lib/utils/url_utility';
import { MOCK_NODE, MOCK_SELECTIVE_SYNC_TYPES, MOCK_SYNC_SHARDS } from '../mock_data'; import {
MOCK_NODE,
MOCK_SELECTIVE_SYNC_TYPES,
MOCK_SYNC_SHARDS,
MOCK_NODES_PATH,
} from '../mock_data';
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
...@@ -26,7 +31,7 @@ describe('GeoNodeForm', () => { ...@@ -26,7 +31,7 @@ describe('GeoNodeForm', () => {
const createComponent = () => { const createComponent = () => {
wrapper = shallowMount(GeoNodeForm, { wrapper = shallowMount(GeoNodeForm, {
store, store: initStore(MOCK_NODES_PATH),
propsData, propsData,
}); });
}; };
...@@ -109,7 +114,7 @@ describe('GeoNodeForm', () => { ...@@ -109,7 +114,7 @@ describe('GeoNodeForm', () => {
it('calls visitUrl when cancel is clicked', () => { it('calls visitUrl when cancel is clicked', () => {
findGeoNodeCancelButton().vm.$emit('click'); findGeoNodeCancelButton().vm.$emit('click');
expect(visitUrl).toHaveBeenCalledWith('/admin/geo/nodes'); expect(visitUrl).toHaveBeenCalledWith(MOCK_NODES_PATH);
}); });
}); });
......
...@@ -67,3 +67,5 @@ export const MOCK_ERROR_MESSAGE = { ...@@ -67,3 +67,5 @@ export const MOCK_ERROR_MESSAGE = {
name: ["can't be blank"], name: ["can't be blank"],
url: ["can't be blank", 'must be a valid URL'], url: ["can't be blank", 'must be a valid URL'],
}; };
export const MOCK_NODES_PATH = 'gitlab/admin/geo/nodes';
...@@ -6,7 +6,7 @@ import testAction from 'helpers/vuex_action_helper'; ...@@ -6,7 +6,7 @@ import testAction from 'helpers/vuex_action_helper';
import createFlash from '~/flash'; import createFlash from '~/flash';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import { visitUrl } from '~/lib/utils/url_utility'; import { visitUrl } from '~/lib/utils/url_utility';
import { MOCK_SYNC_NAMESPACES, MOCK_NODE, MOCK_ERROR_MESSAGE } from '../mock_data'; import { MOCK_SYNC_NAMESPACES, MOCK_NODE, MOCK_ERROR_MESSAGE, MOCK_NODES_PATH } from '../mock_data';
jest.mock('~/flash'); jest.mock('~/flash');
jest.mock('~/lib/utils/url_utility', () => ({ jest.mock('~/lib/utils/url_utility', () => ({
...@@ -24,11 +24,11 @@ describe('GeoNodeForm Store Actions', () => { ...@@ -24,11 +24,11 @@ describe('GeoNodeForm Store Actions', () => {
createFlash.mockClear(); createFlash.mockClear();
}; };
const visitUrlCallback = () => { const visitUrlCallback = () => {
expect(visitUrl).toHaveBeenCalledWith('/admin/geo/nodes'); expect(visitUrl).toHaveBeenCalledWith(MOCK_NODES_PATH);
}; };
beforeEach(() => { beforeEach(() => {
state = createState(); state = createState(MOCK_NODES_PATH);
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
}); });
......
...@@ -4,7 +4,7 @@ import GeoSettingsForm from 'ee/geo_settings/components/geo_settings_form.vue'; ...@@ -4,7 +4,7 @@ import GeoSettingsForm from 'ee/geo_settings/components/geo_settings_form.vue';
import initStore from 'ee/geo_settings/store'; import initStore from 'ee/geo_settings/store';
import * as types from 'ee/geo_settings/store/mutation_types'; import * as types from 'ee/geo_settings/store/mutation_types';
import { visitUrl } from '~/lib/utils/url_utility'; import { visitUrl } from '~/lib/utils/url_utility';
import { STRING_OVER_255 } from '../mock_data'; import { STRING_OVER_255, MOCK_NODES_PATH } from '../mock_data';
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
...@@ -18,7 +18,7 @@ describe('GeoSettingsForm', () => { ...@@ -18,7 +18,7 @@ describe('GeoSettingsForm', () => {
let store; let store;
const createStore = () => { const createStore = () => {
store = initStore(); store = initStore(MOCK_NODES_PATH);
}; };
const createComponent = () => { const createComponent = () => {
...@@ -90,7 +90,7 @@ describe('GeoSettingsForm', () => { ...@@ -90,7 +90,7 @@ describe('GeoSettingsForm', () => {
describe('cancel button', () => { describe('cancel button', () => {
it('calls visitUrl when clicked', () => { it('calls visitUrl when clicked', () => {
findGeoSettingsCancelButton().vm.$emit('click'); findGeoSettingsCancelButton().vm.$emit('click');
expect(visitUrl).toHaveBeenCalledWith('/admin/geo/nodes'); expect(visitUrl).toHaveBeenCalledWith(MOCK_NODES_PATH);
}); });
}); });
}); });
......
...@@ -9,3 +9,5 @@ export const MOCK_BASIC_SETTINGS_DATA = { ...@@ -9,3 +9,5 @@ export const MOCK_BASIC_SETTINGS_DATA = {
}; };
export const STRING_OVER_255 = new Array(257).join('a'); export const STRING_OVER_255 = new Array(257).join('a');
export const MOCK_NODES_PATH = 'gitlab/admin/geo/nodes';
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