({
schemaName,
tableName,
}: TableDataContentProps)
| 47 | } |
| 48 | |
| 49 | export default function TableDataWindow({ |
| 50 | schemaName, |
| 51 | tableName, |
| 52 | }: TableDataContentProps) { |
| 53 | const { updateTableSchema } = useAutoComplete(); |
| 54 | const { schema } = useSchema(); |
| 55 | const { databaseDriver } = useStudioContext(); |
| 56 | const [error, setError] = useState<string>(); |
| 57 | const [executeError, setExecuteError] = useState<string | null>(null); |
| 58 | |
| 59 | const [loading, setLoading] = useState(false); |
| 60 | const [data, setData] = useState<OptimizeTableState<TableHeaderMetadata>>(); |
| 61 | const [tableSchema, setTableSchema] = useState<DatabaseTableSchema>(); |
| 62 | const [stat, setStat] = useState<DatabaseResultStat>(); |
| 63 | const [sortColumns, setSortColumns] = useState<ColumnSortOption[]>([]); |
| 64 | const [changeNumber, setChangeNumber] = useState(0); |
| 65 | |
| 66 | const [where, setWhere] = useState(""); |
| 67 | const [whereInput, setWhereInput] = useState(""); |
| 68 | |
| 69 | const [offset, setOffset] = useState("0"); |
| 70 | const [limit, setLimit] = useState("50"); |
| 71 | |
| 72 | const [finalOffset, setFinalOffset] = useState(0); |
| 73 | const [finalLimit, setFinalLimit] = useState(50); |
| 74 | const [isExecuting, setIsExecuting] = useState(false); |
| 75 | |
| 76 | const [revision, setRevision] = useState(1); |
| 77 | const [lastQueryTimestamp, setLastQueryTimestamp] = useState(0); |
| 78 | |
| 79 | // We cache the schema to prevent re-initial |
| 80 | // the state when schema changes and lost all the |
| 81 | // changes in the table |
| 82 | const [cachedSchema] = useState(() => schema); |
| 83 | |
| 84 | useEffect(() => { |
| 85 | const fetchData = async () => { |
| 86 | setLoading(true); |
| 87 | |
| 88 | try { |
| 89 | const { data: dataResult, schema: schemaResult } = |
| 90 | await databaseDriver.selectTable(schemaName, tableName, { |
| 91 | whereRaw: where, |
| 92 | limit: finalLimit, |
| 93 | offset: finalOffset, |
| 94 | orderBy: sortColumns, |
| 95 | }); |
| 96 | |
| 97 | const tableState = createTableStateFromResult({ |
| 98 | driver: databaseDriver, |
| 99 | result: dataResult, |
| 100 | tableSchema: schemaResult, |
| 101 | schemas: cachedSchema, |
| 102 | }); |
| 103 | |
| 104 | tableState.setSql("SELECT * FROM " + tableName + ";"); |
| 105 | |
| 106 | setData(tableState); |
nothing calls this directly
no test coverage detected