Skip to content

Commit

Permalink
Update docs to records
Browse files Browse the repository at this point in the history
  • Loading branch information
davismcphee committed Jun 12, 2024
1 parent 0c9310d commit c5e23f4
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('Data table record utils', () => {
describe('buildDataTableRecordList', () => {
test('should return a list of DataTableRecord', () => {
const result = buildDataTableRecordList({
docs: esHitsMock,
records: esHitsMock,
dataView: dataViewMock,
});
result.forEach((doc) => {
Expand All @@ -36,7 +36,7 @@ describe('Data table record utils', () => {

test('should support processing each record', () => {
const result = buildDataTableRecordList({
docs: esHitsMock,
records: esHitsMock,
dataView: dataViewMock,
processRecord: (record) => ({ ...record, id: 'custom-id' }),
});
Expand Down
8 changes: 4 additions & 4 deletions packages/kbn-discover-utils/src/utils/build_data_record.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ export function buildDataTableRecord(

/**
* Helper to build multiple DataTableRecords at once, saved a bit of testing code lines
* @param docs Array of documents returned from Elasticsearch
* @param records Array of documents returned from Elasticsearch
* @param dataView this current data view
*/
export function buildDataTableRecordList<T extends DataTableRecord = DataTableRecord>({
docs,
records,
dataView,
processRecord,
}: {
docs: EsHitRecord[];
records: EsHitRecord[];
dataView?: DataView;
processRecord?: (record: DataTableRecord) => T;
}): DataTableRecord[] {
return docs.map((doc) => {
return records.map((doc) => {
const record = buildDataTableRecord(doc, dataView);
return processRecord ? processRecord(record) : record;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ describe('context predecessors', function () {
expect(mockSearchSource.fetch$.calledOnce).toBe(true);
expect(rows).toEqual(
buildDataTableRecordList({
docs: mockSearchSource._stubHits.slice(0, 3),
records: mockSearchSource._stubHits.slice(0, 3),
dataView,
})
);
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('context predecessors', function () {
expect(intervals.length).toBeGreaterThan(1);
expect(rows).toEqual(
buildDataTableRecordList({
docs: mockSearchSource._stubHits.slice(0, 3),
records: mockSearchSource._stubHits.slice(0, 3),
dataView,
})
);
Expand Down Expand Up @@ -178,7 +178,7 @@ describe('context predecessors', function () {

expect(rows).toEqual(
buildDataTableRecordList({
docs: mockSearchSource._stubHits.slice(-3),
records: mockSearchSource._stubHits.slice(-3),
dataView,
})
);
Expand Down Expand Up @@ -271,7 +271,7 @@ describe('context predecessors', function () {
expect(setFieldsSpy.calledOnce).toBe(true);
expect(rows).toEqual(
buildDataTableRecordList({
docs: mockSearchSource._stubHits.slice(0, 3),
records: mockSearchSource._stubHits.slice(0, 3),
dataView,
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ describe('context successors', function () {
expect(mockSearchSource.fetch$.calledOnce).toBe(true);
expect(rows).toEqual(
buildDataTableRecordList({
docs: mockSearchSource._stubHits.slice(-3),
records: mockSearchSource._stubHits.slice(-3),
dataView,
})
);
Expand Down Expand Up @@ -140,7 +140,7 @@ describe('context successors', function () {
expect(intervals.length).toBeGreaterThan(1);
expect(rows).toEqual(
buildDataTableRecordList({
docs: mockSearchSource._stubHits.slice(-3),
records: mockSearchSource._stubHits.slice(-3),
dataView,
})
);
Expand Down Expand Up @@ -173,7 +173,7 @@ describe('context successors', function () {
expect(intervals.length).toBeGreaterThan(1);
expect(rows).toEqual(
buildDataTableRecordList({
docs: mockSearchSource._stubHits.slice(0, 4),
records: mockSearchSource._stubHits.slice(0, 4),
dataView,
})
);
Expand Down Expand Up @@ -262,7 +262,7 @@ describe('context successors', function () {
expect(mockSearchSource.fetch$.calledOnce).toBe(true);
expect(rows).toEqual(
buildDataTableRecordList({
docs: mockSearchSource._stubHits.slice(-3),
records: mockSearchSource._stubHits.slice(-3),
dataView,
})
);
Expand Down Expand Up @@ -337,7 +337,7 @@ describe('context successors', function () {
expect(mockSearchSource.fetch$.calledOnce).toBe(true);
expect(rows).toEqual(
buildDataTableRecordList({
docs: mockSearchSource._stubHits.slice(-3),
records: mockSearchSource._stubHits.slice(-3),
dataView,
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const fetchDocuments = (
filter((res) => !isRunningResponse(res)),
map((res) => {
return buildDataTableRecordList({
docs: res.rawResponse.hits.hits,
records: res.rawResponse.hits.hits,
dataView,
processRecord: (record) => services.profilesManager.resolveDocumentProfile({ record }),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function DocumentsTable({
{loading && <EuiProgress size="xs" color="accent" />}
<UnifiedDataTable
rows={buildDataTableRecordList({
docs: (data?.hits?.hits ?? []) as any,
records: (data?.hits?.hits ?? []) as any,
dataView,
})}
showColumnTokens
Expand Down

0 comments on commit c5e23f4

Please sign in to comment.