-
Notifications
You must be signed in to change notification settings - Fork 14k
/
EmptyState.tsx
163 lines (159 loc) · 4.93 KB
/
EmptyState.tsx
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import React from 'react';
import Button from 'src/components/Button';
import { Empty } from 'src/components';
import { t, styled } from '@superset-ui/core';
import { WelcomeTable } from './types';
const welcomeTableLabels: Record<WelcomeTable, string> = {
[WelcomeTable.Charts]: t('charts'),
[WelcomeTable.Dashboards]: t('dashboards'),
[WelcomeTable.Recents]: t('recents'),
[WelcomeTable.SavedQueries]: t('saved queries'),
};
interface EmptyStateProps {
tableName: WelcomeTable;
tab?: string;
}
const EmptyContainer = styled.div`
min-height: 200px;
display: flex;
flex-direction: column;
justify-content: space-around;
`;
const ButtonContainer = styled.div`
Button {
svg {
color: ${({ theme }) => theme.colors.grayscale.light5};
}
}
`;
type Redirects = Record<
WelcomeTable.Charts | WelcomeTable.Dashboards | WelcomeTable.SavedQueries,
string
>;
export default function EmptyState({ tableName, tab }: EmptyStateProps) {
const mineRedirects: Redirects = {
[WelcomeTable.Charts]: '/chart/add',
[WelcomeTable.Dashboards]: '/dashboard/new',
[WelcomeTable.SavedQueries]: '/superset/sqllab?new=true',
};
const favRedirects: Redirects = {
[WelcomeTable.Charts]: '/chart/list',
[WelcomeTable.Dashboards]: '/dashboard/list/',
[WelcomeTable.SavedQueries]: '/savedqueryview/list/',
};
const tableIcon: Record<WelcomeTable, string> = {
[WelcomeTable.Charts]: 'empty-charts.svg',
[WelcomeTable.Dashboards]: 'empty-dashboard.svg',
[WelcomeTable.Recents]: 'union.svg',
[WelcomeTable.SavedQueries]: 'empty-queries.svg',
};
const mine = (
<span>
{t('No %(tableName)s yet', { tableName: welcomeTableLabels[tableName] })}
</span>
);
const recent = (
<span className="no-recents">
{(() => {
if (tab === 'Viewed') {
return t(
`Recently viewed charts, dashboards, and saved queries will appear here`,
);
}
if (tab === 'Created') {
return t(
'Recently created charts, dashboards, and saved queries will appear here',
);
}
if (tab === 'Examples') {
return t('Example %(tableName)s will appear here', {
tableName: tableName.toLowerCase(),
});
}
if (tab === 'Edited') {
return t(
`Recently edited charts, dashboards, and saved queries will appear here`,
);
}
return null;
})()}
</span>
);
// Mine and Recent Activity(all tabs) tab empty state
if (tab === 'Mine' || tableName === 'RECENTS' || tab === 'Examples') {
return (
<EmptyContainer>
<Empty
image={`/static/assets/images/${tableIcon[tableName]}`}
description={
tableName === 'RECENTS' || tab === 'Examples' ? recent : mine
}
>
{tableName !== 'RECENTS' && (
<ButtonContainer>
<Button
buttonStyle="primary"
onClick={() => {
window.location.href = mineRedirects[tableName];
}}
>
<i className="fa fa-plus" />
{tableName === 'SAVED_QUERIES'
? t('SQL query')
: tableName
.split('')
.slice(0, tableName.length - 1)
.join('')}
</Button>
</ButtonContainer>
)}
</Empty>
</EmptyContainer>
);
}
// Favorite tab empty state
return (
<EmptyContainer>
<Empty
image="/static/assets/images/star-circle.svg"
description={
<span className="no-favorites">
{t("You don't have any favorites yet!")}
</span>
}
>
<Button
buttonStyle="primary"
onClick={() => {
window.location.href = favRedirects[tableName];
}}
>
{t('See all %(tableName)s', {
tableName:
tableName === 'SAVED_QUERIES'
? t('SQL Lab queries')
: welcomeTableLabels[tableName],
})}
</Button>
</Empty>
</EmptyContainer>
);
}