diff --git a/packages/compass-indexes/src/components/regular-indexes-table/regular-indexes-table.tsx b/packages/compass-indexes/src/components/regular-indexes-table/regular-indexes-table.tsx index 102f9c99198..056707f4d63 100644 --- a/packages/compass-indexes/src/components/regular-indexes-table/regular-indexes-table.tsx +++ b/packages/compass-indexes/src/components/regular-indexes-table/regular-indexes-table.tsx @@ -123,7 +123,12 @@ export const RegularIndexesTable: React.FunctionComponent< onUnhideIndex={onUnhideIndex} > ), - details: , + details: ( + + ), }; }); diff --git a/packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.spec.tsx b/packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.spec.tsx index fe4b8783a1f..14c47ec2b9f 100644 --- a/packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.spec.tsx +++ b/packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.spec.tsx @@ -9,6 +9,7 @@ import { import { expect } from 'chai'; import sinon from 'sinon'; import userEvent from '@testing-library/user-event'; +import type { Document } from 'mongodb'; import { SearchIndexesTable } from './search-indexes-table'; import type { SearchIndex } from 'mongodb-data-service'; @@ -85,6 +86,28 @@ describe('SearchIndexesTable Component', function () { ); expect(badge).to.exist; expect(badge).to.have.text(index.status); + + // Renders details + + const expandButton = within(indexRow).getByLabelText('Expand row'); + expect(expandButton).to.exist; + fireEvent.click(expandButton); + + const details = screen.getByTestId( + `search-indexes-details-${index.name}` + ); + expect(details).to.exist; + + if (index.latestDefinition.mappings?.dynamic) { + expect(within(details).getAllByText('Dynamic Mappings')).to.exist; + } + if (index.latestDefinition.mappings?.fields) { + for (const field of Object.keys( + index.latestDefinition.mappings.fields as Document + )) { + expect(within(details).getAllByText(field)).to.exist; + } + } } }); } diff --git a/packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.tsx b/packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.tsx index f958235bacf..935f65a42d2 100644 --- a/packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.tsx +++ b/packages/compass-indexes/src/components/search-indexes-table/search-indexes-table.tsx @@ -1,5 +1,6 @@ import React from 'react'; import { connect } from 'react-redux'; +import type { Document } from 'mongodb'; import type { SearchIndex, SearchIndexStatus } from 'mongodb-data-service'; import { withPreferences } from 'compass-preferences-model'; @@ -9,6 +10,8 @@ import { Button, Link, Badge, + css, + spacing, } from '@mongodb-js/compass-components'; import type { SearchSortColumn } from '../../modules/search-indexes'; @@ -93,6 +96,54 @@ function IndexStatus({ ); } +const searchIndexDetailsStyles = css({ + display: 'inline-flex', + gap: spacing[1], +}); + +const searchIndexFieldStyles = css({ + // Override LeafyGreen's uppercase styles as we want to keep the case sensitivity of the key. + textTransform: 'none', + gap: spacing[1], +}); + +function SearchIndexDetails({ + indexName, + definition, +}: { + indexName: string; + definition: Document; +}) { + const badges = []; + if (definition.mappings?.dynamic) { + badges.push({ + name: 'Dynamic Mappings', + className: undefined, + }); + } + + if (definition.mappings?.fields) { + badges.push( + ...Object.keys(definition.mappings.fields as Document).map((name) => ({ + name, + className: searchIndexFieldStyles, + })) + ); + } + return ( +
+ {badges.map((badge) => ( + + {badge.name} + + ))} +
+ ); +} + export const SearchIndexesTable: React.FunctionComponent< SearchIndexesTableProps > = ({ @@ -138,7 +189,12 @@ export const SearchIndexesTable: React.FunctionComponent< }, ], - // TODO(COMPASS-7206): details for the nested row + details: ( + + ), }; });