Newer
Older
Sloan Sparger
committed
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
import { c } from "ttag";
import { skipToken } from "metabase/api";
import Link from "metabase/core/components/Link";
import { color } from "metabase/lib/colors";
import { useSelector } from "metabase/lib/redux";
import * as Urls from "metabase/lib/urls";
import { getUserIsAdmin } from "metabase/selectors/user";
import { Alert, Box, Icon } from "metabase/ui";
import { useListStaleCollectionItemsQuery } from "metabase-enterprise/api/collection";
import type { Collection } from "metabase-types/api";
const TEXT = {
CLEAN_THINGS_UP: c(
"This is the heading of a banner that invites the user to clean up a collection.",
).t`Clean things up!`,
GET_RID_OF_UNUSED_CONTENT: c(
"This is the heading of a banner that invites the user to clean up a collection.",
).t`Get rid of unused content in this collection`,
};
export const CollectionCleanupAlert = ({
collection,
}: {
collection: Collection;
}) => {
const isAdmin = useSelector(getUserIsAdmin);
const {
data: staleItems,
isLoading,
error,
} = useListStaleCollectionItemsQuery(
isAdmin
? {
id: collection.id,
limit: 0, // only fetch pagination info
}
: skipToken,
);
const hasSomethingToCleanUp = !!staleItems?.total;
if (isLoading || error || !hasSomethingToCleanUp) {
return null;
}
return (
<Alert
data-testid="cleanup-alert"
icon={<Icon name="ai" size={16} />}
styles={{
root: { padding: 0, marginTop: "-.5rem", marginBottom: "2rem" },
icon: { marginRight: ".5rem" },
wrapper: {
backgroundColor: color("brand-lighter"),
padding: "1rem 1.5rem",
},
}}
>
<Box fz="md" c={"text-dark"}>
{TEXT.CLEAN_THINGS_UP}{" "}
<Box
component={Link}
ml="2.5rem"
fw="bold"
variant="brand"
to={`${Urls.collection(collection)}/cleanup`}
>
{TEXT.GET_RID_OF_UNUSED_CONTENT}
</Box>
</Box>
</Alert>
);
};