| 108 | } |
| 109 | |
| 110 | function Views(props) { |
| 111 | const [currentDataflow, setCurrentDataflow] = useState(null); |
| 112 | const [includeSystemCatalog, setIncludeSystemCatalog] = useState(false); |
| 113 | const [records, setRecords] = useState(null); |
| 114 | const [loading, setLoading] = useState(true); |
| 115 | const [error, setError] = useState(false); |
| 116 | |
| 117 | useEffect(() => { |
| 118 | const search = new URLSearchParams(location.search); |
| 119 | const dataflow = search.get('dataflow'); |
| 120 | if (dataflow) { |
| 121 | setCurrentDataflow(dataflow); |
| 122 | } |
| 123 | setIncludeSystemCatalog(search.get('system_catalog') === 'true'); |
| 124 | }, []); |
| 125 | |
| 126 | useEffect(() => { |
| 127 | setCurrentDataflow(null); |
| 128 | }, [props]); |
| 129 | |
| 130 | useEffect(() => { |
| 131 | const params = new URLSearchParams(location.search); |
| 132 | if (currentDataflow) { |
| 133 | params.set('dataflow', currentDataflow); |
| 134 | } else { |
| 135 | params.delete('dataflow'); |
| 136 | } |
| 137 | window.history.replaceState({}, '', `${location.pathname}?${params}`); |
| 138 | }, [currentDataflow]); |
| 139 | |
| 140 | const whereFragment = includeSystemCatalog ? `` : `WHERE name NOT LIKE 'Dataflow: mz_catalog.%'`; |
| 141 | |
| 142 | useEffect(() => { |
| 143 | setLoading(true); |
| 144 | setError(false); |
| 145 | |
| 146 | const load = async () => { |
| 147 | const { |
| 148 | results: [_set_cluster, _set_replica, records_table], |
| 149 | } = await query(` |
| 150 | SET cluster = ${formatNameForQuery(props.clusterName)}; |
| 151 | SET cluster_replica = ${formatNameForQuery(props.replicaName)}; |
| 152 | SELECT |
| 153 | id, name, batches, records, size, capacity, allocations |
| 154 | FROM |
| 155 | mz_introspection.mz_records_per_dataflow |
| 156 | ${whereFragment} |
| 157 | ORDER BY |
| 158 | records DESC |
| 159 | `); |
| 160 | |
| 161 | setRecords(records_table.rows); |
| 162 | setLoading(false); |
| 163 | }; |
| 164 | load().catch((error) => { |
| 165 | setError(error); |
| 166 | setLoading(false); |
| 167 | }); |