Newer
Older
Sloan Sparger
committed
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";
github-automation-metabase
committed
import { PLUGIN_COLLECTIONS } from "metabase/plugins";
Sloan Sparger
committed
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";
import { getDateFilterValue } from "../CleanupCollectionModal/utils";
Sloan Sparger
committed
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);
github-automation-metabase
committed
const shouldFetchStaleItems =
isAdmin && PLUGIN_COLLECTIONS.canCleanUp(collection);
Sloan Sparger
committed
const {
data: staleItems,
isLoading,
error,
} = useListStaleCollectionItemsQuery(
github-automation-metabase
committed
shouldFetchStaleItems
Sloan Sparger
committed
? {
id: collection.id,
limit: 0, // only fetch pagination info
before_date: getDateFilterValue("three-months"), // set to 3 months ago
Sloan Sparger
committed
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
}
: 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>
);
};