go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/lucicfg/starlark/stdlib/internal/luci/rules/list_view.star (about)

     1  # Copyright 2019 The LUCI Authors.
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #      http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  
    15  """Defines luci.list_view(...) rule."""
    16  
    17  load("@stdlib//internal/lucicfg.star", "lucicfg")
    18  load("@stdlib//internal/validate.star", "validate")
    19  load("@stdlib//internal/luci/common.star", "keys", "kinds", "view")
    20  load("@stdlib//internal/luci/rules/list_view_entry.star", "list_view_entry")
    21  
    22  def _list_view(
    23          ctx,  # @unused
    24          *,
    25          name = None,
    26          title = None,
    27          favicon = None,
    28          entries = None):
    29      """A Milo UI view that displays a list of builders.
    30  
    31      Builders that belong to this view can be specified either right here:
    32  
    33          luci.list_view(
    34              name = 'Try builders',
    35              entries = [
    36                  'win',
    37                  'linux',
    38                  luci.list_view_entry('osx'),
    39              ],
    40          )
    41  
    42      Or separately one by one via luci.list_view_entry(...) declarations:
    43  
    44          luci.list_view(name = 'Try builders')
    45          luci.list_view_entry(
    46              builder = 'win',
    47              list_view = 'Try builders',
    48          )
    49          luci.list_view_entry(
    50              builder = 'linux',
    51              list_view = 'Try builders',
    52          )
    53  
    54      Note that list views support builders defined in other projects. See
    55      [Referring to builders in other projects](#external-builders) for more
    56      details.
    57  
    58      Args:
    59        ctx: the implicit rule context, see lucicfg.rule(...).
    60        name: a name of this view, will show up in URLs. Note that names of
    61          luci.list_view(...) and luci.console_view(...) are in the same namespace
    62          i.e. defining a list view with the same name as some console view (and
    63          vice versa) causes an error. Required.
    64        title: a title of this view, will show up in UI. Defaults to `name`.
    65        favicon: optional https URL to the favicon for this view, must be hosted
    66          on `storage.googleapis.com`. Defaults to `favicon` in luci.milo(...).
    67        entries: a list of builders or luci.list_view_entry(...) entities to
    68          include into this view.
    69      """
    70      return view.add_view(
    71          key = keys.list_view(name),
    72          entry_kind = kinds.LIST_VIEW_ENTRY,
    73          entry_ctor = list_view_entry,
    74          entries = entries,
    75          props = {
    76              "name": name,
    77              "title": validate.string("title", title, default = name, required = False),
    78              "favicon": validate.string("favicon", favicon, regexp = r"https://storage\.googleapis\.com/.+", required = False),
    79          },
    80      )
    81  
    82  list_view = lucicfg.rule(impl = _list_view)