Commit bc474e19 authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Merge branch '326354-members_table-vue-refactor-dynamically-called-methods' into 'master'

Refactor dynamically called methods to be more explicit

See merge request gitlab-org/gitlab!78141
parents 232c173b d7ed4cf4
...@@ -6,6 +6,7 @@ import { canOverride, canRemove, canResend, canUpdate } from 'ee_else_ce/members ...@@ -6,6 +6,7 @@ import { canOverride, canRemove, canResend, canUpdate } from 'ee_else_ce/members
import { mergeUrlParams } from '~/lib/utils/url_utility'; import { mergeUrlParams } from '~/lib/utils/url_utility';
import initUserPopovers from '~/user_popovers'; import initUserPopovers from '~/user_popovers';
import { import {
FIELD_KEY_ACTIONS,
FIELDS, FIELDS,
ACTIVE_TAB_QUERY_PARAM_NAME, ACTIVE_TAB_QUERY_PARAM_NAME,
TAB_QUERY_PARAM_VALUES, TAB_QUERY_PARAM_VALUES,
...@@ -63,17 +64,10 @@ export default { ...@@ -63,17 +64,10 @@ export default {
return state[this.namespace].pagination; return state[this.namespace].pagination;
}, },
}), }),
filteredFields() { filteredAndModifiedFields() {
return FIELDS.filter( return FIELDS.filter(
(field) => this.tableFields.includes(field.key) && this.showField(field), (field) => this.tableFields.includes(field.key) && this.showField(field),
).map((field) => { ).map(this.modifyFieldDefinition);
const tdClassFunction = this[field.tdClassFunction];
return {
...field,
...(tdClassFunction && { tdClass: tdClassFunction }),
};
});
}, },
userIsLoggedIn() { userIsLoggedIn() {
return this.currentUserId !== null; return this.currentUserId !== null;
...@@ -100,20 +94,29 @@ export default { ...@@ -100,20 +94,29 @@ export default {
); );
}, },
showField(field) { showField(field) {
if (!Object.prototype.hasOwnProperty.call(field, 'showFunction')) { switch (field.key) {
return true; case FIELD_KEY_ACTIONS:
}
return this[field.showFunction]();
},
showActionsField() {
if (!this.userIsLoggedIn) { if (!this.userIsLoggedIn) {
return false; return false;
} }
return this.members.some((member) => this.hasActionButtons(member)); return this.members.some((member) => this.hasActionButtons(member));
default:
return true;
}
},
modifyFieldDefinition(field) {
switch (field.key) {
case FIELD_KEY_ACTIONS:
return {
...field,
tdClass: this.actionsFieldTdClass,
};
default:
return field;
}
}, },
tdClassActions(value, key, member) { actionsFieldTdClass(value, key, member) {
if (this.hasActionButtons(member)) { if (this.hasActionButtons(member)) {
return 'col-actions'; return 'col-actions';
} }
...@@ -219,7 +222,7 @@ export default { ...@@ -219,7 +222,7 @@ export default {
data-testid="members-table" data-testid="members-table"
head-variant="white" head-variant="white"
stacked="lg" stacked="lg"
:fields="filteredFields" :fields="filteredAndModifiedFields"
:items="members" :items="members"
primary-key="id" primary-key="id"
thead-class="border-bottom" thead-class="border-bottom"
......
import { __ } from '~/locale'; import { __ } from '~/locale';
export const FIELD_KEY_ACCOUNT = 'account';
export const FIELD_KEY_SOURCE = 'source';
export const FIELD_KEY_GRANTED = 'granted';
export const FIELD_KEY_INVITED = 'invited';
export const FIELD_KEY_REQUESTED = 'requested';
export const FIELD_KEY_MAX_ROLE = 'maxRole';
export const FIELD_KEY_EXPIRATION = 'expiration';
export const FIELD_KEY_LAST_SIGN_IN = 'lastSignIn';
export const FIELD_KEY_ACTIONS = 'actions';
export const FIELDS = [ export const FIELDS = [
{ {
key: 'account', key: FIELD_KEY_ACCOUNT,
label: __('Account'), label: __('Account'),
sort: { sort: {
asc: 'name_asc', asc: 'name_asc',
...@@ -10,13 +20,13 @@ export const FIELDS = [ ...@@ -10,13 +20,13 @@ export const FIELDS = [
}, },
}, },
{ {
key: 'source', key: FIELD_KEY_SOURCE,
label: __('Source'), label: __('Source'),
thClass: 'col-meta', thClass: 'col-meta',
tdClass: 'col-meta', tdClass: 'col-meta',
}, },
{ {
key: 'granted', key: FIELD_KEY_GRANTED,
label: __('Access granted'), label: __('Access granted'),
thClass: 'col-meta', thClass: 'col-meta',
tdClass: 'col-meta', tdClass: 'col-meta',
...@@ -26,19 +36,19 @@ export const FIELDS = [ ...@@ -26,19 +36,19 @@ export const FIELDS = [
}, },
}, },
{ {
key: 'invited', key: FIELD_KEY_INVITED,
label: __('Invited'), label: __('Invited'),
thClass: 'col-meta', thClass: 'col-meta',
tdClass: 'col-meta', tdClass: 'col-meta',
}, },
{ {
key: 'requested', key: FIELD_KEY_REQUESTED,
label: __('Requested'), label: __('Requested'),
thClass: 'col-meta', thClass: 'col-meta',
tdClass: 'col-meta', tdClass: 'col-meta',
}, },
{ {
key: 'maxRole', key: FIELD_KEY_MAX_ROLE,
label: __('Max role'), label: __('Max role'),
thClass: 'col-max-role', thClass: 'col-max-role',
tdClass: 'col-max-role', tdClass: 'col-max-role',
...@@ -48,13 +58,13 @@ export const FIELDS = [ ...@@ -48,13 +58,13 @@ export const FIELDS = [
}, },
}, },
{ {
key: 'expiration', key: FIELD_KEY_EXPIRATION,
label: __('Expiration'), label: __('Expiration'),
thClass: 'col-expiration', thClass: 'col-expiration',
tdClass: 'col-expiration', tdClass: 'col-expiration',
}, },
{ {
key: 'lastSignIn', key: FIELD_KEY_LAST_SIGN_IN,
label: __('Last sign-in'), label: __('Last sign-in'),
sort: { sort: {
asc: 'recent_sign_in', asc: 'recent_sign_in',
...@@ -62,10 +72,8 @@ export const FIELDS = [ ...@@ -62,10 +72,8 @@ export const FIELDS = [
}, },
}, },
{ {
key: 'actions', key: FIELD_KEY_ACTIONS,
thClass: 'col-actions', thClass: 'col-actions',
showFunction: 'showActionsField',
tdClassFunction: 'tdClassActions',
}, },
]; ];
......
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