Skip to content

Commit 3a03e91

Browse files
committed
fixup: only track schema export when copied or the download button is clicked
1 parent 94716ad commit 3a03e91

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

packages/compass-schema/src/components/export-schema-modal.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
cancelExportSchema,
2222
changeExportSchemaFormat,
2323
closeExportSchema,
24+
trackSchemaExported,
2425
type SchemaFormat,
2526
type ExportStatus,
2627
} from '../stores/schema-export-reducer';
@@ -75,6 +76,7 @@ const ExportSchemaModal: React.FunctionComponent<{
7576
onCancelSchemaExport: () => void;
7677
onChangeSchemaExportFormat: (format: SchemaFormat) => Promise<void>;
7778
onClose: () => void;
79+
onExportedSchemaCopied: () => void;
7880
}> = ({
7981
errorMessage,
8082
exportStatus,
@@ -84,6 +86,7 @@ const ExportSchemaModal: React.FunctionComponent<{
8486
onCancelSchemaExport,
8587
onChangeSchemaExportFormat,
8688
onClose,
89+
onExportedSchemaCopied,
8790
}) => {
8891
const onFormatOptionSelected = useCallback(
8992
(event: ChangeEvent<HTMLInputElement>) => {
@@ -143,6 +146,7 @@ const ExportSchemaModal: React.FunctionComponent<{
143146
language="json"
144147
className={codeStyles}
145148
copyable={true}
149+
onCopy={onExportedSchemaCopied}
146150
>
147151
{exportedSchema ?? 'Empty'}
148152
</Code>
@@ -163,7 +167,7 @@ const ExportSchemaModal: React.FunctionComponent<{
163167
</Button>
164168
<Button
165169
onClick={() => {
166-
/* TODO(COMPASS-8704) */
170+
/* TODO(COMPASS-8704): download and track with trackSchemaExported */
167171
}}
168172
variant="primary"
169173
>
@@ -183,6 +187,7 @@ export default connect(
183187
exportedSchema: state.schemaExport.exportedSchema,
184188
}),
185189
{
190+
onExportedSchemaCopied: trackSchemaExported,
186191
onCancelSchemaExport: cancelExportSchema,
187192
onChangeSchemaExportFormat: changeExportSchemaFormat,
188193
onClose: closeExportSchema,

packages/compass-schema/src/stores/schema-export-reducer.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,22 @@ const _trackSchemaExported = ({
195195
};
196196
};
197197

198+
export const onSchemaExportCopied = (): SchemaThunkAction<void> => {
199+
return (dispatch, getState) => {
200+
const {
201+
schemaAnalysis: { schema },
202+
schemaExport: { exportFormat },
203+
} = getState();
204+
dispatch(
205+
_trackSchemaExported({
206+
schema,
207+
format: exportFormat,
208+
source: 'schema_tab',
209+
})
210+
);
211+
};
212+
};
213+
198214
export const changeExportSchemaFormat = (
199215
exportFormat: SchemaFormat
200216
): SchemaThunkAction<
@@ -228,7 +244,7 @@ export const changeExportSchemaFormat = (
228244
}
229245
);
230246

231-
const { schemaAccessor, schema } = getState().schemaAnalysis;
247+
const { schemaAccessor } = getState().schemaAnalysis;
232248

233249
let exportedSchema: string;
234250
try {
@@ -265,14 +281,6 @@ export const changeExportSchemaFormat = (
265281
return;
266282
}
267283

268-
dispatch(
269-
_trackSchemaExported({
270-
schema,
271-
format: exportFormat,
272-
source: 'schema_tab',
273-
})
274-
);
275-
276284
log.info(
277285
mongoLogId(1_001_000_344),
278286
'Schema export formatting complete',

0 commit comments

Comments
 (0)