Skip to content

Commit 8a0590c

Browse files
authored
ref(✂️): simplify dynamic import (#90052)
by removing the extra variable and destruct `knip` only sees things as "used" when they are directly destructed from a dynamic import; also, the extra layer seems unnecessary
1 parent 5acef7c commit 8a0590c

File tree

3 files changed

+69
-55
lines changed

3 files changed

+69
-55
lines changed

static/app/actionCreators/modal.tsx

Lines changed: 67 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ export async function openEmailVerification({
5656
onClose,
5757
...args
5858
}: EmailVerificationModalOptions = {}) {
59-
const mod = await import('sentry/components/modals/emailVerificationModal');
60-
const {default: Modal} = mod;
59+
const {default: Modal} = await import(
60+
'sentry/components/modals/emailVerificationModal'
61+
);
6162

6263
openModal(deps => <Modal {...deps} {...args} />, {onClose});
6364
}
@@ -74,8 +75,7 @@ type OpenDiffModalOptions = {
7475
};
7576

7677
export async function openDiffModal(options: OpenDiffModalOptions) {
77-
const mod = await import('sentry/components/modals/diffModal');
78-
const {default: Modal, modalCss} = mod;
78+
const {default: Modal, modalCss} = await import('sentry/components/modals/diffModal');
7979

8080
openModal(deps => <Modal {...deps} {...options} />, {modalCss});
8181
}
@@ -93,8 +93,7 @@ type CreateTeamModalOptions = {
9393
};
9494

9595
export async function openCreateTeamModal(options: CreateTeamModalOptions) {
96-
const mod = await import('sentry/components/modals/createTeamModal');
97-
const {default: Modal} = mod;
96+
const {default: Modal} = await import('sentry/components/modals/createTeamModal');
9897

9998
openModal(deps => <Modal {...deps} {...options} />);
10099
}
@@ -125,8 +124,9 @@ type CreateOwnershipRuleModalOptions = {
125124
export async function openIssueOwnershipRuleModal(
126125
options: CreateOwnershipRuleModalOptions
127126
) {
128-
const mod = await import('sentry/components/modals/issueOwnershipRuleModal');
129-
const {default: Modal, modalCss} = mod;
127+
const {default: Modal, modalCss} = await import(
128+
'sentry/components/modals/issueOwnershipRuleModal'
129+
);
130130

131131
openModal(deps => <Modal {...deps} {...options} />, {
132132
modalCss: modalCss(options.theme),
@@ -142,8 +142,9 @@ export type EditOwnershipRulesModalOptions = {
142142
};
143143

144144
export async function openEditOwnershipRules(options: EditOwnershipRulesModalOptions) {
145-
const mod = await import('sentry/components/modals/editOwnershipRulesModal');
146-
const {default: Modal, modalCss} = mod;
145+
const {default: Modal, modalCss} = await import(
146+
'sentry/components/modals/editOwnershipRulesModal'
147+
);
147148

148149
openModal(deps => <Modal {...deps} {...options} />, {
149150
closeEvents: 'escape-key',
@@ -152,8 +153,9 @@ export async function openEditOwnershipRules(options: EditOwnershipRulesModalOpt
152153
}
153154

154155
export async function openCommandPalette(options: ModalOptions = {}) {
155-
const mod = await import('sentry/components/modals/commandPalette');
156-
const {default: Modal, modalCss} = mod;
156+
const {default: Modal, modalCss} = await import(
157+
'sentry/components/modals/commandPalette'
158+
);
157159

158160
openModal(deps => <Modal {...deps} {...options} />, {modalCss});
159161
}
@@ -163,8 +165,7 @@ type RecoveryModalOptions = {
163165
};
164166

165167
export async function openRecoveryOptions(options: RecoveryModalOptions) {
166-
const mod = await import('sentry/components/modals/recoveryOptionsModal');
167-
const {default: Modal} = mod;
168+
const {default: Modal} = await import('sentry/components/modals/recoveryOptionsModal');
168169

169170
openModal(deps => <Modal {...deps} {...options} />);
170171
}
@@ -176,8 +177,9 @@ export type TeamAccessRequestModalOptions = {
176177
};
177178

178179
export async function openTeamAccessRequestModal(options: TeamAccessRequestModalOptions) {
179-
const mod = await import('sentry/components/modals/teamAccessRequestModal');
180-
const {default: Modal} = mod;
180+
const {default: Modal} = await import(
181+
'sentry/components/modals/teamAccessRequestModal'
182+
);
181183

182184
openModal(deps => <Modal {...deps} {...options} />);
183185
}
@@ -188,8 +190,9 @@ type HelpSearchModalOptions = {
188190
};
189191

190192
export async function openHelpSearchModal(options?: HelpSearchModalOptions) {
191-
const mod = await import('sentry/components/modals/helpSearchModal');
192-
const {default: Modal, modalCss} = mod;
193+
const {default: Modal, modalCss} = await import(
194+
'sentry/components/modals/helpSearchModal'
195+
);
193196

194197
openModal(deps => <Modal {...deps} {...options} />, {modalCss});
195198
}
@@ -206,9 +209,10 @@ export async function openDebugFileSourceModal({
206209
onClose,
207210
...restOptions
208211
}: DebugFileSourceModalOptions) {
209-
const mod = await import('sentry/components/modals/debugFileCustomRepository');
212+
const {default: Modal, modalCss} = await import(
213+
'sentry/components/modals/debugFileCustomRepository'
214+
);
210215

211-
const {default: Modal, modalCss} = mod;
212216
openModal(deps => <Modal {...deps} {...restOptions} />, {
213217
modalCss,
214218
onClose,
@@ -219,8 +223,9 @@ export async function openInviteMembersModal({
219223
onClose,
220224
...args
221225
}: InviteMembersModalOptions = {}) {
222-
const mod = await import('sentry/components/modals/inviteMembersModal');
223-
const {default: Modal, modalCss} = mod;
226+
const {default: Modal, modalCss} = await import(
227+
'sentry/components/modals/inviteMembersModal'
228+
);
224229

225230
openModal(deps => <Modal {...deps} {...args} />, {modalCss, onClose});
226231
}
@@ -249,8 +254,9 @@ export async function openInviteMissingMembersModal({
249254
export async function openWidgetBuilderOverwriteModal(
250255
options: OverwriteWidgetModalProps
251256
) {
252-
const mod = await import('sentry/components/modals/widgetBuilder/overwriteWidgetModal');
253-
const {default: Modal, modalCss} = mod;
257+
const {default: Modal, modalCss} = await import(
258+
'sentry/components/modals/widgetBuilder/overwriteWidgetModal'
259+
);
254260

255261
openModal(deps => <Modal {...deps} {...options} />, {
256262
closeEvents: 'escape-key',
@@ -259,8 +265,9 @@ export async function openWidgetBuilderOverwriteModal(
259265
}
260266

261267
export async function openAddToDashboardModal(options: AddToDashboardModalProps) {
262-
const mod = await import('sentry/components/modals/widgetBuilder/addToDashboardModal');
263-
const {default: Modal, modalCss} = mod;
268+
const {default: Modal, modalCss} = await import(
269+
'sentry/components/modals/widgetBuilder/addToDashboardModal'
270+
);
264271

265272
openModal(deps => <Modal {...deps} {...options} />, {
266273
closeEvents: 'escape-key',
@@ -271,8 +278,9 @@ export async function openAddToDashboardModal(options: AddToDashboardModalProps)
271278
export async function openImportDashboardFromFileModal(
272279
options: ImportDashboardFromFileModalProps
273280
) {
274-
const mod = await import('sentry/components/modals/importDashboardFromFileModal');
275-
const {default: Modal, modalCss} = mod;
281+
const {default: Modal, modalCss} = await import(
282+
'sentry/components/modals/importDashboardFromFileModal'
283+
);
276284

277285
openModal(deps => <Modal {...deps} {...options} />, {
278286
closeEvents: 'escape-key',
@@ -292,8 +300,7 @@ export async function openReprocessEventModal({
292300
}
293301

294302
export async function demoSignupModal(options: ModalOptions = {}) {
295-
const mod = await import('sentry/components/modals/demoSignUp');
296-
const {default: Modal, modalCss} = mod;
303+
const {default: Modal, modalCss} = await import('sentry/components/modals/demoSignUp');
297304

298305
openModal(deps => <Modal {...deps} {...options} />, {modalCss});
299306
}
@@ -303,17 +310,19 @@ export type DemoEndModalOptions = {
303310
};
304311

305312
export async function demoEndModal(options: DemoEndModalOptions) {
306-
const mod = await import('sentry/components/modals/demoEndModal');
307-
const {default: Modal, modalCss} = mod;
313+
const {default: Modal, modalCss} = await import(
314+
'sentry/components/modals/demoEndModal'
315+
);
308316

309317
openModal(deps => <Modal {...deps} {...options} />, {modalCss});
310318
}
311319

312320
export async function openDashboardWidgetQuerySelectorModal(
313321
options: DashboardWidgetQuerySelectorModalOptions
314322
) {
315-
const mod = await import('sentry/components/modals/dashboardWidgetQuerySelectorModal');
316-
const {default: Modal, modalCss} = mod;
323+
const {default: Modal, modalCss} = await import(
324+
'sentry/components/modals/dashboardWidgetQuerySelectorModal'
325+
);
317326

318327
openModal(deps => <Modal {...deps} {...options} />, {
319328
closeEvents: 'escape-key',
@@ -325,9 +334,9 @@ export async function openWidgetViewerModal({
325334
onClose,
326335
...options
327336
}: WidgetViewerModalOptions & {onClose?: () => void}) {
328-
const mod = await import('sentry/components/modals/widgetViewerModal');
329-
330-
const {default: Modal, modalCss} = mod;
337+
const {default: Modal, modalCss} = await import(
338+
'sentry/components/modals/widgetViewerModal'
339+
);
331340

332341
openModal(deps => <Modal {...deps} {...options} />, {
333342
closeEvents: 'none',
@@ -337,17 +346,19 @@ export async function openWidgetViewerModal({
337346
}
338347

339348
export async function openCreateNewIntegrationModal() {
340-
const mod = await import('sentry/components/modals/createNewIntegrationModal');
341-
const {default: Modal} = mod;
349+
const {default: Modal} = await import(
350+
'sentry/components/modals/createNewIntegrationModal'
351+
);
342352

343353
openModal(deps => <Modal {...deps} />);
344354
}
345355

346356
export async function openCreateReleaseIntegration(
347357
options: CreateReleaseIntegrationModalOptions
348358
) {
349-
const mod = await import('sentry/components/modals/createReleaseIntegrationModal');
350-
const {default: Modal} = mod;
359+
const {default: Modal} = await import(
360+
'sentry/components/modals/createReleaseIntegrationModal'
361+
);
351362

352363
openModal(deps => <Modal {...deps} {...options} />);
353364
}
@@ -359,15 +370,17 @@ export type NavigateToExternalLinkModalOptions = {
359370
export async function openNavigateToExternalLinkModal(
360371
options: NavigateToExternalLinkModalOptions
361372
) {
362-
const mod = await import('sentry/components/modals/navigateToExternalLinkModal');
363-
const {default: Modal} = mod;
373+
const {default: Modal} = await import(
374+
'sentry/components/modals/navigateToExternalLinkModal'
375+
);
364376

365377
openModal(deps => <Modal {...deps} {...options} />);
366378
}
367379

368380
export async function openProjectCreationModal(options: {defaultCategory: Category}) {
369-
const mod = await import('sentry/components/modals/projectCreationModal');
370-
const {default: Modal, modalCss} = mod;
381+
const {default: Modal, modalCss} = await import(
382+
'sentry/components/modals/projectCreationModal'
383+
);
371384

372385
openModal(deps => <Modal {...deps} {...options} />, {modalCss});
373386
}
@@ -384,8 +397,9 @@ export async function openBulkEditMonitorsModal({onClose, ...options}: ModalOpti
384397
}
385398

386399
export async function openInsightChartModal(options: InsightChartModalOptions) {
387-
const mod = await import('sentry/components/modals/insightChartModal');
388-
const {default: Modal, modalCss} = mod;
400+
const {default: Modal, modalCss} = await import(
401+
'sentry/components/modals/insightChartModal'
402+
);
389403

390404
openModal(deps => <Modal {...deps} {...options} />, {modalCss});
391405
}
@@ -394,15 +408,17 @@ export async function openAddTempestCredentialsModal(options: {
394408
organization: Organization;
395409
project: Project;
396410
}) {
397-
const mod = await import('sentry/components/modals/addTempestCredentialsModal');
398-
const {default: Modal} = mod;
411+
const {default: Modal} = await import(
412+
'sentry/components/modals/addTempestCredentialsModal'
413+
);
399414

400415
openModal(deps => <Modal {...deps} {...options} />);
401416
}
402417

403418
export async function openSaveQueryModal(options: SaveQueryModalProps) {
404-
const mod = await import('sentry/components/modals/explore/saveQueryModal');
405-
const {default: Modal} = mod;
419+
const {default: Modal} = await import(
420+
'sentry/components/modals/explore/saveQueryModal'
421+
);
406422

407423
openModal(deps => <Modal {...deps} {...options} />);
408424
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import ModalStore from 'sentry/stores/modalStore';
22

33
export async function redirectToProject(newProjectSlug: string) {
4-
const mod = await import('sentry/components/modals/redirectToProject');
5-
const {default: Modal} = mod;
4+
const {default: Modal} = await import('sentry/components/modals/redirectToProject');
65

76
ModalStore.openModal(deps => <Modal {...deps} slug={newProjectSlug} />, {});
87
}

static/app/actionCreators/sudoModal.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ export async function openSudo({
1515
closeEvents,
1616
...args
1717
}: OpenSudoModalOptions = {}) {
18-
const mod = await import('sentry/components/modals/sudoModal');
19-
const {default: Modal} = mod;
18+
const {default: Modal} = await import('sentry/components/modals/sudoModal');
2019

2120
ModalStore.openModal(deps => <Modal {...deps} {...args} />, {onClose, closeEvents});
2221
}

0 commit comments

Comments
 (0)