Welcome to mirror list, hosted at ThFree Co, Russian Federation.

assignees_realtime.vue « assignees « components « sidebar « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f98798582c153eda1e294f631354b982ef27b3e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<script>
import actionCable from '~/actioncable_consumer';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import { assigneesQueries } from '~/sidebar/constants';

export default {
  subscription: null,
  name: 'AssigneesRealtime',
  props: {
    mediator: {
      type: Object,
      required: false,
      default: null,
    },
    issuableIid: {
      type: String,
      required: true,
    },
    projectPath: {
      type: String,
      required: true,
    },
    issuableType: {
      type: String,
      required: true,
    },
  },
  apollo: {
    workspace: {
      query() {
        return assigneesQueries[this.issuableType].query;
      },
      variables() {
        return {
          iid: this.issuableIid,
          fullPath: this.projectPath,
        };
      },
      result(data) {
        if (this.mediator) {
          this.handleFetchResult(data);
        }
      },
    },
  },
  mounted() {
    this.initActionCablePolling();
  },
  beforeDestroy() {
    this.$options.subscription.unsubscribe();
  },
  methods: {
    received(data) {
      if (data.event === 'updated') {
        this.$apollo.queries.workspace.refetch();
      }
    },
    initActionCablePolling() {
      this.$options.subscription = actionCable.subscriptions.create(
        {
          channel: 'IssuesChannel',
          project_path: this.projectPath,
          iid: this.issuableIid,
        },
        { received: this.received },
      );
    },
    handleFetchResult({ data }) {
      const { nodes } = data.workspace.issuable.assignees;

      const assignees = nodes.map((n) => ({
        ...n,
        avatar_url: n.avatarUrl,
        id: getIdFromGraphQLId(n.id),
      }));

      this.mediator.store.setAssigneesFromRealtime(assignees);
    },
  },
  render() {
    return null;
  },
};
</script>