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

External link display option to data table #70

Merged
merged 9 commits into from
Apr 29, 2024
2 changes: 2 additions & 0 deletions src/components/DataTable/DataTableRowActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { DynamicActionComponent } from "./DynamicActionComponent";
export const DataTableRowActions = ({ row, column }) => {
const actions = row.original.actions || column.columnDef.actions;

if (!actions?.length) return null;

return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
Expand Down
12 changes: 12 additions & 0 deletions src/components/DataTable/SWRDataTable/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ export const renderDataTableCell = ({ filters, column, row, selectedRows }) => {
);
case "select":
return value;
case "external_link":
return (
<a
href={value}
target="_blank"
rel="noreferrer"
className="underline text-primary flex items-center"
>
<Trans>Open</Trans>&nbsp;
<span>{column.columnDef.title}</span>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#could use radix's external link or link2: https://www.radix-ui.com/icons
Screenshot 2024-04-29 at 9 36 15 AM
Screenshot 2024-04-29 at 9 36 10 AM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#would add tooltip

</a>
);
default:
return null;
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/FormBuilder/fields/CheckboxField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from "#/components/ui/Form";

import { BaseField, withConditional } from "../fields";
import isFieldDisabled from "../isFieldDisabled";

export interface CheckboxFieldProps extends BaseField {
type: "checkbox";
Expand All @@ -31,6 +32,7 @@ export const CheckboxField = withConditional<CheckboxFieldProps>(
<Checkbox
checked={formField.value}
onCheckedChange={formField.onChange}
disabled={isFieldDisabled(form, field)}
/>
</FormControl>
<div className="space-y-1 leading-none">
Expand Down
1 change: 1 addition & 0 deletions src/components/FormBuilder/fields/DatePickerInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const DatePickerInput = withConditional<DatePickerInputProps>(
control={form.control}
name={field.name}
rules={field.required ? { required: true } : undefined}
defaultValue={field.defaultValue}
render={({ field: formField }) => (
<FormItem className="flex flex-col">
<FormLabel tooltip={field.tooltip}>{field.label}</FormLabel>
Expand Down
13 changes: 6 additions & 7 deletions src/components/FormBuilder/fields/FieldArray.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,7 @@ export const FieldArray = withConditional<FieldArrayFieldProps>(
<DragDropContext onDragEnd={handleDrag}>
<ul>
<StrictModeDroppable droppableId={`${field.name}-items`}>
{/* eslint-disable-next-line no-shadow, @typescript-eslint/no-unused-vars */}
{(provided, snapshot) => (
{(provided) => (
<div {...provided.droppableProps} ref={provided.innerRef}>
{fields.map((rhfField, index) => {
// @ts-expect-error
Expand All @@ -139,11 +138,10 @@ export const FieldArray = withConditional<FieldArrayFieldProps>(
draggableId={`item-${index}`}
index={index}
>
{/* eslint-disable-next-line no-shadow, @typescript-eslint/no-unused-vars */}
{(provided, snapshot) => (
{(innerProvided) => (
<li
ref={provided.innerRef}
{...provided.draggableProps}
ref={innerProvided.innerRef}
{...innerProvided.draggableProps}
className="mb-3"
>
<div
Expand All @@ -152,7 +150,7 @@ export const FieldArray = withConditional<FieldArrayFieldProps>(
{field.hasSequence && (
<div
className="flex h-full w-6 flex-col justify-center"
{...provided.dragHandleProps}
{...innerProvided.dragHandleProps}
>
<MoveIcon className="size-6 self-center" />
</div>
Expand All @@ -167,6 +165,7 @@ export const FieldArray = withConditional<FieldArrayFieldProps>(
// eslint-disable-next-line jsx-a11y/control-has-associated-label
<button
type="button"
data-testid="remove-button"
onClick={() => handleRemove(Number(index))}
className="mt-4"
>
Expand Down
6 changes: 3 additions & 3 deletions src/components/FormBuilder/fields/HiddenField.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { FormControl, FormField } from "#/components/ui/Form";
import { FormField, FormItem } from "#/components/ui/Form";

import { withConditional } from "../fields";

Expand All @@ -9,9 +9,9 @@ export const HiddenField = withConditional(({ form, field }) => (
name={field.name}
defaultValue={field.value}
render={({ field: formField }) => (
<FormControl>
<FormItem>
<input type="hidden" {...formField} />
</FormControl>
</FormItem>
)}
/>
));
1 change: 1 addition & 0 deletions src/components/FormBuilder/fields/InputField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const InputField = withConditional<InputFieldProps>(
}
: undefined
}
defaultValue={field.defaultValue}
render={({ field: formField }) => (
<FormItem className="w-full">
<FormLabel tooltip={field.tooltip}>{field.label}</FormLabel>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import {
import { withConditional } from "../fields";
import { SelectFieldProps } from "./selects/SelectField";

export interface MultiSelectCheckboxesField extends SelectFieldProps {
export interface MultiSelectCheckboxesFieldProps extends SelectFieldProps {
type: "multi_select_checkbox";
}

export const MultiSelectCheckboxes =
withConditional<MultiSelectCheckboxesField>(({ form, field }) => (
withConditional<MultiSelectCheckboxesFieldProps>(({ form, field }) => (
<FormField
control={form.control}
name={field.name}
Expand Down
2 changes: 2 additions & 0 deletions src/components/FormBuilder/fields/TextAreaField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { Textarea } from "#/components/ui/Textarea";

import { BaseField, withConditional } from "../fields";
import isFieldDisabled from "../isFieldDisabled";

export interface TextAreaFieldProps extends BaseField {
length?: {
Expand Down Expand Up @@ -47,6 +48,7 @@ export const TextAreaField = withConditional<TextAreaFieldProps>(
<FormDescription>{field.description}</FormDescription>
<FormControl>
<Textarea
disabled={isFieldDisabled(form, field)}
placeholder={field.placeholder}
className="resize-none"
{...formField}
Expand Down
80 changes: 37 additions & 43 deletions src/components/FormBuilder/fields/selects/SelectField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import * as Select from "#/components/ui/Select";

import { BaseField, withConditional } from "../../fields";
import isFieldDisabled from "../../isFieldDisabled";

export interface SelectFieldProps extends BaseField {
options?: Array<{
Expand All @@ -20,48 +21,41 @@ export interface SelectFieldProps extends BaseField {
}

export const SelectField = withConditional<SelectFieldProps>(
({ form, field }) => {
const disabled =
typeof field.disabled === "function"
? field.disabled(form.getValues())
: field.disabled;
({ form, field }) => (
<FormField
control={form.control}
name={field.name}
rules={field.required ? { required: true } : undefined}
render={({ field: formField }) => (
<FormItem className="w-full">
<FormLabel tooltip={field.tooltip}>{field.label}</FormLabel>
<FormDescription>{field.description}</FormDescription>
<Select.SelectRoot
onValueChange={formField.onChange}
defaultValue={String(formField.value)}
name={field.name}
disabled={isFieldDisabled(form, field)}
>
<FormControl>
<Select.SelectTrigger className="h-10 w-full rounded-md border dark:border-2 shadow-none">
<Select.SelectValue placeholder={field.placeholder} />
</Select.SelectTrigger>
</FormControl>
<Select.SelectContent className="z-[10000]">
{field.options?.map((option) => (
<Select.SelectItem
key={String(option.value)}
value={String(option.value)}
>
{option.label}
</Select.SelectItem>
))}
</Select.SelectContent>
</Select.SelectRoot>

return (
<FormField
control={form.control}
name={field.name}
rules={field.required ? { required: true } : undefined}
render={({ field: formField }) => (
<FormItem className="w-full">
<FormLabel tooltip={field.tooltip}>{field.label}</FormLabel>
<FormDescription>{field.description}</FormDescription>
<Select.SelectRoot
onValueChange={formField.onChange}
defaultValue={String(formField.value)}
name={field.name}
disabled={disabled}
>
<FormControl>
<Select.SelectTrigger className="h-10 w-full rounded-md border dark:border-2 shadow-none">
<Select.SelectValue placeholder={field.placeholder} />
</Select.SelectTrigger>
</FormControl>
<Select.SelectContent className="z-[10000]">
{field.options?.map((option) => (
<Select.SelectItem
key={String(option.value)}
value={String(option.value)}
>
{option.label}
</Select.SelectItem>
))}
</Select.SelectContent>
</Select.SelectRoot>

<FormMessage />
</FormItem>
)}
/>
);
}
<FormMessage />
</FormItem>
)}
/>
)
);
12 changes: 12 additions & 0 deletions src/components/FormBuilder/isFieldDisabled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { CommonFieldProps, FormFieldProps } from "./fields";

type FieldProps = CommonFieldProps<FormFieldProps>;

export default function isFieldDisabled(
form: FieldProps["form"],
field: FieldProps["field"]
) {
return typeof field.disabled === "function"
? field.disabled(form.getValues())
: field.disabled;
}
5 changes: 4 additions & 1 deletion src/components/RichTextEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import React, { Suspense, lazy } from "react";
import { Trans, useTranslation } from "react-i18next";
import { useTheme } from "#/components/ThemeToggle/context";

const JoditEditor = lazy(() => import("jodit-react"));
const JoditEditor = lazy(async () => {
const module = await import("jodit-react");
return { default: module.default };
});

const EDITOR_BUTTONS = [
"undo",
Expand Down
14 changes: 12 additions & 2 deletions src/components/SectionTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import React from "react";
import { cn } from "#/lib/utils";

type SectionTitleProps = {
children: React.ReactNode;
className?: string;
};

export const SectionTitle: React.FC<SectionTitleProps> = ({ children }) => (
<h2 className="pt-8 text-2xl font-bold tracking-tigh text-foreground">
export const SectionTitle: React.FC<SectionTitleProps> = ({
children,
className,
}) => (
<h2
className={cn(
"pt-8 text-2xl font-bold tracking-tigh text-foreground",
className
)}
>
{children}
</h2>
);
Loading