({
columns, data, hasSelectRow, schema, sortOptions, tableProps, searchVal,
loadNextPage, ...props
})
| 105 | }; |
| 106 | |
| 107 | export function Table({ |
| 108 | columns, data, hasSelectRow, schema, sortOptions, tableProps, searchVal, |
| 109 | loadNextPage, ...props |
| 110 | }) { |
| 111 | const { schemaState } = useSchemaState({ |
| 112 | schema: getTableSchema(schema), |
| 113 | getInitData: null, |
| 114 | viewHelperProps: {mode: 'properties'}, |
| 115 | }); |
| 116 | |
| 117 | // We don't care about validation in static table, hence - initialising the |
| 118 | // data directly. |
| 119 | if (data.length && schemaState) { |
| 120 | schemaState.initData = schemaState.data = prepareData({'data': data}); |
| 121 | } |
| 122 | |
| 123 | const defaultColumn = React.useMemo( |
| 124 | () => ({ |
| 125 | size: 150, |
| 126 | minSize: 100, |
| 127 | maxSize: 1200, |
| 128 | }), |
| 129 | [] |
| 130 | ); |
| 131 | |
| 132 | const finalColumns = useMemo(() => (hasSelectRow ? [{ |
| 133 | id: 'selection', |
| 134 | header: getCheckboxCell({ |
| 135 | title: gettext('Select All Rows'), |
| 136 | }), |
| 137 | cell: getCheckboxHeaderCell({ |
| 138 | title: gettext('Select Row'), |
| 139 | }), |
| 140 | enableSorting: false, |
| 141 | enableResizing: false, |
| 142 | maxSize: 35, |
| 143 | }] : []).concat( |
| 144 | columns.filter( |
| 145 | (c) => _.isUndefined(c.enableVisibility) ? true : c.enableVisibility |
| 146 | ).map((c) => ({ |
| 147 | ...c, |
| 148 | // if data is null then global search doesn't work |
| 149 | // Use accessorFn to return empty string if data is null. |
| 150 | accessorFn: c.accessorFn ?? ( |
| 151 | c.accessorKey ? (row) => row[c.accessorKey] ?? '' : undefined |
| 152 | ), |
| 153 | })) |
| 154 | ), [hasSelectRow, columns]); |
| 155 | |
| 156 | // Render the UI for your table |
| 157 | const tableRef = useRef(); |
| 158 | let flatData = []; |
| 159 | let fetchMoreOnBottomReached; |
| 160 | let totalFetched = 0; |
| 161 | let totalDBRowCount = 0; |
| 162 | |
| 163 | // Infinite scrolling |
| 164 | const { _data, fetchNextPage, isFetching } = useInfiniteQuery({ |
nothing calls this directly
no test coverage detected