feat: auto-refresh services list when duplicating to same environment - Add cache invalidation for environment.one and environment.byProjectId queries - Fix issue where duplicated services weren't visible until hard refresh - Ensure proper invalidation when duplicating to current environment - Resolves #2565

This commit is contained in:
HarikrishnanD
2025-09-09 22:07:40 +05:30
parent 24729f35ec
commit abcbd2d599

View File

@@ -80,6 +80,25 @@ export const DuplicateProject = ({
api.project.duplicate.useMutation({
onSuccess: async (newProject) => {
await utils.project.all.invalidate();
// If duplicating to same project+environment, invalidate the environment query
// to refresh the services list
if (duplicateType === "existing-environment") {
await utils.environment.one.invalidate({ environmentId: selectedTargetEnvironment });
await utils.environment.byProjectId.invalidate({ projectId: selectedTargetProject });
// If duplicating to the same environment we're currently viewing,
// also invalidate the current environment to refresh the services list
if (selectedTargetEnvironment === environmentId) {
await utils.environment.one.invalidate({ environmentId });
// Also invalidate the project query to refresh the project data
const projectId = router.query.projectId as string;
if (projectId) {
await utils.project.one.invalidate({ projectId });
}
}
}
toast.success(
duplicateType === "new-project"
? "Project duplicated successfully"
@@ -328,4 +347,4 @@ export const DuplicateProject = ({
</DialogContent>
</Dialog>
);
};
};