2020-05-04 08:09:46 -04:00
|
|
|
<script>
|
|
|
|
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
|
|
|
|
import query from '~/issuable_sidebar/queries/issue_sidebar.query.graphql';
|
|
|
|
import actionCable from '~/actioncable_consumer';
|
|
|
|
|
|
|
|
export default {
|
2020-05-08 02:09:40 -04:00
|
|
|
subscription: null,
|
2020-05-04 08:09:46 -04:00
|
|
|
name: 'AssigneesRealtime',
|
|
|
|
props: {
|
|
|
|
mediator: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
issuableIid: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
projectPath: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
apollo: {
|
|
|
|
project: {
|
|
|
|
query,
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
iid: this.issuableIid,
|
|
|
|
fullPath: this.projectPath,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
result(data) {
|
|
|
|
this.handleFetchResult(data);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.initActionCablePolling();
|
|
|
|
},
|
2020-05-08 02:09:40 -04:00
|
|
|
beforeDestroy() {
|
|
|
|
this.$options.subscription.unsubscribe();
|
|
|
|
},
|
2020-05-04 08:09:46 -04:00
|
|
|
methods: {
|
|
|
|
received(data) {
|
|
|
|
if (data.event === 'updated') {
|
|
|
|
this.$apollo.queries.project.refetch();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
initActionCablePolling() {
|
2020-05-08 02:09:40 -04:00
|
|
|
this.$options.subscription = actionCable.subscriptions.create(
|
2020-05-04 08:09:46 -04:00
|
|
|
{
|
|
|
|
channel: 'IssuesChannel',
|
|
|
|
project_path: this.projectPath,
|
|
|
|
iid: this.issuableIid,
|
|
|
|
},
|
|
|
|
{ received: this.received },
|
|
|
|
);
|
|
|
|
},
|
|
|
|
handleFetchResult({ data }) {
|
|
|
|
const { nodes } = data.project.issue.assignees;
|
|
|
|
|
|
|
|
const assignees = nodes.map(n => ({
|
|
|
|
...n,
|
|
|
|
avatar_url: n.avatarUrl,
|
|
|
|
id: getIdFromGraphQLId(n.id),
|
|
|
|
}));
|
|
|
|
|
|
|
|
this.mediator.store.setAssigneesFromRealtime(assignees);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
render() {
|
|
|
|
return this.$slots.default;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|