Skip to content

Commit 5809c25

Browse files
committed
feat: Collapse db and expiration by default
https://harperdb.atlassian.net/browse/STUDIO-463
1 parent 7efff58 commit 5809c25

File tree

10 files changed

+281
-189
lines changed

10 files changed

+281
-189
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { FormControl } from '@/components/ui/form/FormControl';
2+
import { FormDescription } from '@/components/ui/form/FormDescription';
3+
import { FormItem } from '@/components/ui/form/FormItem';
4+
import { FormLabel } from '@/components/ui/form/FormLabel';
5+
import { FormMessage } from '@/components/ui/form/FormMessage';
6+
import { Input } from '@/components/ui/input';
7+
import { useToggler } from '@/hooks/useToggler';
8+
import { cx } from 'class-variance-authority';
9+
import { ArrowDownIcon, ArrowRightIcon } from 'lucide-react';
10+
import { ControllerRenderProps } from 'react-hook-form';
11+
import { z } from 'zod';
12+
import { newTableSchema } from './newTableSchema';
13+
14+
export function DatabaseName(
15+
{ field }: { field: ControllerRenderProps<z.infer<typeof newTableSchema>, 'databaseName'> },
16+
) {
17+
const { toggled, toggle } = useToggler(false);
18+
return (
19+
<FormItem className="my-4">
20+
<FormLabel
21+
onClick={toggle}
22+
className={cx(
23+
'flex items-center gap-2',
24+
toggled ? '' : 'text-muted-foreground italic',
25+
)}
26+
>
27+
{toggled ? <ArrowDownIcon /> : <ArrowRightIcon />} Optional Database Name
28+
</FormLabel>
29+
<FormDescription className={toggled ? '' : 'hidden'}>"data" is the default recommended name</FormDescription>
30+
<FormControl className={toggled ? '' : 'hidden'}>
31+
<Input type="text" className="my-1" {...field} />
32+
</FormControl>
33+
<FormMessage />
34+
</FormItem>
35+
);
36+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { FormControl } from '@/components/ui/form/FormControl';
2+
import { FormDescription } from '@/components/ui/form/FormDescription';
3+
import { FormItem } from '@/components/ui/form/FormItem';
4+
import { FormLabel } from '@/components/ui/form/FormLabel';
5+
import { FormMessage } from '@/components/ui/form/FormMessage';
6+
import { Input } from '@/components/ui/input';
7+
import { useToggler } from '@/hooks/useToggler';
8+
import { cx } from 'class-variance-authority';
9+
import { ArrowDownIcon, ArrowRightIcon } from 'lucide-react';
10+
import { ChangeEvent, useCallback } from 'react';
11+
import { ControllerRenderProps } from 'react-hook-form';
12+
import { z } from 'zod';
13+
import { newTableSchema } from './newTableSchema';
14+
15+
export function OptionalExpiration(
16+
{ field }: { field: ControllerRenderProps<z.infer<typeof newTableSchema>, 'expiration'> },
17+
) {
18+
const { toggled, toggle } = useToggler(false);
19+
const onChange = useCallback(
20+
(e: ChangeEvent<HTMLInputElement>) =>
21+
field.onChange(e.target.value ? parseInt(e.target.value, 10) : e.target.value),
22+
[],
23+
);
24+
return (
25+
<FormItem className="my-4">
26+
<FormLabel
27+
onClick={toggle}
28+
className={cx(
29+
'flex items-center gap-2',
30+
toggled ? '' : 'text-muted-foreground italic',
31+
)}
32+
>
33+
{toggled ? <ArrowDownIcon /> : <ArrowRightIcon />} Optional Expiration
34+
</FormLabel>
35+
<FormDescription className={toggled ? '' : 'hidden'}>
36+
After how many seconds should records be automatically evicted? Leave blank or set to 0 to skip this feature.
37+
(It can be useful for cache records.)
38+
</FormDescription>
39+
<FormControl className={toggled ? '' : 'hidden'}>
40+
<Input {...field} type="number" min={0} step={1} className="my-1" onChange={onChange} />
41+
</FormControl>
42+
<FormMessage />
43+
</FormItem>
44+
);
45+
}

0 commit comments

Comments
 (0)