backstage

Форк
0
110 строк · 3.0 Кб
1
/*
2
 * Copyright 2020 The Backstage Authors
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16

17
import { Entity } from '@backstage/catalog-model';
18
import { createDevApp, EntityGridItem } from '@backstage/dev-utils';
19
import { EntityProvider } from '@backstage/plugin-catalog-react';
20
import { Grid } from '@material-ui/core';
21
import React from 'react';
22
import {
23
  EntitySentryCard,
24
  EntitySentryContent,
25
  MockSentryApi,
26
  SentryApi,
27
  sentryApiRef,
28
} from '../src';
29
import {
30
  SENTRY_PROJECT_SLUG_ANNOTATION,
31
  getProjectSlug,
32
} from '../src/api/annotations';
33
import { Content, Header, Page } from '@backstage/core-components';
34

35
const entity = (name?: string) =>
36
  ({
37
    apiVersion: 'backstage.io/v1alpha1',
38
    kind: 'Component',
39
    metadata: {
40
      annotations: {
41
        [SENTRY_PROJECT_SLUG_ANNOTATION]: name,
42
      },
43
      name: name,
44
    },
45
  } as Entity);
46

47
createDevApp()
48
  .registerApi({
49
    api: sentryApiRef,
50
    deps: {},
51
    factory: () =>
52
      ({
53
        fetchIssues: async (e: Entity) => {
54
          switch (getProjectSlug(e)) {
55
            case 'error':
56
              throw new Error('Error!');
57

58
            case 'never':
59
              return new Promise(() => {});
60

61
            case 'with-values':
62
              return new MockSentryApi().fetchIssues();
63

64
            default:
65
              return [];
66
          }
67
        },
68
      } as SentryApi),
69
  })
70
  .addPage({
71
    title: 'Entity Content',
72
    element: (
73
      <Page themeId="home">
74
        <Header title="Sentry" />
75
        <Content>
76
          <EntityProvider entity={entity('with-values')}>
77
            <EntitySentryContent />
78
          </EntityProvider>
79
        </Content>
80
      </Page>
81
    ),
82
  })
83
  .addPage({
84
    title: 'Cards',
85
    element: (
86
      <Page themeId="home">
87
        <Header title="Sentry" />
88
        <Content>
89
          <Grid container>
90
            <EntityGridItem xs={12} md={6} entity={entity('error')}>
91
              <EntitySentryCard />
92
            </EntityGridItem>
93
            <EntityGridItem xs={12} md={6} entity={entity('empty')}>
94
              <EntitySentryCard />
95
            </EntityGridItem>
96
            <EntityGridItem xs={12} md={6} entity={entity('never')}>
97
              <EntitySentryCard />
98
            </EntityGridItem>
99
            <EntityGridItem xs={12} md={6} entity={entity('with-values')}>
100
              <EntitySentryCard />
101
            </EntityGridItem>
102
            <EntityGridItem xs={12} entity={entity(undefined)}>
103
              <EntitySentryCard />
104
            </EntityGridItem>
105
          </Grid>
106
        </Content>
107
      </Page>
108
    ),
109
  })
110
  .render();
111

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.