1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

fix: project features batch actions refetch (#5680)

Reload paginated features on project overview after batch action.
This commit is contained in:
Tymoteusz Czech 2023-12-19 13:46:06 +01:00 committed by GitHub
parent 42943ada75
commit 8388700f76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 19 deletions

View File

@ -481,6 +481,7 @@ export const PaginatedProjectFeatureToggles = ({
data={features}
projectId={projectId}
onResetSelection={table.resetRowSelection}
onChange={refetch}
/>
</BatchSelectionActionsBar>
</>

View File

@ -693,6 +693,7 @@ export const ProjectFeatureToggles = ({
data={features}
projectId={projectId}
onResetSelection={() => toggleAllRowsSelected(false)}
onChange={onChange}
/>
</BatchSelectionActionsBar>
</>

View File

@ -6,7 +6,6 @@ import { ITag } from 'interfaces/tags';
import useTagApi from 'hooks/api/actions/useTagApi/useTagApi';
import useToast from 'hooks/useToast';
import { formatUnknownError } from 'utils/formatUnknownError';
import useProject from 'hooks/api/getters/useProject/useProject';
import { PermissionHOC } from 'component/common/PermissionHOC/PermissionHOC';
import { UPDATE_FEATURE } from 'component/providers/AccessProvider/permissions';
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
@ -14,11 +13,15 @@ import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
interface IManageTagsProps {
data: FeatureSchema[];
projectId: string;
onChange?: () => void;
}
export const ManageTags: VFC<IManageTagsProps> = ({ projectId, data }) => {
export const ManageTags: VFC<IManageTagsProps> = ({
projectId,
data,
onChange,
}) => {
const { bulkUpdateTags } = useTagApi();
const { refetch } = useProject(projectId);
const { setToastData, setToastApiError } = useToast();
const { trackEvent } = usePlausibleTracker();
const [isOpen, setIsOpen] = useState(false);
@ -60,7 +63,6 @@ export const ManageTags: VFC<IManageTagsProps> = ({ projectId, data }) => {
const payload = { features, tags: { addedTags, removedTags } };
try {
await bulkUpdateTags(payload, projectId);
refetch();
const added = addedTags.length
? `Added tags: ${addedTags
.map(({ type, value }) => `${type}:${value}`)
@ -86,6 +88,7 @@ export const ManageTags: VFC<IManageTagsProps> = ({ projectId, data }) => {
} catch (error: unknown) {
setToastApiError(formatUnknownError(error));
}
onChange?.();
setIsOpen(false);
};

View File

@ -15,7 +15,6 @@ import { MoreVert, WatchLater } from '@mui/icons-material';
import type { FeatureSchema } from 'openapi';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import useProjectApi from 'hooks/api/actions/useProjectApi/useProjectApi';
import useProject from 'hooks/api/getters/useProject/useProject';
import useToast from 'hooks/useToast';
import { formatUnknownError } from 'utils/formatUnknownError';
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
@ -24,12 +23,16 @@ import { MORE_BATCH_ACTIONS } from 'utils/testIds';
interface IMoreActionsProps {
projectId: string;
data: FeatureSchema[];
onChange?: () => void;
}
const menuId = 'selection-actions-menu';
export const MoreActions: VFC<IMoreActionsProps> = ({ projectId, data }) => {
const { refetch } = useProject(projectId);
export const MoreActions: VFC<IMoreActionsProps> = ({
projectId,
data,
onChange,
}) => {
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const { staleFeatures } = useProjectApi();
const { setToastData, setToastApiError } = useToast();
@ -52,7 +55,7 @@ export const MoreActions: VFC<IMoreActionsProps> = ({ projectId, data }) => {
try {
handleClose();
await staleFeatures(projectId, selectedIds);
await refetch();
onChange?.();
setToastData({
title: 'State updated',
text: 'Feature toggles marked as stale',
@ -72,7 +75,7 @@ export const MoreActions: VFC<IMoreActionsProps> = ({ projectId, data }) => {
try {
handleClose();
await staleFeatures(projectId, selectedIds, false);
await refetch();
onChange?.();
setToastData({
title: 'State updated',
text: 'Feature toggles unmarked as stale',

View File

@ -16,11 +16,12 @@ interface IProjectFeaturesBatchActionsProps {
data: FeatureSchema[];
projectId: string;
onResetSelection: () => void;
onChange?: () => void;
}
export const ProjectFeaturesBatchActions: FC<
IProjectFeaturesBatchActionsProps
> = ({ selectedIds, data, projectId, onResetSelection }) => {
> = ({ selectedIds, data, projectId, onResetSelection, onChange }) => {
const { uiConfig } = useUiConfig();
const [showExportDialog, setShowExportDialog] = useState(false);
const [showBulkEnableDialog, setShowBulkEnableDialog] = useState(false);
@ -39,21 +40,24 @@ export const ProjectFeaturesBatchActions: FC<
return Array.from(new Set(envs));
}, [selectedData]);
const trackExport = () => {
const confirmExport = () => {
onChange?.();
trackEvent('batch_operations', {
props: {
eventType: 'features exported',
},
});
};
const trackBulkEnabled = () => {
const confirmBulkEnabled = () => {
onChange?.();
trackEvent('batch_operations', {
props: {
eventType: 'features enabled',
},
});
};
const trackBulkDisabled = () => {
const confirmBulkDisabled = () => {
onChange?.();
trackEvent('batch_operations', {
props: {
eventType: 'features disabled',
@ -61,6 +65,11 @@ export const ProjectFeaturesBatchActions: FC<
});
};
const confirmArchive = () => {
onChange?.();
onResetSelection();
};
return (
<>
<ConditionallyRender
@ -93,7 +102,7 @@ export const ProjectFeaturesBatchActions: FC<
projectId={projectId}
featureIds={selectedIds}
features={data}
onConfirm={onResetSelection}
onConfirm={confirmArchive}
/>
<Button
variant='outlined'
@ -102,14 +111,22 @@ export const ProjectFeaturesBatchActions: FC<
>
Export
</Button>
<ManageTags projectId={projectId} data={selectedData} />
<MoreActions projectId={projectId} data={selectedData} />
<ManageTags
projectId={projectId}
data={selectedData}
onChange={onChange}
/>
<MoreActions
projectId={projectId}
data={selectedData}
onChange={onChange}
/>
<ExportDialog
showExportDialog={showExportDialog}
data={selectedData}
onClose={() => setShowExportDialog(false)}
environments={environments}
onConfirm={trackExport}
onConfirm={confirmExport}
/>
<BulkEnableDialog
showExportDialog={showBulkEnableDialog}
@ -117,7 +134,7 @@ export const ProjectFeaturesBatchActions: FC<
onClose={() => setShowBulkEnableDialog(false)}
environments={environments}
projectId={projectId}
onConfirm={trackBulkEnabled}
onConfirm={confirmBulkEnabled}
/>
<BulkDisableDialog
showExportDialog={showBulkDisableDialog}
@ -125,7 +142,7 @@ export const ProjectFeaturesBatchActions: FC<
onClose={() => setShowBulkDisableDialog(false)}
environments={environments}
projectId={projectId}
onConfirm={trackBulkDisabled}
onConfirm={confirmBulkDisabled}
/>
</>
);