More typings

This commit is contained in:
Adria Navarro 2024-12-23 19:44:40 +01:00
parent 32bba9b1ab
commit 26d1243e68
3 changed files with 29 additions and 10 deletions

View File

@ -4,8 +4,11 @@ import { enrichSchemaWithRelColumns, memo } from "../../../utils"
import { cloneDeep } from "lodash" import { cloneDeep } from "lodash"
import { import {
FieldSchema, FieldSchema,
Row,
SaveRowRequest,
SaveTableRequest, SaveTableRequest,
UIDatasource, UIDatasource,
UIFieldMutation,
UIFieldSchema, UIFieldSchema,
UpdateViewRequest, UpdateViewRequest,
ViewV2Type, ViewV2Type,
@ -211,7 +214,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => {
} }
// Updates the datasources primary display column // Updates the datasources primary display column
const changePrimaryDisplay = async column => { const changePrimaryDisplay = async (column: string) => {
let newDefinition = cloneDeep(get(definition)) let newDefinition = cloneDeep(get(definition))
// Update primary display // Update primary display
@ -227,7 +230,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => {
} }
// Adds a schema mutation for a single field // Adds a schema mutation for a single field
const addSchemaMutation = (field, mutation) => { const addSchemaMutation = (field: string, mutation: UIFieldMutation) => {
if (!field || !mutation) { if (!field || !mutation) {
return return
} }
@ -243,7 +246,11 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => {
} }
// Adds a nested schema mutation for a single field // Adds a nested schema mutation for a single field
const addSubSchemaMutation = (field, fromField, mutation) => { const addSubSchemaMutation = (
field: string,
fromField: string,
mutation: UIFieldMutation
) => {
if (!field || !fromField || !mutation) { if (!field || !fromField || !mutation) {
return return
} }
@ -305,32 +312,32 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => {
} }
// Adds a row to the datasource // Adds a row to the datasource
const addRow = async row => { const addRow = async (row: SaveRowRequest) => {
return await getAPI()?.actions.addRow(row) return await getAPI()?.actions.addRow(row)
} }
// Updates an existing row in the datasource // Updates an existing row in the datasource
const updateRow = async row => { const updateRow = async (row: SaveRowRequest) => {
return await getAPI()?.actions.updateRow(row) return await getAPI()?.actions.updateRow(row)
} }
// Deletes rows from the datasource // Deletes rows from the datasource
const deleteRows = async rows => { const deleteRows = async (rows: Row[]) => {
return await getAPI()?.actions.deleteRows(rows) return await getAPI()?.actions.deleteRows(rows)
} }
// Gets a single row from a datasource // Gets a single row from a datasource
const getRow = async id => { const getRow = async (id: string) => {
return await getAPI()?.actions.getRow(id) return await getAPI()?.actions.getRow(id)
} }
// Checks if a certain datasource config is valid // Checks if a certain datasource config is valid
const isDatasourceValid = datasource => { const isDatasourceValid = (datasource: UIDatasource) => {
return getAPI()?.actions.isDatasourceValid(datasource) return getAPI()?.actions.isDatasourceValid(datasource)
} }
// Checks if this datasource can use a specific column by name // Checks if this datasource can use a specific column by name
const canUseColumn = name => { const canUseColumn = (name: string) => {
return getAPI()?.actions.canUseColumn(name) return getAPI()?.actions.canUseColumn(name)
} }

View File

@ -14,7 +14,14 @@ const columnTypeManyTypeOverrides = {
} }
const columnTypeManyParser = { const columnTypeManyParser = {
[FieldType.DATETIME]: (value: any[], field: any) => { [FieldType.DATETIME]: (
value: any[],
field: {
timeOnly?: boolean
dateOnly?: boolean
ignoreTimezones?: boolean
}
) => {
function parseDate(value: any) { function parseDate(value: any) {
const { timeOnly, dateOnly, ignoreTimezones } = field || {} const { timeOnly, dateOnly, ignoreTimezones } = field || {}
const enableTime = !dateOnly const enableTime = !dateOnly

View File

@ -10,3 +10,8 @@ export interface UIDatasource {
} }
queryUI: any // TODO queryUI: any // TODO
} }
export interface UIFieldMutation {
visible: boolean
readonly?: boolean
}