2021-03-11 19:13:27 +05:30
|
|
|
import { GlToast } from '@gitlab/ui';
|
2020-11-24 15:15:51 +05:30
|
|
|
import Vue from 'vue';
|
|
|
|
import Vuex from 'vuex';
|
2021-06-08 01:23:25 +05:30
|
|
|
import { parseDataAttributes } from '~/members/utils';
|
2021-09-04 01:27:46 +05:30
|
|
|
import MembersTabs from './components/members_tabs.vue';
|
|
|
|
import { MEMBER_TYPES } from './constants';
|
2021-03-11 19:13:27 +05:30
|
|
|
import membersStore from './store';
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
export const initMembersApp = (el, options) => {
|
2020-11-24 15:15:51 +05:30
|
|
|
if (!el) {
|
|
|
|
return () => {};
|
|
|
|
}
|
|
|
|
|
|
|
|
Vue.use(Vuex);
|
2021-01-03 14:25:43 +05:30
|
|
|
Vue.use(GlToast);
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-10-27 15:23:28 +05:30
|
|
|
const {
|
|
|
|
sourceId,
|
|
|
|
canManageMembers,
|
|
|
|
canExportMembers,
|
|
|
|
exportCsvPath,
|
|
|
|
...vuexStoreAttributes
|
|
|
|
} = parseDataAttributes(el);
|
2021-04-29 21:17:54 +05:30
|
|
|
|
2021-09-04 01:27:46 +05:30
|
|
|
const modules = Object.keys(MEMBER_TYPES).reduce((accumulator, namespace) => {
|
|
|
|
const namespacedOptions = options[namespace];
|
|
|
|
|
|
|
|
if (!namespacedOptions) {
|
|
|
|
return accumulator;
|
|
|
|
}
|
|
|
|
|
|
|
|
const {
|
|
|
|
tableFields = [],
|
|
|
|
tableAttrs = {},
|
|
|
|
tableSortableFields = [],
|
|
|
|
requestFormatter = () => {},
|
|
|
|
filteredSearchBar = { show: false },
|
|
|
|
} = namespacedOptions;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...accumulator,
|
2021-04-29 21:17:54 +05:30
|
|
|
[namespace]: membersStore({
|
2021-09-04 01:27:46 +05:30
|
|
|
...vuexStoreAttributes[namespace],
|
2021-04-29 21:17:54 +05:30
|
|
|
tableFields,
|
|
|
|
tableAttrs,
|
|
|
|
tableSortableFields,
|
|
|
|
requestFormatter,
|
|
|
|
filteredSearchBar,
|
|
|
|
}),
|
2021-09-04 01:27:46 +05:30
|
|
|
};
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
const store = new Vuex.Store({ modules });
|
2020-11-24 15:15:51 +05:30
|
|
|
|
|
|
|
return new Vue({
|
|
|
|
el,
|
2021-09-04 01:27:46 +05:30
|
|
|
components: { MembersTabs },
|
2020-11-24 15:15:51 +05:30
|
|
|
store,
|
2021-04-29 21:17:54 +05:30
|
|
|
provide: {
|
|
|
|
currentUserId: gon.current_user_id || null,
|
|
|
|
sourceId,
|
|
|
|
canManageMembers,
|
2021-10-27 15:23:28 +05:30
|
|
|
canExportMembers,
|
|
|
|
exportCsvPath,
|
2021-04-29 21:17:54 +05:30
|
|
|
},
|
2021-09-04 01:27:46 +05:30
|
|
|
render: (createElement) => createElement('members-tabs'),
|
2020-11-24 15:15:51 +05:30
|
|
|
});
|
|
|
|
};
|