hotfix for lab (#9981)
Issue: When attempting to toggle a public feature flag that didn't exist in the workspace's feature flags array, the LabService threw a FeatureFlagException with code FEATURE_FLAG_NOT_FOUND. This prevented users from enabling public feature flags for the first time in their workspace. Fix: Modified the LabService to handle non-existent public feature flags by creating them instead of throwing an error. When the flag doesn't exist, the service now saves a new feature flag record with the provided key and value, associates it with the workspace, and returns the newly created flag.
This commit is contained in:
@ -4,6 +4,10 @@ export const UPDATE_LAB_PUBLIC_FEATURE_FLAG = gql`
|
||||
mutation UpdateLabPublicFeatureFlag(
|
||||
$input: UpdateLabPublicFeatureFlagInput!
|
||||
) {
|
||||
updateLabPublicFeatureFlag(input: $input)
|
||||
updateLabPublicFeatureFlag(input: $input) {
|
||||
id
|
||||
key
|
||||
value
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@ -15,7 +15,29 @@ export const useLabPublicFeatureFlags = () => {
|
||||
);
|
||||
const labPublicFeatureFlags = useRecoilValue(labPublicFeatureFlagsState);
|
||||
|
||||
const [updateLabPublicFeatureFlag] = useUpdateLabPublicFeatureFlagMutation();
|
||||
const [updateLabPublicFeatureFlag] = useUpdateLabPublicFeatureFlagMutation({
|
||||
onCompleted: (data) => {
|
||||
if (isDefined(currentWorkspace)) {
|
||||
const updatedFlag = data.updateLabPublicFeatureFlag;
|
||||
|
||||
setCurrentWorkspace({
|
||||
...currentWorkspace,
|
||||
featureFlags: [
|
||||
...(currentWorkspace.featureFlags?.filter(
|
||||
(flag) => flag.key !== updatedFlag.key,
|
||||
) ?? []),
|
||||
{
|
||||
...updatedFlag,
|
||||
workspaceId: currentWorkspace.id,
|
||||
},
|
||||
],
|
||||
});
|
||||
}
|
||||
},
|
||||
onError: (error) => {
|
||||
setError(error.message);
|
||||
},
|
||||
});
|
||||
|
||||
const handleLabPublicFeatureFlagUpdate = async (
|
||||
publicFeatureFlag: FeatureFlagKey,
|
||||
@ -35,20 +57,8 @@ export const useLabPublicFeatureFlags = () => {
|
||||
value,
|
||||
},
|
||||
},
|
||||
onError: (error) => {
|
||||
setError(error.message);
|
||||
},
|
||||
});
|
||||
|
||||
if (isDefined(response.data)) {
|
||||
setCurrentWorkspace({
|
||||
...currentWorkspace,
|
||||
featureFlags: currentWorkspace.featureFlags?.map((flag) =>
|
||||
flag.key === publicFeatureFlag ? { ...flag, value } : flag,
|
||||
),
|
||||
});
|
||||
}
|
||||
|
||||
return !!response.data;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user