Skip to content

Commit

Permalink
[front] - fix: ensure type safety and null checks in data sources tables
Browse files Browse the repository at this point in the history
 - Introduced a new TypeScript interface to improve type checking for the cell rendering functions in data source tables
 - Added null checks for the `editedByUser` field and fallbacks for missing `imageUrl` and `editedAt` properties to prevent runtime errors
 - Ensured the display of formatted dates accounts for possible null values in `editedAt` field
  • Loading branch information
Jules authored and Jules committed Jul 31, 2024
1 parent 8d0c97d commit d7b1fd2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
29 changes: 21 additions & 8 deletions front/pages/w/[wId]/builder/data-sources/public-urls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type {
import { ConnectorsAPI } from "@dust-tt/types";
import type { InferGetServerSidePropsType } from "next";
import { useRouter } from "next/router";
import type { ComponentType } from "react";
import { useMemo, useRef, useState } from "react";
import * as React from "react";

Expand Down Expand Up @@ -233,11 +234,19 @@ export default function DataSourcesView({
}

function getTableColumns() {
// to please typescript
type OriginalType = DataSourceType & {
icon: ComponentType;
usage: number;
};
interface Info {
row: { original: OriginalType };
}
return [
{
header: "Name",
accessorKey: "name",
cell: (info) => (
cell: (info: Info) => (
<TableData.Cell icon={info.row.original.icon}>
{info.row.original.name}
</TableData.Cell>
Expand All @@ -246,26 +255,30 @@ function getTableColumns() {
{
header: "Used by",
accessorKey: "usage",
cell: (info) => (
cell: (info: Info) => (
<TableData.Cell icon={RobotIcon}>
{info.row.original.usage}
</TableData.Cell>
),
},
{
header: "Added by",
cell: (info) => (
<TableData.Cell avatarUrl={info.row.original.editedByUser.imageUrl} />
cell: (info: Info) => (
<TableData.Cell
avatarUrl={info.row.original.editedByUser?.imageUrl ?? ""}
/>
),
},
{
header: "Last updated",
accessorKey: "editedByUser.editedAt",
cell: (info) => (
cell: (info: Info) => (
<TableData.Cell>
{new Date(
info.row.original.editedByUser.editedAt
).toLocaleDateString()}
{info.row.original.editedByUser?.editedAt
? new Date(
info.row.original.editedByUser.editedAt
).toLocaleDateString()
: null}
</TableData.Cell>
),
},
Expand Down
29 changes: 21 additions & 8 deletions front/pages/w/[wId]/builder/data-sources/static.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type { DataSourceType, WorkspaceType } from "@dust-tt/types";
import type { PlanType, SubscriptionType } from "@dust-tt/types";
import type { InferGetServerSidePropsType } from "next";
import { useRouter } from "next/router";
import type { ComponentType } from "react";
import { useMemo, useRef, useState } from "react";
import * as React from "react";

Expand Down Expand Up @@ -189,11 +190,19 @@ export default function DataSourcesView({
}

function getTableColumns() {
// to please typescript
type OriginalType = DataSourceType & {
icon: ComponentType;
usage: number;
};
interface Info {
row: { original: OriginalType };
}
return [
{
header: "Name",
accessorKey: "name",
cell: (info) => (
cell: (info: Info) => (
<TableData.Cell icon={info.row.original.icon}>
{info.row.original.name}
</TableData.Cell>
Expand All @@ -202,26 +211,30 @@ function getTableColumns() {
{
header: "Used by",
accessorKey: "usage",
cell: (info) => (
cell: (info: Info) => (
<TableData.Cell icon={RobotIcon}>
{info.row.original.usage}
</TableData.Cell>
),
},
{
header: "Added by",
cell: (info) => (
<TableData.Cell avatarUrl={info.row.original.editedByUser.imageUrl} />
cell: (info: Info) => (
<TableData.Cell
avatarUrl={info.row.original.editedByUser?.imageUrl ?? ""}
/>
),
},
{
header: "Last updated",
accessorKey: "editedByUser.editedAt",
cell: (info) => (
cell: (info: Info) => (
<TableData.Cell>
{new Date(
info.row.original.editedByUser.editedAt
).toLocaleDateString()}
{info.row.original.editedByUser?.editedAt
? new Date(
info.row.original.editedByUser.editedAt
).toLocaleDateString()
: null}
</TableData.Cell>
),
},
Expand Down

0 comments on commit d7b1fd2

Please sign in to comment.