Skip to content

Commit

Permalink
clean up a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
mabaasit committed Sep 20, 2024
1 parent f032ff1 commit 9fcf8e3
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 24 deletions.
20 changes: 9 additions & 11 deletions packages/compass-components/src/components/tab-nav-bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,15 @@ function TabNavBar({
</Tabs>
</div>
{tabs.map(({ name, content }, idx) => {
if (idx === activeTabIndex) {
return (
<div
className={tabStyles}
key={`tab-content-${name}`}
data-testid={`${name.toLowerCase().replace(/ /g, '-')}-content`}
>
{content}
</div>
);
}
idx === activeTabIndex && (
<div
className={tabStyles}
key={`tab-content-${name}`}
data-testid={`${name.toLowerCase().replace(/ /g, '-')}-content`}
>
{content}
</div>
);
})}
</div>
);
Expand Down
6 changes: 3 additions & 3 deletions packages/compass-crud/src/plugin-name.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ const format = (value: any, format = 'a') => {
return numeral(value).format(precision + format);
};

type CollectionTabStatsProps = {
type CollectionStatsProps = {
text: string;
details: string[];
};
const CollectionTabStats: React.FunctionComponent<CollectionTabStatsProps> = ({
const CollectionStats: React.FunctionComponent<CollectionStatsProps> = ({
text,
details,
}) => {
Expand Down Expand Up @@ -99,7 +99,7 @@ export const CrudPluginName = ({
className={tabTitleWithStatsStyles}
>
Documents
<CollectionTabStats text={documentCount} details={details} />
<CollectionStats text={documentCount} details={details} />
</div>
);
};
11 changes: 8 additions & 3 deletions packages/compass-indexes/src/modules/collection-stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,20 @@ function isAction<A extends AnyAction>(
return action.type === type;
}

export function pickCollectionIndexStats(collection: Collection): CollectionStats {
export function extractCollectionStats(
collection: Collection
): CollectionStats {
const { index_count, index_size } = collection.toJSON();
return {
index_count,
index_size,
};
}

export type CollectionStats = Pick<Collection, 'index_count' | 'index_size'> | null;
export type CollectionStats = Pick<
Collection,
'index_count' | 'index_size'
> | null;

enum StatsActions {
CollectionStatsFetched = 'compass-indexes/CollectionStatsFetchedCollection',
Expand All @@ -34,7 +39,7 @@ const reducer: Reducer<CollectionStats, Action> = (state = null, action) => {
StatsActions.CollectionStatsFetched
)
) {
return pickCollectionIndexStats(action.collection);
return extractCollectionStats(action.collection);
}
return state;
};
Expand Down
9 changes: 4 additions & 5 deletions packages/compass-indexes/src/plugin-name.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useMemo } from 'react';
import { connect } from 'react-redux';
import type { CollectionStats } from './modules/collection-stats';
import type { RootState } from './modules';
import { Badge, css, spacing, Tooltip } from '@mongodb-js/compass-components';
import numeral from 'numeral';
Expand Down Expand Up @@ -37,11 +36,11 @@ const format = (value: any, format = 'a') => {
return numeral(value).format(precision + format);
};

type CollectionTabStatsProps = {
type CollectionStatsProps = {
text: string;
details: string[];
};
const CollectionTabStats: React.FunctionComponent<CollectionTabStatsProps> = ({
const CollectionStats: React.FunctionComponent<CollectionStatsProps> = ({
text,
details,
}) => {
Expand Down Expand Up @@ -79,7 +78,7 @@ const CollectionTabStats: React.FunctionComponent<CollectionTabStatsProps> = ({
const PluginName = ({
collectionStats,
}: {
collectionStats: CollectionStats;
collectionStats: RootState['collectionStats'];
}) => {
const { indexCount, totalIndexSize, avgIndexSize } = useMemo(() => {
const { index_count = NaN, index_size = NaN } = collectionStats ?? {};
Expand All @@ -102,7 +101,7 @@ const PluginName = ({
className={tabTitleWithStatsStyles}
>
Indexes
<CollectionTabStats text={indexCount} details={details} />
<CollectionStats text={indexCount} details={details} />
</div>
);
};
Expand Down
4 changes: 2 additions & 2 deletions packages/compass-indexes/src/stores/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type { TrackFunction } from '@mongodb-js/compass-telemetry';
import type { ConnectionInfoRef } from '@mongodb-js/compass-connections/provider';
import {
collectionStatsFetched,
pickCollectionIndexStats,
extractCollectionStats,
} from '../modules/collection-stats';

export type IndexesDataServiceProps =
Expand Down Expand Up @@ -97,7 +97,7 @@ export function activateIndexesPlugin(
? SearchIndexesStatuses.NOT_READY
: SearchIndexesStatuses.NOT_AVAILABLE,
},
collectionStats: pickCollectionIndexStats(collectionModel),
collectionStats: extractCollectionStats(collectionModel),
},
applyMiddleware(
thunk.withExtraArgument({
Expand Down

0 comments on commit 9fcf8e3

Please sign in to comment.