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 support for multi-select field type #16080

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 4 additions & 0 deletions extensions/twenty/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Twenty Changelog

## [Enhancements] - {PR_MERGE_DATE}

- Added support for multi-select field type

## [Enhancements] - 2024-12-18

- Updated select field type with preference
Expand Down
7 changes: 7 additions & 0 deletions extensions/twenty/src/components/FieldComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { DataModelField } from "../services/zod/schema/recordFieldSchema";
import TextInput from "./TextInput";
import Select from "./Select";
import Rating from "./Rating";
import MultiSelect from "./MultiSelect";

type FieldComponentProps = {
values: {
Expand All @@ -25,6 +26,12 @@ export default function FieldComponent({ values }: FieldComponentProps) {
case "RATING": {
return <Rating values={{ field }} {...itemProps} />;
}
case "MULTI_SELECT": {
return <MultiSelect values={{ field }} {...itemProps} />;
}
// case "MULTI_SELECT": {
// return <MultiSelect values={{ field }} />;
Copy link
Contributor

Choose a reason for hiding this comment

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

@GeniusNirmit remove this commented code.

// }
default:
return <></>;
}
Expand Down
48 changes: 48 additions & 0 deletions extensions/twenty/src/components/MultiSelect.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React, { forwardRef } from "react";
import { Form, FormItemRef } from "@raycast/api";
import { DataModelField } from "../services/zod/schema/recordFieldSchema";
import { optionIcons } from "../enum/icons";

type MultiSelectProps = {
field: DataModelField;
};

// Use forwardRef for consistency and ref handling
const MultiSelect = forwardRef<FormItemRef, { values: MultiSelectProps } & React.ComponentProps<typeof Form.TagPicker>>(
({ values, ...rest }, ref) => {
const { field } = values;
const { options } = field;

const defaultValue = Array.isArray(field.defaultValue)
? field.defaultValue.map((value) => value.replace(/^'|'$/g, "").trim())
: field.defaultValue
? [field.defaultValue.replace(/^'|'$/g, "").trim()]
: [];

const { id, value, ...modifiedRest } = rest; // eslint-disable-line @typescript-eslint/no-unused-vars

return (
<Form.TagPicker
title={field.label}
defaultValue={defaultValue}
id={field.name}
ref={ref as React.Ref<FormItemRef>}
Copy link
Contributor

Choose a reason for hiding this comment

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

@GeniusNirmit Here add placeholder Select ${field.name}.... see TextInput Field for reference.

{...modifiedRest}
>
{options?.map((option) => (
<Form.TagPicker.Item
key={option.id}
value={option.value ?? ""}
title={option.label ?? ""}
icon={optionIcons[option?.color ?? ""] ?? undefined}
/>
))}
</Form.TagPicker>
);
},
);

// Set display name for better debugging
MultiSelect.displayName = "MultiSelect";

export default MultiSelect;
6 changes: 6 additions & 0 deletions extensions/twenty/src/helper/formatValues.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ export function formatValues(values: Record<string, any>, objectRecordMetadata:
}
break;
}
case "MULTI_SELECT": {
if (formattedValues[key] === "") {
formattedValues[key] = null;
}
break;
}
default:
break;
}
Expand Down
Loading