Skip to content

Commit dfee340

Browse files
committed
Improve null handling for object properties and types
1 parent 6f61914 commit dfee340

4 files changed

Lines changed: 11 additions & 8 deletions

File tree

src/components/UpdateForm/UpdateObjectForm.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export function UpdateObjectForm({ spaceId, object, mutateObjects, mutateObject
3636
const { pop } = useNavigation();
3737
const [objectSearchText, setObjectSearchText] = useState("");
3838

39-
const properties = object.type.properties.filter((p) => !Object.values(bundledPropKeys).includes(p.key));
39+
const properties = object.type?.properties.filter((p) => !Object.values(bundledPropKeys).includes(p.key)) ?? [];
4040
const numberFieldValidations = useMemo(() => getNumberFieldValidations(properties), [properties]);
4141

4242
const { objects, objectsError, isLoadingObjects } = useSearch(spaceId, objectSearchText, []);
@@ -218,7 +218,7 @@ export function UpdateObjectForm({ spaceId, object, mutateObjects, mutateObject
218218

219219
return (
220220
<Form
221-
navigationTitle={`Edit ${object.type.name}`}
221+
navigationTitle={`Edit ${object.type?.name ?? "Object"}`}
222222
isLoading={isLoadingObjects || isLoadingTags}
223223
actions={
224224
<ActionPanel>

src/mappers/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ export async function mapTypes(types: RawType[]): Promise<Type[]> {
1515
/**
1616
* Map raw `Type` object from the API into display-ready data (e.g., icon).
1717
*/
18-
export async function mapType(type: RawType): Promise<Type> {
19-
// Handle deleted types
18+
export async function mapType(type: RawType | null): Promise<Type> {
2019
if (!type || !type.id) {
2120
return {
2221
object: "type",

src/models/object.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ export interface RawSpaceObject {
3535
object: string;
3636
id: string;
3737
name: string;
38-
icon: ObjectIcon;
39-
type: RawType;
38+
icon: ObjectIcon | null;
39+
type: RawType | null;
4040
snippet: string;
4141
layout: ObjectLayout;
4242
space_id: string;

src/utils/icon.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ import { colorToHex, iconWidth } from "./constant";
1010
* @param type The type of the object .
1111
* @returns The base64 data URI or Raycast Icon.
1212
*/
13-
export async function getIconWithFallback(icon: ObjectIcon, layout: string, type?: RawType): Promise<Image.ImageLike> {
13+
export async function getIconWithFallback(
14+
icon: ObjectIcon | null,
15+
layout: string,
16+
type?: RawType | null,
17+
): Promise<Image.ImageLike> {
1418
if (icon && icon.format) {
1519
// type built-in icons
1620
if (icon.format === IconFormat.Icon && icon.name) {
@@ -32,7 +36,7 @@ export async function getIconWithFallback(icon: ObjectIcon, layout: string, type
3236
}
3337

3438
// fallback to grey version of type built-in icon
35-
if (type?.icon && type.icon.format === IconFormat.Icon && type.icon.name) {
39+
if (type && type.icon && type.icon.format === IconFormat.Icon && type.icon.name) {
3640
return getCustomTypeIcon(type.icon.name, "grey");
3741
}
3842

0 commit comments

Comments
 (0)