Skip to content

Commit 2760184

Browse files
lzhao-sentryandrewshie-sentry
authored andcommitted
chore(cell-actions): use built-in external linking instead of helper function (#97567)
### Changes Move external linking for cell actions V2 into menu item's `externalHref` prop so there's no need to call the `openExternalLink` helper function in the switch case. There are no visual UI changes for this PR
1 parent c52797c commit 2760184

File tree

3 files changed

+4
-24
lines changed

3 files changed

+4
-24
lines changed

static/app/views/dashboards/widgets/tableWidget/tableWidgetVisualization.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import GridEditable, {COL_WIDTH_UNDEFINED} from 'sentry/components/tables/gridEd
66
import SortLink from 'sentry/components/tables/gridEditable/sortLink';
77
import {defined} from 'sentry/utils';
88
import {getSortField} from 'sentry/utils/dashboards/issueFieldRenderers';
9+
import type {TableDataRow} from 'sentry/utils/discover/discoverQuery';
910
import type {MetaType} from 'sentry/utils/discover/eventView';
1011
import type {RenderFunctionBaggage} from 'sentry/utils/discover/fieldRenderers';
1112
import {getFieldRenderer} from 'sentry/utils/discover/fieldRenderers';
@@ -29,7 +30,6 @@ import type {
2930
import CellAction, {
3031
Actions,
3132
copyToClipboard,
32-
openExternalLink,
3333
} from 'sentry/views/discover/table/cellAction';
3434

3535
type FieldRendererGetter = (
@@ -283,17 +283,13 @@ export function TableWidgetVisualization(props: TableWidgetVisualizationProps) {
283283
<CellAction
284284
key={`${rowIndex}-${columnIndex}:${tableColumn.name}`}
285285
column={formattedColumn}
286-
// id is not used by CellAction, but is required for the TableDataRow type
287-
dataRow={{...dataRow, id: ''}}
286+
dataRow={dataRow as TableDataRow}
288287
handleCellAction={(action: Actions, value: string | number) => {
289288
onTriggerCellAction?.(action, value);
290289
switch (action) {
291290
case Actions.COPY_TO_CLIPBOARD:
292291
copyToClipboard(value);
293292
break;
294-
case Actions.OPEN_EXTERNAL_LINK:
295-
openExternalLink(value);
296-
break;
297293
default:
298294
break;
299295
}

static/app/views/discover/table/cellAction.tsx

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ export function updateQuery(
9595
copyToClipboard(value);
9696
break;
9797
case Actions.OPEN_EXTERNAL_LINK:
98-
openExternalLink(value);
99-
break;
10098
case Actions.RELEASE:
10199
case Actions.DRILLDOWN:
102100
case Actions.OPEN_INTERNAL_LINK:
@@ -166,18 +164,6 @@ export function copyToClipboard(value: string | number | string[]) {
166164
});
167165
}
168166

169-
/**
170-
* If provided value is a valid url, opens the url in a new tab
171-
* @param value
172-
*/
173-
export function openExternalLink(value: string | number | string[]) {
174-
if (typeof value === 'string' && isUrl(value)) {
175-
window.open(value, '_blank', 'noopener,noreferrer');
176-
} else {
177-
addErrorMessage('Could not open link');
178-
}
179-
}
180-
181167
type CellActionsOpts = {
182168
column: TableColumn<keyof TableDataRow>;
183169
dataRow: TableDataRow;
@@ -235,6 +221,8 @@ function makeCellActions({
235221
textValue: itemTextValue,
236222
onAction: () => handleCellAction(action, value!),
237223
to: action === Actions.OPEN_INTERNAL_LINK && to ? stripURLOrigin(to) : undefined,
224+
externalHref:
225+
action === Actions.OPEN_EXTERNAL_LINK ? (value as string) : undefined,
238226
});
239227
}
240228
}

static/app/views/explore/logs/tables/logsTableRow.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import CellAction, {
1919
Actions,
2020
ActionTriggerType,
2121
copyToClipboard,
22-
openExternalLink,
2322
} from 'sentry/views/discover/table/cellAction';
2423
import type {TableColumn} from 'sentry/views/discover/table/types';
2524
import {AttributesTree} from 'sentry/views/explore/components/traceItemAttributes/attributesTree';
@@ -332,9 +331,6 @@ export const LogRowContent = memo(function LogRowContent({
332331
case Actions.COPY_TO_CLIPBOARD:
333332
copyToClipboard(cellValue);
334333
break;
335-
case Actions.OPEN_EXTERNAL_LINK:
336-
openExternalLink(cellValue);
337-
break;
338334
default:
339335
break;
340336
}

0 commit comments

Comments
 (0)