eric-briscoe commented on code in PR #21948: URL: https://github.com/apache/superset/pull/21948#discussion_r1019669441
########## superset-frontend/src/views/CRUD/data/dataset/AddDataset/DatasetPanel/types.ts: ########## @@ -0,0 +1,92 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * Interface for table columns dataset + */ +export interface ITableColumn { + /** + * Name of the column + */ + name: string; + /** + * Datatype of the column + */ + type: string; +} + +/** + * Checks if a given item matches the ITableColumn interface + * @param item Object to check if it matches the ITableColumn interface + * @returns boolean true if matches interface + */ +export const isITableColumn = (item: any): boolean => { + let match = true; + const BASE_ERROR = + 'The object provided to isITableColumn does match the interface.'; + if (typeof item?.name !== 'string') { + match = false; + // eslint-disable-next-line no-console + console.error( + `${BASE_ERROR} The property 'name' is required and must be a string`, + ); + } + if (match && typeof item?.type !== 'string') { + match = false; + // eslint-disable-next-line no-console + console.error( + `${BASE_ERROR} The property 'type' is required and must be a string`, + ); + } + return match; +}; + +export interface IDatabaseTable { + name: string; + columns: ITableColumn[]; +} + +/** + * Checks if a given item matches the isIDatabsetTable interface + * @param item Object to check if it matches the isIDatabsetTable interface + * @returns boolean true if matches interface + */ +export const isIDatabaseTable = (item: any): boolean => { + let match = true; + if (typeof item?.name !== 'string') { + match = false; + } + if (match && !Array.isArray(item.columns)) { + match = false; + } + if (match && item.columns.length > 0) { + const invalid = item.columns.some((column: any, index: number) => { Review Comment: @lyndsiWilliams another case of being in the internals of a type guard function we are allowing any value to be provided then doing checks to validate it matches a specific type interface, so in this case the any is intentional -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
