Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
a47ceab1
Commit
a47ceab1
authored
Apr 18, 2018
by
Kushal Pandya
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GroupMemberContributions Store
parent
dde2e2bb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
108 additions
and
0 deletions
+108
-0
ee/app/assets/javascripts/group_member_contributions/store/group_member_store.js
...ts/group_member_contributions/store/group_member_store.js
+59
-0
spec/javascripts/group_member_contributions/store/group_member_store_spec.js
...oup_member_contributions/store/group_member_store_spec.js
+49
-0
No files found.
ee/app/assets/javascripts/group_member_contributions/store/group_member_store.js
0 → 100644
View file @
a47ceab1
import
{
convertObjectPropsToCamelCase
}
from
'
~/lib/utils/common_utils
'
;
export
default
class
GroupMemberStore
{
constructor
()
{
this
.
state
=
{};
this
.
state
.
members
=
[];
this
.
state
.
columns
=
[];
this
.
state
.
sortOrders
=
{};
this
.
state
.
currentSortedColumn
=
''
;
}
get
members
()
{
return
this
.
state
.
members
;
}
get
sortOrders
()
{
return
this
.
state
.
sortOrders
;
}
setColumns
(
columns
)
{
this
.
state
.
columns
=
columns
;
this
.
state
.
sortOrders
=
this
.
state
.
columns
.
reduce
(
(
acc
,
column
)
=>
({
...
acc
,
[
column
.
name
]:
1
}),
{},
);
}
setMembers
(
rawMembers
)
{
this
.
state
.
members
=
rawMembers
.
map
(
rawMember
=>
GroupMemberStore
.
formatMember
(
rawMember
));
}
sortMembers
(
sortByColumn
)
{
if
(
sortByColumn
)
{
this
.
state
.
currentSortedColumn
=
sortByColumn
;
this
.
state
.
sortOrders
[
sortByColumn
]
=
this
.
state
.
sortOrders
[
sortByColumn
]
*
-
1
;
const
currentColumnOrder
=
this
.
state
.
sortOrders
[
sortByColumn
]
||
1
;
const
members
=
this
.
state
.
members
.
slice
().
sort
((
a
,
b
)
=>
{
let
delta
=
-
1
;
const
columnOrderA
=
a
[
sortByColumn
];
const
columnOrderB
=
b
[
sortByColumn
];
if
(
columnOrderA
===
columnOrderB
)
{
delta
=
0
;
}
else
if
(
columnOrderA
>
columnOrderB
)
{
delta
=
1
;
}
return
delta
*
currentColumnOrder
;
});
this
.
state
.
members
=
members
;
}
}
static
formatMember
(
rawMember
)
{
return
convertObjectPropsToCamelCase
(
rawMember
);
}
}
spec/javascripts/group_member_contributions/store/group_member_store_spec.js
0 → 100644
View file @
a47ceab1
import
GroupMemberStore
from
'
ee/group_member_contributions/store/group_member_store
'
;
import
defaultColumns
from
'
ee/group_member_contributions/constants
'
;
import
{
rawMembers
}
from
'
../mock_data
'
;
describe
(
'
GroupMemberStore
'
,
()
=>
{
let
store
;
beforeEach
(()
=>
{
store
=
new
GroupMemberStore
();
});
describe
(
'
setColumns
'
,
()
=>
{
beforeEach
(()
=>
{
store
.
setColumns
(
defaultColumns
);
});
it
(
'
sets columns to store state
'
,
()
=>
{
expect
(
store
.
state
.
columns
).
toBe
(
defaultColumns
);
});
it
(
'
initializes sortOrders on store state
'
,
()
=>
{
Object
.
keys
(
store
.
state
.
sortOrders
).
forEach
(
column
=>
{
expect
(
store
.
state
.
sortOrders
[
column
]).
toBe
(
1
);
});
});
});
describe
(
'
setMembers
'
,
()
=>
{
it
(
'
sets members to store state
'
,
()
=>
{
store
.
setMembers
(
rawMembers
);
expect
(
store
.
state
.
members
.
length
).
toBe
(
rawMembers
.
length
);
});
});
describe
(
'
sortMembers
'
,
()
=>
{
it
(
'
sorts members list based on provided column name
'
,
()
=>
{
store
.
setColumns
(
defaultColumns
);
store
.
setMembers
(
rawMembers
);
let
firstMember
=
store
.
state
.
members
[
0
];
expect
(
firstMember
.
fullname
).
toBe
(
'
Administrator
'
);
store
.
sortMembers
(
'
fullname
'
);
firstMember
=
store
.
state
.
members
[
0
];
expect
(
firstMember
.
fullname
).
toBe
(
'
Terrell Graham
'
);
});
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment