debian-mirror-gitlab/app/assets/javascripts/sidebar/components/assignees/assignees_realtime.vue

85 lines
1.8 KiB
Vue
Raw Normal View History

2020-05-24 23:13:21 +05:30
<script>
2021-03-11 19:13:27 +05:30
import actionCable from '~/actioncable_consumer';
2020-05-24 23:13:21 +05:30
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
2021-04-29 21:17:54 +05:30
import { assigneesQueries } from '~/sidebar/constants';
2020-05-24 23:13:21 +05:30
export default {
subscription: null,
name: 'AssigneesRealtime',
props: {
mediator: {
type: Object,
2021-04-29 21:17:54 +05:30
required: false,
default: null,
2020-05-24 23:13:21 +05:30
},
issuableIid: {
type: String,
required: true,
},
projectPath: {
type: String,
required: true,
},
2021-04-29 21:17:54 +05:30
issuableType: {
type: String,
required: true,
},
2020-05-24 23:13:21 +05:30
},
apollo: {
2021-04-29 21:17:54 +05:30
workspace: {
query() {
return assigneesQueries[this.issuableType].query;
},
2020-05-24 23:13:21 +05:30
variables() {
return {
iid: this.issuableIid,
fullPath: this.projectPath,
};
},
result(data) {
2021-04-29 21:17:54 +05:30
if (this.mediator) {
this.handleFetchResult(data);
}
2020-05-24 23:13:21 +05:30
},
},
},
mounted() {
this.initActionCablePolling();
},
beforeDestroy() {
this.$options.subscription.unsubscribe();
},
methods: {
received(data) {
if (data.event === 'updated') {
2021-04-29 21:17:54 +05:30
this.$apollo.queries.workspace.refetch();
2020-05-24 23:13:21 +05:30
}
},
initActionCablePolling() {
this.$options.subscription = actionCable.subscriptions.create(
{
channel: 'IssuesChannel',
project_path: this.projectPath,
iid: this.issuableIid,
},
{ received: this.received },
);
},
handleFetchResult({ data }) {
2021-04-29 21:17:54 +05:30
const { nodes } = data.workspace.issuable.assignees;
2020-05-24 23:13:21 +05:30
2021-03-08 18:12:59 +05:30
const assignees = nodes.map((n) => ({
2020-05-24 23:13:21 +05:30
...n,
avatar_url: n.avatarUrl,
id: getIdFromGraphQLId(n.id),
}));
this.mediator.store.setAssigneesFromRealtime(assignees);
},
},
render() {
2021-04-29 21:17:54 +05:30
return null;
2020-05-24 23:13:21 +05:30
},
};
</script>