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

top_nav_view_model_builder.rb « nav « gitlab « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 11ca6a3a3bab2b64755b13b9d734b8903efd4061 (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
# frozen_string_literal: true

module Gitlab
  module Nav
    class TopNavViewModelBuilder
      def initialize
        @menu_builder = ::Gitlab::Nav::TopNavMenuBuilder.new
        @views = {}
        @shortcuts = []
      end

      # Using delegate hides the stacktrace for some errors, so we choose to be explicit.
      # https://gitlab.com/gitlab-org/gitlab/-/merge_requests/62047#note_579031091
      def add_primary_menu_item(**args)
        @menu_builder.add_primary_menu_item(**args)
      end

      def add_secondary_menu_item(**args)
        @menu_builder.add_secondary_menu_item(**args)
      end

      def add_shortcut(**args)
        item = ::Gitlab::Nav::TopNavMenuItem.build(**args)

        @shortcuts.push(item)
      end

      def add_primary_menu_item_with_shortcut(shortcut_class:, shortcut_href: nil, **args)
        add_primary_menu_item(**args)
        add_shortcut(
          id: "#{args.fetch(:id)}-shortcut",
          title: args.fetch(:title),
          href: shortcut_href || args.fetch(:href),
          css_class: shortcut_class
        )
      end

      def add_view(name, props)
        @views[name] = props
      end

      def build
        menu = @menu_builder.build

        menu.merge({
          views: @views,
          shortcuts: @shortcuts,
          activeTitle: _('Menu')
        })
      end
    end
  end
end