Skip to content

Commit

Permalink
feat / add switch and input to project settings
Browse files Browse the repository at this point in the history
  • Loading branch information
psiddharthdesign committed Aug 14, 2024
1 parent 4227139 commit e673c64
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Button } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
import { Switch } from "@/components/ui/switch";
import { updateProjectSettingsAction } from "@/data/user/projects";
import { useSAToastMutation } from "@/hooks/useSAToastMutation";
import { Tables } from "@/lib/database.types";
Expand All @@ -21,6 +22,8 @@ type ProjectSettingsFormData = {
terraformWorkingDir: string;
labels: string[];
managedState: boolean;
is_drift_detection_enabled: boolean;
drift_crontab: string;
};

export default function ProjectSettings({ project, repositoryName }: ProjectSettingsProps) {
Expand All @@ -31,6 +34,8 @@ export default function ProjectSettings({ project, repositoryName }: ProjectSett
terraformWorkingDir: project.terraform_working_dir || '',
labels: project.labels || [],
managedState: project.is_managing_state || false,
is_drift_detection_enabled: project.is_drift_detection_enabled || false,
drift_crontab: project.drift_crontab || '',
},
});

Expand All @@ -41,6 +46,8 @@ export default function ProjectSettings({ project, repositoryName }: ProjectSett
terraformWorkingDir: data.terraformWorkingDir,
labels: data.labels,
managedState: data.managedState,
is_drift_detection_enabled: data.is_drift_detection_enabled,
drift_crontab: data.drift_crontab,
});
return result;
},
Expand Down Expand Up @@ -132,6 +139,34 @@ export default function ProjectSettings({ project, repositoryName }: ProjectSett
/>
</motion.div>


{/* Drift Detection */}
<div className="flex items-center gap-2">
<Label htmlFor="is_drift_detection_enabled">Drift Detection</Label>
<Controller
name="is_drift_detection_enabled"
control={control}
render={({ field }) => (
<Switch
checked={field.value}
onCheckedChange={field.onChange}
/>
)}
/>
</div>

{/* Input to set the drift detection crontab */}
<div>
<Label htmlFor="drift_crontab">Drift Detection Crontab</Label>
<Controller
name="drift_crontab"
control={control}
render={({ field }) => (
<Input id="drift_crontab" {...field} />
)}
/>
</div>

<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
Expand Down
6 changes: 6 additions & 0 deletions src/data/user/projects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -800,11 +800,15 @@ export async function updateProjectSettingsAction({
terraformWorkingDir,
labels,
managedState,
is_drift_detection_enabled,
drift_crontab,
}: {
projectId: string;
terraformWorkingDir: string;
labels: string[];
managedState: boolean;
is_drift_detection_enabled: boolean;
drift_crontab: string;
}): Promise<SAPayload<unknown>> {
const supabase = createSupabaseUserServerComponentClient();

Expand All @@ -815,6 +819,8 @@ export async function updateProjectSettingsAction({
terraform_working_dir: terraformWorkingDir,
labels,
is_managing_state: managedState,
is_drift_detection_enabled: is_drift_detection_enabled,
drift_crontab: drift_crontab,
})
.eq('id', projectId)
.select()
Expand Down
6 changes: 6 additions & 0 deletions src/lib/database.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,9 @@ export type Database = {
configuration_yaml: string | null
created_at: string
deleted_at: string | null
drift_crontab: string | null
id: string
is_drift_detection_enabled: boolean | null
is_generated: boolean | null
is_in_main_branch: boolean | null
is_managing_state: boolean | null
Expand All @@ -1295,7 +1297,9 @@ export type Database = {
configuration_yaml?: string | null
created_at?: string
deleted_at?: string | null
drift_crontab?: string | null
id?: string
is_drift_detection_enabled?: boolean | null
is_generated?: boolean | null
is_in_main_branch?: boolean | null
is_managing_state?: boolean | null
Expand All @@ -1315,7 +1319,9 @@ export type Database = {
configuration_yaml?: string | null
created_at?: string
deleted_at?: string | null
drift_crontab?: string | null
id?: string
is_drift_detection_enabled?: boolean | null
is_generated?: boolean | null
is_in_main_branch?: boolean | null
is_managing_state?: boolean | null
Expand Down

0 comments on commit e673c64

Please sign in to comment.