From 32954e81680ce5315b3d63649dcc5e07b90c2d3b Mon Sep 17 00:00:00 2001
From: andreas-unleash
Date: Tue, 8 Aug 2023 16:46:11 +0300
Subject: [PATCH] feat: bulk archive usage warning (#4448)
Adds a warning when about to archive features that have lastSeenAt of
less than a week (green usage)
Closes #
[1-224](https://linear.app/unleash/issue/1-1224/bulk-edit-show-last-seen-usage-warning)
![Screenshot 2023-08-08 at 15 10
26](https://github.com/Unleash/unleash/assets/104830839/7783c751-dcdf-4d80-a6fb-b441fb034b70)
---------
Signed-off-by: andreas-unleash
---
.../FeatureArchiveDialog.tsx | 59 +++++++++++++++++++
.../ArchiveButton.tsx | 29 ++++++++-
.../ProjectFeaturesBatchActions.tsx | 6 +-
3 files changed, 90 insertions(+), 4 deletions(-)
diff --git a/frontend/src/component/common/FeatureArchiveDialog/FeatureArchiveDialog.tsx b/frontend/src/component/common/FeatureArchiveDialog/FeatureArchiveDialog.tsx
index ec4daf26ee..7cb2a0c088 100644
--- a/frontend/src/component/common/FeatureArchiveDialog/FeatureArchiveDialog.tsx
+++ b/frontend/src/component/common/FeatureArchiveDialog/FeatureArchiveDialog.tsx
@@ -5,6 +5,9 @@ import useToast from 'hooks/useToast';
import { formatUnknownError } from 'utils/formatUnknownError';
import { ConditionallyRender } from '../ConditionallyRender/ConditionallyRender';
import useProjectApi from 'hooks/api/actions/useProjectApi/useProjectApi';
+import { Alert, Typography } from '@mui/material';
+import { Link } from 'react-router-dom';
+import useUiConfig from '../../../hooks/api/getters/useUiConfig/useUiConfig';
interface IFeatureArchiveDialogProps {
isOpen: boolean;
@@ -12,18 +15,61 @@ interface IFeatureArchiveDialogProps {
onClose: () => void;
projectId: string;
featureIds: string[];
+ featuresWithUsage?: string[];
}
+const UsageWarning = ({
+ ids,
+ projectId,
+}: {
+ ids?: string[];
+ projectId: string;
+}) => {
+ const formatPath = (id: string) => {
+ return `/projects/${projectId}/features/${id}`;
+ };
+ if (ids) {
+ return (
+ theme.spacing(2, 0) }}
+ >
+
+ {`${ids.length} feature toggles `}
+
+
+ have usage from applications. If you archive these feature
+ toggles they will not be available to Client SDKs:
+
+
+ {ids?.map(id => (
+ -
+ {{id}}
+
+ ))}
+
+
+ );
+ }
+ return null;
+};
+
export const FeatureArchiveDialog: VFC = ({
isOpen,
onClose,
onConfirm,
projectId,
featureIds,
+ featuresWithUsage,
}) => {
const { archiveFeatureToggle } = useFeatureApi();
const { archiveFeatures } = useProjectApi();
const { setToastData, setToastApiError } = useToast();
+ const { uiConfig } = useUiConfig();
const isBulkArchive = featureIds?.length > 1;
const archiveToggle = async () => {
@@ -82,6 +128,19 @@ export const FeatureArchiveDialog: VFC = ({
{featureIds?.length} feature
toggles?
+ 0
+ )}
+ show={
+
+ }
+ />
{
+ const aWeekAgo = addDays(new Date(), -DEFAULT_USAGE_THRESHOLD_DAYS);
+ return !!(
+ feature &&
+ feature.lastSeenAt &&
+ isBefore(new Date(feature.lastSeenAt), aWeekAgo)
+ );
+};
+
export const ArchiveButton: VFC = ({
projectId,
+ featureIds,
features,
}) => {
const { refetch } = useProject(projectId);
const [isDialogOpen, setIsDialogOpen] = useState(false);
const { trackEvent } = usePlausibleTracker();
+ const featuresWithUsage = useMemo(() => {
+ return featureIds.filter(name => {
+ const feature = features.find(f => f.name === name);
+ return isFeatureInUse(feature);
+ });
+ }, [JSON.stringify(features), featureIds]);
+
const onConfirm = async () => {
setIsDialogOpen(false);
await refetch();
@@ -45,7 +67,8 @@ export const ArchiveButton: VFC = ({
setIsDialogOpen(false)}
diff --git a/frontend/src/component/project/Project/ProjectFeatureToggles/ProjectFeaturesBatchActions/ProjectFeaturesBatchActions.tsx b/frontend/src/component/project/Project/ProjectFeatureToggles/ProjectFeaturesBatchActions/ProjectFeaturesBatchActions.tsx
index f8386e18dd..80ac294bcd 100644
--- a/frontend/src/component/project/Project/ProjectFeatureToggles/ProjectFeaturesBatchActions/ProjectFeaturesBatchActions.tsx
+++ b/frontend/src/component/project/Project/ProjectFeatureToggles/ProjectFeaturesBatchActions/ProjectFeaturesBatchActions.tsx
@@ -88,7 +88,11 @@ export const ProjectFeaturesBatchActions: FC<
}
/>
-
+