Commit 6e7d4f4d authored by Paul Slaughter's avatar Paul Slaughter

Merge branch '351626-follow-up-clean-up-group-wrapping-for-namespace-select' into 'master'

Follow-up: clean up prop wrapping for namespace select

See merge request gitlab-org/gitlab!79730
parents 3910b0bc 31fdc52f
...@@ -20,8 +20,8 @@ export default { ...@@ -20,8 +20,8 @@ export default {
NamespaceSelect, NamespaceSelect,
}, },
props: { props: {
parentGroups: { groupNamespaces: {
type: Object, type: Array,
required: true, required: true,
}, },
isPaidGroup: { isPaidGroup: {
...@@ -60,7 +60,7 @@ export default { ...@@ -60,7 +60,7 @@ export default {
<gl-form-group v-if="!isPaidGroup"> <gl-form-group v-if="!isPaidGroup">
<namespace-select <namespace-select
:default-text="$options.i18n.dropdownTitle" :default-text="$options.i18n.dropdownTitle"
:data="parentGroups" :group-namespaces="groupNamespaces"
:empty-namespace-title="$options.i18n.emptyNamespaceTitle" :empty-namespace-title="$options.i18n.emptyNamespaceTitle"
:include-headers="false" :include-headers="false"
include-empty-namespace include-empty-namespace
......
...@@ -5,15 +5,13 @@ import TransferGroupForm, { i18n } from './components/transfer_group_form.vue'; ...@@ -5,15 +5,13 @@ import TransferGroupForm, { i18n } from './components/transfer_group_form.vue';
const prepareGroups = (rawGroups) => { const prepareGroups = (rawGroups) => {
if (!rawGroups) { if (!rawGroups) {
return { group: [] }; return [];
} }
const group = JSON.parse(rawGroups).map(({ id, text: humanName }) => ({ return JSON.parse(rawGroups).map(({ id, text: humanName }) => ({
id, id,
humanName, humanName,
})); }));
return { group };
}; };
export default () => { export default () => {
...@@ -38,7 +36,7 @@ export default () => { ...@@ -38,7 +36,7 @@ export default () => {
render(createElement) { render(createElement) {
return createElement(TransferGroupForm, { return createElement(TransferGroupForm, {
props: { props: {
parentGroups: prepareGroups(parentGroups), groupNamespaces: prepareGroups(parentGroups),
isPaidGroup: parseBoolean(isPaidGroup), isPaidGroup: parseBoolean(isPaidGroup),
confirmButtonText, confirmButtonText,
confirmationPhrase: groupName, confirmationPhrase: groupName,
......
...@@ -11,8 +11,12 @@ export default { ...@@ -11,8 +11,12 @@ export default {
ConfirmDanger, ConfirmDanger,
}, },
props: { props: {
namespaces: { groupNamespaces: {
type: Object, type: Array,
required: true,
},
userNamespaces: {
type: Array,
required: true, required: true,
}, },
confirmationPhrase: { confirmationPhrase: {
...@@ -46,7 +50,8 @@ export default { ...@@ -46,7 +50,8 @@ export default {
<namespace-select <namespace-select
data-testid="transfer-project-namespace" data-testid="transfer-project-namespace"
:full-width="true" :full-width="true"
:data="namespaces" :group-namespaces="groupNamespaces"
:user-namespaces="userNamespaces"
:selected-namespace="selectedNamespace" :selected-namespace="selectedNamespace"
@select="handleSelect" @select="handleSelect"
/> />
......
...@@ -3,10 +3,14 @@ import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils'; ...@@ -3,10 +3,14 @@ import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import TransferProjectForm from './components/transfer_project_form.vue'; import TransferProjectForm from './components/transfer_project_form.vue';
const prepareNamespaces = (rawNamespaces = '') => { const prepareNamespaces = (rawNamespaces = '') => {
if (!rawNamespaces) {
return { groupNamespaces: [], userNamespaces: [] };
}
const data = JSON.parse(rawNamespaces); const data = JSON.parse(rawNamespaces);
return { return {
group: data?.group.map(convertObjectPropsToCamelCase), groupNamespaces: data?.group?.map(convertObjectPropsToCamelCase) || [],
user: data?.user.map(convertObjectPropsToCamelCase), userNamespaces: data?.user?.map(convertObjectPropsToCamelCase) || [],
}; };
}; };
...@@ -35,7 +39,7 @@ export default () => { ...@@ -35,7 +39,7 @@ export default () => {
props: { props: {
confirmButtonText, confirmButtonText,
confirmationPhrase, confirmationPhrase,
namespaces: prepareNamespaces(namespaces), ...prepareNamespaces(namespaces),
}, },
on: { on: {
selectNamespace: (id) => { selectNamespace: (id) => {
......
...@@ -34,9 +34,15 @@ export default { ...@@ -34,9 +34,15 @@ export default {
GlSearchBoxByType, GlSearchBoxByType,
}, },
props: { props: {
data: { groupNamespaces: {
type: Object, type: Array,
required: true, required: false,
default: () => [],
},
userNamespaces: {
type: Array,
required: false,
default: () => [],
}, },
fullWidth: { fullWidth: {
type: Boolean, type: Boolean,
...@@ -72,18 +78,18 @@ export default { ...@@ -72,18 +78,18 @@ export default {
}, },
computed: { computed: {
hasUserNamespaces() { hasUserNamespaces() {
return this.data.user?.length; return this.userNamespaces.length;
}, },
hasGroupNamespaces() { hasGroupNamespaces() {
return this.data.group?.length; return this.groupNamespaces.length;
}, },
filteredGroupNamespaces() { filteredGroupNamespaces() {
if (!this.hasGroupNamespaces) return []; if (!this.hasGroupNamespaces) return [];
return filterByName(this.data.group, this.searchTerm); return filterByName(this.groupNamespaces, this.searchTerm);
}, },
filteredUserNamespaces() { filteredUserNamespaces() {
if (!this.hasUserNamespaces) return []; if (!this.hasUserNamespaces) return [];
return filterByName(this.data.user, this.searchTerm); return filterByName(this.userNamespaces, this.searchTerm);
}, },
selectedNamespaceText() { selectedNamespaceText() {
return this.selectedNamespace?.humanName || this.defaultText; return this.selectedNamespace?.humanName || this.defaultText;
......
...@@ -10,7 +10,7 @@ describe('Transfer group form', () => { ...@@ -10,7 +10,7 @@ describe('Transfer group form', () => {
const confirmButtonText = 'confirm'; const confirmButtonText = 'confirm';
const confirmationPhrase = 'confirmation-phrase'; const confirmationPhrase = 'confirmation-phrase';
const paidGroupHelpLink = 'some/fake/link'; const paidGroupHelpLink = 'some/fake/link';
const groups = [ const groupNamespaces = [
{ {
id: 1, id: 1,
humanName: 'Group 1', humanName: 'Group 1',
...@@ -22,7 +22,7 @@ describe('Transfer group form', () => { ...@@ -22,7 +22,7 @@ describe('Transfer group form', () => {
]; ];
const defaultProps = { const defaultProps = {
parentGroups: { groups }, groupNamespaces,
paidGroupHelpLink, paidGroupHelpLink,
isPaidGroup: false, isPaidGroup: false,
confirmationPhrase, confirmationPhrase,
...@@ -63,7 +63,7 @@ describe('Transfer group form', () => { ...@@ -63,7 +63,7 @@ describe('Transfer group form', () => {
includeHeaders: false, includeHeaders: false,
emptyNamespaceTitle: 'No parent group', emptyNamespaceTitle: 'No parent group',
includeEmptyNamespace: true, includeEmptyNamespace: true,
data: { groups }, groupNamespaces,
}); });
}); });
...@@ -91,7 +91,7 @@ describe('Transfer group form', () => { ...@@ -91,7 +91,7 @@ describe('Transfer group form', () => {
}); });
describe('with a selected project', () => { describe('with a selected project', () => {
const [firstGroup] = groups; const [firstGroup] = groupNamespaces;
beforeEach(() => { beforeEach(() => {
wrapper = createComponent(); wrapper = createComponent();
findNamespaceSelect().vm.$emit('select', firstGroup); findNamespaceSelect().vm.$emit('select', firstGroup);
......
import { namespaces } from 'jest/vue_shared/components/namespace_select/mock_data'; import {
groupNamespaces,
userNamespaces,
} from 'jest/vue_shared/components/namespace_select/mock_data';
import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper';
import TransferProjectForm from '~/projects/settings/components/transfer_project_form.vue'; import TransferProjectForm from '~/projects/settings/components/transfer_project_form.vue';
import NamespaceSelect from '~/vue_shared/components/namespace_select/namespace_select.vue'; import NamespaceSelect from '~/vue_shared/components/namespace_select/namespace_select.vue';
...@@ -13,7 +16,8 @@ describe('Transfer project form', () => { ...@@ -13,7 +16,8 @@ describe('Transfer project form', () => {
const createComponent = () => const createComponent = () =>
shallowMountExtended(TransferProjectForm, { shallowMountExtended(TransferProjectForm, {
propsData: { propsData: {
namespaces, userNamespaces,
groupNamespaces,
confirmButtonText, confirmButtonText,
confirmationPhrase, confirmationPhrase,
}, },
...@@ -43,7 +47,7 @@ describe('Transfer project form', () => { ...@@ -43,7 +47,7 @@ describe('Transfer project form', () => {
}); });
describe('with a selected namespace', () => { describe('with a selected namespace', () => {
const [selectedItem] = namespaces.group; const [selectedItem] = groupNamespaces;
beforeEach(() => { beforeEach(() => {
findNamespaceSelect().vm.$emit('select', selectedItem); findNamespaceSelect().vm.$emit('select', selectedItem);
......
export const group = [ export const groupNamespaces = [
{ id: 1, name: 'Group 1', humanName: 'Group 1' }, { id: 1, name: 'Group 1', humanName: 'Group 1' },
{ id: 2, name: 'Subgroup 1', humanName: 'Group 1 / Subgroup 1' }, { id: 2, name: 'Subgroup 1', humanName: 'Group 1 / Subgroup 1' },
]; ];
export const user = [{ id: 3, name: 'User namespace 1', humanName: 'User namespace 1' }]; export const userNamespaces = [{ id: 3, name: 'User namespace 1', humanName: 'User namespace 1' }];
export const namespaces = {
group,
user,
};
...@@ -5,9 +5,9 @@ import NamespaceSelect, { ...@@ -5,9 +5,9 @@ import NamespaceSelect, {
i18n, i18n,
EMPTY_NAMESPACE_ID, EMPTY_NAMESPACE_ID,
} from '~/vue_shared/components/namespace_select/namespace_select.vue'; } from '~/vue_shared/components/namespace_select/namespace_select.vue';
import { user, group, namespaces } from './mock_data'; import { userNamespaces, groupNamespaces } from './mock_data';
const FLAT_NAMESPACES = [...group, ...user]; const FLAT_NAMESPACES = [...groupNamespaces, ...userNamespaces];
const EMPTY_NAMESPACE_TITLE = 'Empty namespace TEST'; const EMPTY_NAMESPACE_TITLE = 'Empty namespace TEST';
const EMPTY_NAMESPACE_ITEM = { id: EMPTY_NAMESPACE_ID, humanName: EMPTY_NAMESPACE_TITLE }; const EMPTY_NAMESPACE_ITEM = { id: EMPTY_NAMESPACE_ID, humanName: EMPTY_NAMESPACE_TITLE };
...@@ -17,7 +17,8 @@ describe('Namespace Select', () => { ...@@ -17,7 +17,8 @@ describe('Namespace Select', () => {
const createComponent = (props = {}) => const createComponent = (props = {}) =>
shallowMountExtended(NamespaceSelect, { shallowMountExtended(NamespaceSelect, {
propsData: { propsData: {
data: namespaces, userNamespaces,
groupNamespaces,
...props, ...props,
}, },
stubs: { stubs: {
...@@ -89,11 +90,11 @@ describe('Namespace Select', () => { ...@@ -89,11 +90,11 @@ describe('Namespace Select', () => {
describe('with search', () => { describe('with search', () => {
it.each` it.each`
term | includeEmptyNamespace | expectedItems term | includeEmptyNamespace | expectedItems
${''} | ${false} | ${[...namespaces.group, ...namespaces.user]} ${''} | ${false} | ${[...groupNamespaces, ...userNamespaces]}
${'sub'} | ${false} | ${[namespaces.group[1]]} ${'sub'} | ${false} | ${[groupNamespaces[1]]}
${'User'} | ${false} | ${[...namespaces.user]} ${'User'} | ${false} | ${[...userNamespaces]}
${'User'} | ${true} | ${[...namespaces.user]} ${'User'} | ${true} | ${[...userNamespaces]}
${'namespace'} | ${true} | ${[EMPTY_NAMESPACE_ITEM, ...namespaces.user]} ${'namespace'} | ${true} | ${[EMPTY_NAMESPACE_ITEM, ...userNamespaces]}
`( `(
'with term=$term and includeEmptyNamespace=$includeEmptyNamespace, should show $expectedItems.length', 'with term=$term and includeEmptyNamespace=$includeEmptyNamespace, should show $expectedItems.length',
async ({ term, includeEmptyNamespace, expectedItems }) => { async ({ term, includeEmptyNamespace, expectedItems }) => {
...@@ -115,7 +116,7 @@ describe('Namespace Select', () => { ...@@ -115,7 +116,7 @@ describe('Namespace Select', () => {
describe('with a selected namespace', () => { describe('with a selected namespace', () => {
const selectedGroupIndex = 1; const selectedGroupIndex = 1;
const selectedItem = group[selectedGroupIndex]; const selectedItem = groupNamespaces[selectedGroupIndex];
beforeEach(() => { beforeEach(() => {
wrapper = createComponent(); wrapper = createComponent();
......
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