Skip to content

Commit

Permalink
fix: updated select field with preference (#15805)
Browse files Browse the repository at this point in the history
* fix: updated select field with preference

* fix: linting issue

* Update Select.tsx

* Update CHANGELOG.md and optimise images

---------

Co-authored-by: Per Nielsen Tikær <[email protected]>
Co-authored-by: raycastbot <[email protected]>
  • Loading branch information
3 people authored Dec 18, 2024
1 parent cd98501 commit cd129b5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
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] - 2024-12-18

- Updated select field type with preference

## [Enhancements] - 2024-12-11

- Added support for rating field type
Expand Down
2 changes: 1 addition & 1 deletion extensions/twenty/src/components/FieldComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function FieldComponent({ values }: FieldComponentProps) {
return <TextInput values={{ field, placeholder: `Enter ${field.name}...` }} {...itemProps} />;
}
case "SELECT": {
return <Select values={{ field }} />;
return <Select values={{ field }} {...itemProps} />;
}
case "RATING": {
return <Rating values={{ field }} {...itemProps} />;
Expand Down
56 changes: 34 additions & 22 deletions extensions/twenty/src/components/Select.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Form } from "@raycast/api";
import React, { forwardRef } from "react";
import { Form, FormItemRef } from "@raycast/api";
import { DataModelField } from "../services/zod/schema/recordFieldSchema";
import { randomUUID } from "crypto";
import { optionIcons } from "../enum/icons";
Expand All @@ -7,29 +8,40 @@ type SelectProps = {
field: DataModelField;
};

const Select = ({ values }: { values: SelectProps }) => {
const { field } = values;
const { options } = field;
const defaultValue = field.defaultValue ? field.defaultValue.replace(/^'|'$/g, "") : "";
return (
<Form.Dropdown title={field.label} defaultValue={defaultValue} id={field.name}>
<Form.Dropdown.Item
key={randomUUID().toString()}
value={""}
title={`No ${field.label}`}
icon={optionIcons["white"]}
/>
{options?.map((option) => (
// Use forwardRef to allow ref forwarding
const Select = forwardRef<FormItemRef, { values: SelectProps } & React.ComponentProps<typeof Form.Dropdown>>(
({ values, ...rest }, ref) => {
const { field } = values;
const { options } = field;
const defaultValue = field.defaultValue ? field.defaultValue.replace(/^'|'$/g, "") : "";
const { id, value, ...modifiedRest } = rest; // eslint-disable-line @typescript-eslint/no-unused-vars

return (
<Form.Dropdown
title={field.label}
defaultValue={defaultValue}
id={field.name}
ref={ref as React.Ref<FormItemRef>}
{...modifiedRest}
>
<Form.Dropdown.Item
key={option.id}
value={option.value ?? ""}
title={option.label ?? ""}
icon={optionIcons[option?.color ?? ""] ?? undefined}
key={randomUUID().toString()}
value={""}
title={`No ${field.label}`}
icon={optionIcons["white"]}
/>
))}
</Form.Dropdown>
);
};
{options?.map((option) => (
<Form.Dropdown.Item
key={option.id}
value={option.value ?? ""}
title={option.label ?? ""}
icon={optionIcons[option?.color ?? ""] ?? undefined}
/>
))}
</Form.Dropdown>
);
},
);

// Set display name for better debugging
Select.displayName = "Select";
Expand Down

0 comments on commit cd129b5

Please sign in to comment.