Skip to content

Commit

Permalink
Allowed mimetype and title params for table creation (#9016)
Browse files Browse the repository at this point in the history
* Allowed mimetype and title params for table creation

* Modified swagger to include new types, and have title and name always have the same value (title overrides)

* Updated /tables post swagger

* removed default mimeType value

* Fixed callback deps warning

* Enforce that table id is in parent in first position, even when provided

* Allowing different values for title and names in api endpoints

* tested and works as expected, removing forbidden field from swagger

---------

Co-authored-by: Lucas <[email protected]>
  • Loading branch information
overmode and Lucas authored Dec 3, 2024
1 parent 0ed2caf commit c5c0203
Show file tree
Hide file tree
Showing 8 changed files with 196 additions and 7 deletions.
3 changes: 3 additions & 0 deletions front/components/data_source/TableUploadOrEditModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ export const TableUploadOrEditModal = ({
truncate: true,
async: false,
useAppForHeaderDetection,
title: table.name,
mimeType: tableState.file?.type ?? "text/csv",
};
let upsertRes = null;
if (initialId) {
Expand Down Expand Up @@ -184,6 +186,7 @@ export const TableUploadOrEditModal = ({
doUpdate,
fileUploaderService,
useAppForHeaderDetection,
tableState.file?.type,
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import { apiError } from "@app/logger/withlogging";
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Datasource'
* $ref: '#/components/schemas/Table'
* 404:
* description: The table was not found
* 405:
Expand Down Expand Up @@ -205,6 +205,8 @@ async function handler(
timestamp: table.timestamp,
tags: table.tags,
parents: table.parents,
mime_type: table.mime_type,
title: table.title,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ async function handler(
}
const upsertRes = await handleDataSourceTableCSVUpsert({
auth,
params: r.data,
params: {
...r.data,
mimeType: r.data.mimeType,
title: r.data.title ?? r.data.name,
},
dataSource,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import { apiError } from "@app/logger/withlogging";
* schema:
* type: array
* items:
* $ref: '#/components/schemas/Datasource'
* $ref: '#/components/schemas/Table'
* 400:
* description: Invalid request
* post:
Expand Down Expand Up @@ -92,6 +92,9 @@ import { apiError } from "@app/logger/withlogging";
* name:
* type: string
* description: Name of the table
* title:
* type: string
* description: Title of the table
* table_id:
* type: string
* description: Unique identifier for the table
Expand Down Expand Up @@ -226,6 +229,8 @@ async function handler(
timestamp: table.timestamp,
tags: table.tags,
parents: table.parents,
mime_type: table.mime_type,
title: table.title,
};
}),
});
Expand Down Expand Up @@ -345,6 +350,12 @@ async function handler(
});
}

// Enforce that the table is a parent of itself by default.
const parentsWithTableId =
parents?.includes(tableId) && parents[0] === tableId
? parents
: [tableId, ...(parents || []).filter((p) => p !== tableId)];

const upsertRes = await coreAPI.upsertTable({
projectId: dataSource.dustAPIProjectId,
dataSourceId: dataSource.dustAPIDataSourceId,
Expand All @@ -353,7 +364,8 @@ async function handler(
description,
timestamp: timestamp ?? null,
tags: tags || [],
parents: parents || [],
// Table is a parent of itself by default.
parents: parentsWithTableId,
remoteDatabaseTableId: remoteDatabaseTableId ?? null,
remoteDatabaseSecretId: remoteDatabaseSecretId ?? null,
title,
Expand Down Expand Up @@ -394,6 +406,8 @@ async function handler(
timestamp: table.timestamp,
tags: table.tags,
parents: table.parents,
mime_type: table.mime_type,
title: table.title,
},
});

Expand Down
61 changes: 61 additions & 0 deletions front/pages/api/v1/w/[wId]/swagger_schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,67 @@
* type: boolean
* description: Whether this datasource is selected by default for assistants
* example: true
* Table:
* type: object
* properties:
* name:
* type: string
* description: Name of the table
* example: "Roi data"
* deprecated: true
* title:
* type: string
* description: Title of the table
* example: "ROI Data"
* table_id:
* type: string
* description: Unique identifier for the table
* example: "1234f4567c"
* description:
* type: string
* description: Description of the table
* example: "roi data for Q1"
* mime_type:
* type: string
* description: MIME type of the table
* example: "text/csv"
* schema:
* type: array
* description: Array of column definitions
* items:
* type: object
* properties:
* name:
* type: string
* description: Name of the column
* example: "roi"
* value_type:
* type: string
* description: Data type of the column
* enum: [text, int, float, bool, date]
* example: "int"
* possible_values:
* type: array
* description: Array of possible values for the column (null if unrestricted)
* items:
* type: string
* nullable: true
* example: ["1", "2", "3"]
* timestamp:
* type: number
* description: Unix timestamp of table creation/modification
* example: 1732810375150
* tags:
* type: array
* description: Array of tags associated with the table
* items:
* type: string
* parents:
* type: array
* description: Array of parent table IDs
* items:
* type: string
* example: ["1234f4567c"]
* DatasourceView:
* type: object
* properties:
Expand Down
107 changes: 104 additions & 3 deletions front/public/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2571,7 +2571,7 @@
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Datasource"
"$ref": "#/components/schemas/Table"
}
}
}
Expand Down Expand Up @@ -3065,7 +3065,7 @@
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Datasource"
"$ref": "#/components/schemas/Table"
}
}
}
Expand Down Expand Up @@ -3125,7 +3125,16 @@
"properties": {
"name": {
"type": "string",
"description": "Name of the table"
"description": "Name of the table",
"deprecated": true
},
"title": {
"type": "string",
"description": "Title of the table"
},
"mime_type": {
"type": "string",
"description": "Mime type of the table"
},
"table_id": {
"type": "string",
Expand Down Expand Up @@ -3957,6 +3966,98 @@
}
}
},
"Table": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Name of the table",
"example": "Roi data",
"deprecated": true
},
"title": {
"type": "string",
"description": "Title of the table",
"example": "ROI Data"
},
"table_id": {
"type": "string",
"description": "Unique identifier for the table",
"example": "1234f4567c"
},
"description": {
"type": "string",
"description": "Description of the table",
"example": "roi data for Q1"
},
"mime_type": {
"type": "string",
"description": "MIME type of the table",
"example": "text/csv"
},
"schema": {
"type": "array",
"description": "Array of column definitions",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "Name of the column",
"example": "roi"
},
"value_type": {
"type": "string",
"description": "Data type of the column",
"enum": [
"text",
"int",
"float",
"bool",
"date"
],
"example": "int"
},
"possible_values": {
"type": "array",
"description": "Array of possible values for the column (null if unrestricted)",
"items": {
"type": "string"
},
"nullable": true,
"example": [
"1",
"2",
"3"
]
}
}
}
},
"timestamp": {
"type": "number",
"description": "Unix timestamp of table creation/modification",
"example": 1732810375150
},
"tags": {
"type": "array",
"description": "Array of tags associated with the table",
"items": {
"type": "string"
}
},
"parents": {
"type": "array",
"description": "Array of parent table IDs",
"items": {
"type": "string"
},
"example": [
"1234f4567c"
]
}
}
},
"DatasourceView": {
"type": "object",
"properties": {
Expand Down
2 changes: 2 additions & 0 deletions sdks/js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ const CoreAPITablePublicSchema = z.object({
timestamp: z.number(),
tags: z.array(z.string()),
parents: z.array(z.string()),
mime_type: z.string().optional(),
title: z.string().optional(),
});

export type CoreAPITablePublic = z.infer<typeof CoreAPITablePublicSchema>;
Expand Down
2 changes: 2 additions & 0 deletions types/src/front/lib/core_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ export type CoreAPITable = {
parents: string[];
created: number;
data_source_id: string;
title: string;
mime_type: string;
remote_database_table_id: string | null;
remote_database_secret_id: string | null;
};
Expand Down

0 comments on commit c5c0203

Please sign in to comment.