-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Add edit[id] page #40
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
Changes from all commits
469d91d
dea85a9
6dad657
c6aead0
8294d7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| 'use client'; | ||
|
|
||
| import { useState } from 'react'; | ||
| import { useParams, useRouter } from 'next/navigation'; | ||
|
|
||
| import { Button } from '@/components/ui/button'; | ||
| import { FeatureFlagDetails } from '@/components/FeatureFlagDetails'; | ||
| import { VariationsTable } from '@/components/VariationsTable'; | ||
| import { mockFeatureFlags } from '@/data/mock-data'; | ||
| import { FeatureFlag } from '@/types/featureFlag'; | ||
|
|
||
| export default function FeatureFlagSettings() { | ||
| const params = useParams(); | ||
| const router = useRouter(); | ||
| const id = params.id as string; | ||
|
|
||
| const targetFeatureFlag = | ||
| mockFeatureFlags.find((flag) => flag.id === id) ?? null; | ||
| const [featureFlag, setFeatureFlag] = useState<FeatureFlag | null>( | ||
| targetFeatureFlag ?? null, | ||
| ); | ||
| const [isEditing, setIsEditing] = useState(false); | ||
|
|
||
| if (!featureFlag) { | ||
| return <div>Feature flag not found</div>; | ||
| } | ||
|
|
||
| const handleSave = () => { | ||
| console.log('Saved Feature Flag:', featureFlag); | ||
| setIsEditing(false); | ||
| }; | ||
|
|
||
| const handleCancel = () => { | ||
| setFeatureFlag(targetFeatureFlag); | ||
| setIsEditing(false); | ||
| }; | ||
|
|
||
| const handleDelete = () => { | ||
| console.log('Deleting feature flag:', featureFlag); | ||
| router.push('/'); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="space-y-5 p-8"> | ||
| <div className="flex items-center justify-between"> | ||
| <h2 className="text-2xl font-bold">Feature Flag Settings</h2> | ||
| <div className="space-x-5"> | ||
| {isEditing ? ( | ||
| <> | ||
| <Button onClick={handleSave}>Save</Button> | ||
| <Button variant="outline" onClick={handleCancel}> | ||
| Cancel | ||
| </Button> | ||
| </> | ||
| ) : ( | ||
| <Button onClick={() => setIsEditing(true)}>Edit</Button> | ||
| )} | ||
| </div> | ||
| </div> | ||
|
|
||
| <FeatureFlagDetails | ||
| featureFlag={featureFlag} | ||
| setFeatureFlag={setFeatureFlag} | ||
| isEditing={isEditing} | ||
| /> | ||
|
|
||
| <VariationsTable | ||
| featureFlag={featureFlag} | ||
| setFeatureFlag={setFeatureFlag} | ||
| isEditing={isEditing} | ||
| /> | ||
|
|
||
| {isEditing && ( | ||
| <div className="flex justify-end"> | ||
| <Button variant="destructive" onClick={handleDelete}> | ||
| Delete Feature Flag | ||
| </Button> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| 'use client'; | ||
|
|
||
| import { Card, CardContent, 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 { | ||
| Select, | ||
| SelectContent, | ||
| SelectItem, | ||
| SelectTrigger, | ||
| SelectValue, | ||
| } from '@/components/ui/select'; | ||
| import { FeatureFlag } from '@/types/featureFlag'; | ||
|
|
||
| type FeatureFlagDetailsProps = { | ||
| featureFlag: FeatureFlag; | ||
| setFeatureFlag: (flag: FeatureFlag) => void; | ||
| isEditing: boolean; | ||
| }; | ||
|
|
||
| export function FeatureFlagDetails({ | ||
| featureFlag, | ||
| setFeatureFlag, | ||
| isEditing, | ||
| }: FeatureFlagDetailsProps) { | ||
| return ( | ||
| <Card className="space-y-1"> | ||
| <CardHeader> | ||
| <CardTitle className="text-xl">Feature Flag Details</CardTitle> | ||
| </CardHeader> | ||
| <CardContent className="grid grid-cols-1 gap-5 md:grid-cols-2"> | ||
| <div> | ||
| <Label htmlFor="key">Key</Label> | ||
| <Input | ||
| id="key" | ||
| value={featureFlag.key} | ||
| readOnly={!isEditing} | ||
| onChange={(e) => | ||
| setFeatureFlag({ ...featureFlag, key: e.target.value }) | ||
| } | ||
| /> | ||
| </div> | ||
| <div> | ||
| <Label htmlFor="type">Type</Label> | ||
| {isEditing ? ( | ||
| <Select | ||
| defaultValue={featureFlag.type} | ||
| onValueChange={(value) => | ||
| setFeatureFlag({ | ||
| ...featureFlag, | ||
| type: value as FeatureFlag['type'], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 타입스크립트 공부 많이하셨군요. 여기서 조금 UX 관련해서 타입이 바뀌면 variations 도 다 없애거나 default 값들로 리셋을 해야하지 않을까 생각이 드는데 일단 이건 급한건 아니니깐 하셔도 되고 안하셔도 괜찮습니다 . |
||
| }) | ||
| } | ||
| > | ||
| <SelectTrigger> | ||
| <SelectValue placeholder="Select type" /> | ||
| </SelectTrigger> | ||
| <SelectContent> | ||
| <SelectItem value="Bool">Boolean</SelectItem> | ||
| <SelectItem value="Number">Number</SelectItem> | ||
| <SelectItem value="String">String</SelectItem> | ||
| </SelectContent> | ||
| </Select> | ||
| ) : ( | ||
| <Input id="type" value={featureFlag.type} readOnly /> | ||
| )} | ||
| </div> | ||
| <div> | ||
| <Label htmlFor="createdAt">Created At</Label> | ||
| <Input id="createdAt" value={featureFlag.createdAt} readOnly /> | ||
| </div> | ||
| <div> | ||
| <Label htmlFor="createdBy">Created By</Label> | ||
| <Input id="createdBy" value={featureFlag.createdBy} readOnly /> | ||
| </div> | ||
| <div className="flex items-center space-x-2"> | ||
| <Label htmlFor="status">Status</Label> | ||
| <Switch | ||
| id="status" | ||
| checked={featureFlag.enabled} | ||
| disabled={!isEditing} | ||
| onCheckedChange={(checked) => | ||
| setFeatureFlag({ ...featureFlag, enabled: checked }) | ||
| } | ||
| /> | ||
| </div> | ||
| </CardContent> | ||
| </Card> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| 'use client'; | ||
|
|
||
| import { PlusCircle, Trash2 } from 'lucide-react'; | ||
|
|
||
| import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; | ||
| import { | ||
| Table, | ||
| TableBody, | ||
| TableCell, | ||
| TableHead, | ||
| TableHeader, | ||
| TableRow, | ||
| } from '@/components/ui/table'; | ||
| import { Input } from '@/components/ui/input'; | ||
| import { Button } from '@/components/ui/button'; | ||
| import { FeatureFlag } from '@/types/featureFlag'; | ||
|
|
||
| interface VariationsTableProps { | ||
| featureFlag: FeatureFlag; | ||
| isEditing: boolean; | ||
| setFeatureFlag: (flag: FeatureFlag) => void; | ||
| } | ||
|
|
||
| export function VariationsTable({ | ||
| featureFlag, | ||
| isEditing, | ||
| setFeatureFlag, | ||
| }: VariationsTableProps) { | ||
| const handleVariationChange = ( | ||
| index: number, | ||
| key: keyof FeatureFlag['variations'][0], | ||
| value: string, | ||
| ) => { | ||
| const newVariations = [...featureFlag.variations]; | ||
| newVariations[index] = { ...newVariations[index], [key]: value }; | ||
| setFeatureFlag({ ...featureFlag, variations: newVariations }); | ||
| }; | ||
|
|
||
| const handleAddVariation = () => { | ||
| const newVariation = { | ||
| key: '', | ||
| value: | ||
| featureFlag.type === 'Bool' | ||
| ? false | ||
| : featureFlag.type === 'Number' | ||
| ? 0 | ||
| : '', | ||
| }; | ||
| setFeatureFlag({ | ||
| ...featureFlag, | ||
| variations: [...featureFlag.variations, newVariation], | ||
| }); | ||
| }; | ||
|
|
||
| const handleDeleteVariation = (index: number) => { | ||
| const updateVariations = featureFlag.variations.filter( | ||
| (_, i) => i !== index, | ||
| ); | ||
| setFeatureFlag({ ...featureFlag, variations: updateVariations }); | ||
| }; | ||
|
|
||
| return ( | ||
| <Card> | ||
| <CardHeader> | ||
| <CardTitle className="text-xl">Variations</CardTitle> | ||
| </CardHeader> | ||
| <CardContent> | ||
| <Table> | ||
| <TableHeader> | ||
| <TableRow> | ||
| <TableHead>Key</TableHead> | ||
| <TableHead>Value</TableHead> | ||
| {isEditing && ( | ||
| <TableHead className="w-[100px]">Actions</TableHead> | ||
| )} | ||
| </TableRow> | ||
| </TableHeader> | ||
| <TableBody> | ||
| {featureFlag.variations.map((variation, index) => ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| <TableRow key={index}> | ||
| <TableCell> | ||
| <Input | ||
| value={variation.key} | ||
| readOnly={!isEditing} | ||
| onChange={(e) => | ||
| handleVariationChange(index, 'key', e.target.value) | ||
| } | ||
| /> | ||
| </TableCell> | ||
| <TableCell> | ||
| <Input | ||
| value={variation.value.toString()} | ||
| readOnly={!isEditing} | ||
| onChange={(e) => | ||
| handleVariationChange(index, 'value', e.target.value) | ||
| } | ||
| /> | ||
| </TableCell> | ||
| {isEditing && ( | ||
| <TableCell> | ||
| <Button | ||
| variant="ghost" | ||
| size="sm" | ||
| onClick={() => handleDeleteVariation(index)} | ||
| > | ||
| <Trash2 className="size-4" /> | ||
| </Button> | ||
| </TableCell> | ||
| )} | ||
| </TableRow> | ||
| ))} | ||
| </TableBody> | ||
| </Table> | ||
|
|
||
| {isEditing && ( | ||
| <Button | ||
| variant="outline" | ||
| size="sm" | ||
| onClick={handleAddVariation} | ||
| className="mt-4" | ||
| > | ||
| <PlusCircle className="mr-2 size-4" /> | ||
| Add Variation | ||
| </Button> | ||
| )} | ||
| </CardContent> | ||
| </Card> | ||
| ); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
컴포넌트 잘 나누신것 같습니다.