Skip to content

Commit fb39a27

Browse files
authored
chore(query-bar, crud, schema): remove query-changed, query-reset, subtab-changed events from the app COMPASS-7543 COMPASS-7544 (#5814)
* chore(query-bar): introduce new hooks to access last applied query state * chore(schema): replace unnecessary state with query bar hooks and service * chore(crud): replace unnecessary state with query bar hooks and service
1 parent 8b23bb2 commit fb39a27

File tree

27 files changed

+722
-1415
lines changed

27 files changed

+722
-1415
lines changed

package-lock.json

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/compass-collection/src/components/collection-tab.tsx

Lines changed: 84 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ type ConnectionTabConnectedProps = {
7272
stats: CollectionState['stats'];
7373
onTabClick: (tab: CollectionSubtab) => void;
7474
};
75+
76+
// TODO(COMPASS-7937): Wrong place for these types and type descriptions
7577
// Props definition when using the component
7678
type ConnectionTabExpectedProps = {
7779
/**
@@ -129,8 +131,6 @@ const CollectionTabWithMetadata: React.FunctionComponent<
129131
});
130132
}
131133
}, [currentTab, track]);
132-
133-
const QueryBarPlugin = useCollectionQueryBar();
134134
const pluginTabs = useCollectionSubTabs();
135135
const pluginModals = useCollectionScopedModals();
136136

@@ -157,77 +157,75 @@ const CollectionTabWithMetadata: React.FunctionComponent<
157157
const activeTabIndex = tabs.findIndex((tab) => tab.name === currentTab);
158158

159159
return (
160-
<QueryBarPlugin {...pluginProps}>
161-
<div className={collectionStyles} data-testid="collection">
162-
<div className={collectionContainerStyles}>
163-
<CollectionHeader
164-
editViewName={editViewName}
165-
{...collectionMetadata}
166-
></CollectionHeader>
167-
<TabNavBar
168-
data-testid="collection-tabs"
169-
aria-label="Collection Tabs"
170-
tabNames={tabs.map((tab) => tab.name)}
171-
tabLabels={tabs.map((tab) => {
172-
// We don't show stats, when the collection is a timeseries or a view
173-
// or when the view is being edited
174-
const hideStats =
175-
collectionMetadata.isTimeSeries ||
176-
collectionMetadata.sourceName ||
177-
editViewName;
178-
if (hideStats) {
179-
return tab.name;
180-
}
181-
if (tab.name === 'Documents') {
182-
return (
183-
<TabTitleWithStats
184-
data-testid="documents-tab-with-stats"
185-
title={tab.name}
186-
statsComponent={<CollectionDocumentsStats stats={stats} />}
187-
/>
188-
);
189-
}
190-
if (tab.name === 'Indexes') {
191-
return (
192-
<TabTitleWithStats
193-
data-testid="indexes-tab-with-stats"
194-
title={tab.name}
195-
statsComponent={<CollectionIndexesStats stats={stats} />}
196-
/>
197-
);
198-
}
160+
<div className={collectionStyles} data-testid="collection">
161+
<div className={collectionContainerStyles}>
162+
<CollectionHeader
163+
editViewName={editViewName}
164+
{...collectionMetadata}
165+
></CollectionHeader>
166+
<TabNavBar
167+
data-testid="collection-tabs"
168+
aria-label="Collection Tabs"
169+
tabNames={tabs.map((tab) => tab.name)}
170+
tabLabels={tabs.map((tab) => {
171+
// We don't show stats, when the collection is a timeseries or a view
172+
// or when the view is being edited
173+
const hideStats =
174+
collectionMetadata.isTimeSeries ||
175+
collectionMetadata.sourceName ||
176+
editViewName;
177+
if (hideStats) {
199178
return tab.name;
200-
})}
201-
views={tabs.map((tab) => {
179+
}
180+
if (tab.name === 'Documents') {
202181
return (
203-
<ErrorBoundary
204-
key={tab.name}
205-
onError={(error: Error, errorInfo: unknown) => {
206-
log.error(
207-
mongoLogId(1001000107),
208-
'Collection Workspace',
209-
'Rendering collection tab failed',
210-
{ name: tab.name, error: error.stack, errorInfo }
211-
);
212-
}}
213-
>
214-
{tab.component}
215-
</ErrorBoundary>
182+
<TabTitleWithStats
183+
data-testid="documents-tab-with-stats"
184+
title={tab.name}
185+
statsComponent={<CollectionDocumentsStats stats={stats} />}
186+
/>
216187
);
217-
})}
218-
activeTabIndex={activeTabIndex}
219-
onTabClicked={(id) => {
220-
onTabClick(tabs[id].name);
221-
}}
222-
/>
223-
</div>
224-
<div className={collectionModalContainerStyles}>
225-
{pluginModals.map((ModalPlugin, idx) => {
226-
return <ModalPlugin key={idx} {...pluginProps}></ModalPlugin>;
188+
}
189+
if (tab.name === 'Indexes') {
190+
return (
191+
<TabTitleWithStats
192+
data-testid="indexes-tab-with-stats"
193+
title={tab.name}
194+
statsComponent={<CollectionIndexesStats stats={stats} />}
195+
/>
196+
);
197+
}
198+
return tab.name;
199+
})}
200+
views={tabs.map((tab) => {
201+
return (
202+
<ErrorBoundary
203+
key={tab.name}
204+
onError={(error: Error, errorInfo: unknown) => {
205+
log.error(
206+
mongoLogId(1001000107),
207+
'Collection Workspace',
208+
'Rendering collection tab failed',
209+
{ name: tab.name, error: error.stack, errorInfo }
210+
);
211+
}}
212+
>
213+
{tab.component}
214+
</ErrorBoundary>
215+
);
227216
})}
228-
</div>
217+
activeTabIndex={activeTabIndex}
218+
onTabClicked={(id) => {
219+
onTabClick(tabs[id].name);
220+
}}
221+
/>
229222
</div>
230-
</QueryBarPlugin>
223+
<div className={collectionModalContainerStyles}>
224+
{pluginModals.map((ModalPlugin, idx) => {
225+
return <ModalPlugin key={idx} {...pluginProps}></ModalPlugin>;
226+
})}
227+
</div>
228+
</div>
231229
);
232230
};
233231

@@ -237,15 +235,29 @@ const CollectionTab = ({
237235
}: Omit<CollectionTabProps, 'collectionMetadata'> & {
238236
collectionMetadata: CollectionMetadata | null;
239237
}) => {
238+
const QueryBarPlugin = useCollectionQueryBar();
239+
240240
if (!collectionMetadata) {
241241
return null;
242242
}
243243

244+
const pluginProps = {
245+
...collectionMetadata,
246+
namespace: props.namespace,
247+
aggregation: props.initialAggregation,
248+
pipeline: props.initialPipeline,
249+
pipelineText: props.initialPipelineText,
250+
query: props.initialQuery,
251+
editViewName: props.editViewName,
252+
};
253+
244254
return (
245-
<CollectionTabWithMetadata
246-
collectionMetadata={collectionMetadata}
247-
{...props}
248-
></CollectionTabWithMetadata>
255+
<QueryBarPlugin {...pluginProps}>
256+
<CollectionTabWithMetadata
257+
collectionMetadata={collectionMetadata}
258+
{...props}
259+
></CollectionTabWithMetadata>
260+
</QueryBarPlugin>
249261
);
250262
};
251263

packages/compass-collection/src/modules/collection-tab.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ export const collectionMetadataFetched = (metadata: CollectionMetadata) => {
9999
export const selectTab = (
100100
tabName: CollectionSubtab
101101
): CollectionThunkAction<void> => {
102-
return (_dispatch, getState, { localAppRegistry, workspaces }) => {
103-
localAppRegistry.emit('subtab-changed', tabName);
102+
return (_dispatch, getState, { workspaces }) => {
104103
workspaces.openCollectionWorkspaceSubtab(
105104
getState().workspaceTabId,
106105
tabName

packages/compass-components/src/components/empty-content.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ type EmptyContentProps = {
4747
icon: React.FunctionComponent;
4848
title: string;
4949
subTitle: string;
50-
callToAction?: string | JSX.Element;
51-
callToActionLink?: JSX.Element;
50+
callToAction?: React.ReactNode;
51+
callToActionLink?: React.ReactNode;
5252
};
5353

5454
const EmptyContent: React.FunctionComponent<

packages/compass-crud/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ application can be listened to via [hadron-app-registry][hadron-app-registry].
117117

118118
- **'import-finished'**: received when import in the import-export plugin is
119119
finished. Refreshes documents.
120-
- **'query-changed'**: received when query was changed in the query bar. Handles updates to crud plugin's query
121-
state, and refreshes documents.
122120
- **'refresh-data'**: received when other plugins need documents refreshed.
123121
Refreshes documents.
124122

packages/compass-crud/src/components/connected-document-list.tsx

Lines changed: 0 additions & 16 deletions
This file was deleted.

packages/compass-crud/src/components/crud-toolbar.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ const CrudToolbar: React.FunctionComponent<CrudToolbarProps> = ({
169169
<div className={crudToolbarStyles}>
170170
<div className={crudQueryBarStyles}>
171171
<QueryBar
172+
source="crud"
172173
resultId={resultId}
173174
buttonLabel="Find"
174175
onApply={onApplyClicked}

0 commit comments

Comments
 (0)