Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add killFeatureFlag function to List component #4120

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion apps/web/src/components/Staff/FeatureFlags/List.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Create from './Create';
const List: FC = () => {
const [showCreateModal, setShowCreateModal] = useState(false);
const [features, setFeatures] = useState<[] | Feature[]>([]);
const [killing, setKilling] = useState(false);

const { error, isLoading } = useQuery({
queryFn: () =>
Expand All @@ -31,6 +32,33 @@ const List: FC = () => {
queryKey: ['getAllFeatureFlags']
});

const killFeatureFlag = async (id: string, enabled: boolean) => {
setKilling(true);
toast.promise(
axios.post(
`${HEY_API_URL}/internal/feature/kill`,
{ enabled, id },
{ headers: getAuthWorkerHeaders() }
),
{
error: () => {
setKilling(false);
return 'Failed to kill feature flag';
},
loading: 'Killing feature flag...',
success: () => {
setKilling(false);
setFeatures(
features.map((feature) =>
feature.id === id ? { ...feature, enabled } : feature
)
);
return 'Feature flag killed';
}
}
);
};

const deleteFeatureFlag = async (id: string) => {
toast.promise(
axios.post(
Expand Down Expand Up @@ -82,9 +110,10 @@ const List: FC = () => {
description={`Created on ${formatDate(
feature.createdAt
)} with priority ${feature.priority}`}
disabled={killing}
heading={feature.key}
on={feature.enabled}
setOn={() => {}}
setOn={() => killFeatureFlag(feature.id, !feature.enabled)}
/>
{feature.priority === 0 && (
<Button
Expand Down
Loading