MCPcopy
hub / github.com/redpanda-data/console / QuickTable

Function QuickTable

frontend/src/utils/tsx-utils.tsx:135–193  ·  view source on GitHub ↗
(
  data:
    | { key: React.ReactNode; value: React.ReactNode }[]
    | { [key: string]: React.ReactNode }
    | [React.ReactNode, React.ReactNode][],
  options?: QuickTableOptions
)

Source from the content-addressed store, hash-verified

133): JSX.Element;
134
135export function QuickTable(
136 data:
137 | { key: React.ReactNode; value: React.ReactNode }[]
138 | { [key: string]: React.ReactNode }
139 | [React.ReactNode, React.ReactNode][],
140 options?: QuickTableOptions
141): JSX.Element {
142 let entries: { key: React.ReactNode; value: React.ReactNode }[];
143
144 // plain object?
145 if (typeof data === 'object' && !Array.isArray(data)) {
146 // Convert to array of key value objects
147 entries = [];
148 for (const [k, v] of Object.entries(data)) {
149 entries.push({ key: k, value: v });
150 }
151 }
152 // array of [any, any] ?
153 else if (Array.isArray(data) && data.length > 0 && Array.isArray(data[0])) {
154 // Convert to array of key-value objects
155 entries = (data as [React.ReactNode, React.ReactNode][]).map((ar) => ({ key: ar[0], value: ar[1] }));
156 }
157 // already correct? array of { key:any, value:any }
158 else {
159 // Cast to correct type directly
160 entries = data as { key: React.ReactNode; value: React.ReactNode }[];
161 }
162
163 const o = Object.assign({} as QuickTableOptions, DefaultQuickTableOptions, options);
164
165 const showVerticalGutter = (typeof o.gapHeight === 'number' && o.gapHeight > 0) || typeof o.gapHeight === 'string';
166 const classNames = [o.tableClassName, 'quickTable'].joinStr(' ');
167
168 return (
169 <table className={classNames} style={o.tableStyle}>
170 <tbody>
171 {entries.map((obj, i) => (
172 <React.Fragment key={`${toSafeString(obj.key)}-${i}`}>
173 <tr>
174 <td className="keyCell" style={{ textAlign: o.keyAlign, ...o.keyStyle }}>
175 {React.isValidElement(obj.key) ? obj.key : toSafeString(obj.key)}
176 </td>
177 <td style={{ minWidth: '0px', width: o.gapWidth, padding: '0px' }} />
178 <td className="valueCell" style={{ textAlign: o.valueAlign, ...o.valueStyle }}>
179 {React.isValidElement(obj.value) ? obj.value : toSafeString(obj.value)}
180 </td>
181 </tr>
182
183 {showVerticalGutter && i < entries.length - 1 && (
184 <tr>
185 <td style={{ padding: 0, paddingBottom: o.gapHeight }} />
186 </tr>
187 )}
188 </React.Fragment>
189 ))}
190 </tbody>
191 </table>
192 );

Callers 5

renderMethod · 0.90
OverviewTabFunction · 0.90
renderMethod · 0.90
renderMethod · 0.90

Calls 2

toSafeStringFunction · 0.85
joinStrMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…