Skip to content

Commit

Permalink
ui: fixed insights table bug on insights
Browse files Browse the repository at this point in the history
 cockroachdb#96440 introduced a bug to the Insights Table on the Schema
Insights page. This commit fixes that bug.

Release note: None
Epic: None
ericharmeling committed Feb 17, 2023
1 parent c00dbe8 commit 868b3ce
Showing 5 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@ export const StatementInsightDetailsOverviewTab: React.FC<
const isCockroachCloud = useContext(CockroachCloudContext);

const insightsColumns = useMemo(
() => makeInsightsColumns(isCockroachCloud, hasAdminRole, true),
() => makeInsightsColumns(isCockroachCloud, hasAdminRole),
[isCockroachCloud, hasAdminRole],
);

25 changes: 15 additions & 10 deletions pkg/ui/workspaces/cluster-ui/src/insightsTable/insightsTable.tsx
Original file line number Diff line number Diff line change
@@ -131,11 +131,15 @@ const StatementExecution = ({

function descriptionCell(
insightRec: InsightRecommendation,
isExecution: boolean,
disableStmtLink: boolean,
isCockroachCloud: boolean,
isFingerprint: boolean,
): React.ReactElement {
const stmtLink = isIndexRec(insightRec) ? (
<StatementExecution rec={insightRec} disableLink={!isExecution} />
<StatementExecution
rec={insightRec}
disableLink={disableStmtLink || isFingerprint}
/>
) : null;

const clusterSettingsLink = (
@@ -201,15 +205,15 @@ function descriptionCell(
case "HighContention":
return (
<>
{isExecution && (
{!isFingerprint && (
<div className={cx("description-item")}>
<span className={cx("label-bold")}>Time Spent Waiting: </span>{" "}
{Duration(insightRec.details.duration * 1e6)}
</div>
)}
{stmtLink}
<div className={cx("description-item")}>
{isExecution && (
{!isFingerprint && (
<span className={cx("label-bold")}>Description: </span>
)}
{insightRec.details.description} {clusterSettingsLink}
@@ -272,15 +276,15 @@ function descriptionCell(
case "Unknown":
return (
<>
{isExecution && (
{!isFingerprint && (
<div className={cx("description-item")}>
<span className={cx("label-bold")}>Elapsed Time: </span>
{Duration(insightRec.details.duration * 1e6)}
</div>
)}
{stmtLink}
<div className={cx("description-item")}>
{isExecution && (
{!isFingerprint && (
<span className={cx("label-bold")}>Description: </span>
)}
{insightRec.details.description} {clusterSettingsLink}
@@ -390,7 +394,8 @@ const isIndexRec = (rec: InsightRecommendation) => {
export function makeInsightsColumns(
isCockroachCloud: boolean,
hasAdminRole: boolean,
isExecution?: boolean,
disableStmtLink?: boolean,
isFingerprint?: boolean,
): ColumnDescriptor<InsightRecommendation>[] {
const columns: ColumnDescriptor<InsightRecommendation>[] = [
{
@@ -403,17 +408,17 @@ export function makeInsightsColumns(
name: "details",
title: insightsTableTitles.details(),
cell: (item: InsightRecommendation) =>
descriptionCell(item, isExecution, isCockroachCloud),
descriptionCell(item, disableStmtLink, isCockroachCloud, isFingerprint),
sort: (item: InsightRecommendation) => item.type,
},
{
name: "action",
title: insightsTableTitles.actions(),
cell: (item: InsightRecommendation) =>
actionCell(item, isCockroachCloud || !hasAdminRole || !isExecution),
actionCell(item, isCockroachCloud || !hasAdminRole || isFingerprint),
},
];
if (!isExecution) {
if (isFingerprint) {
columns.push({
name: "latestExecution",
title: insightsTableTitles.latestExecution(),
Original file line number Diff line number Diff line change
@@ -295,7 +295,7 @@ export function Insights({
hasAdminRole,
}: InsightsProps): React.ReactElement {
const hideAction = useContext(CockroachCloudContext) || database?.length == 0;
const insightsColumns = makeInsightsColumns(hideAction, hasAdminRole, false);
const insightsColumns = makeInsightsColumns(hideAction, hasAdminRole, true);
const data = formatIdxRecommendations(
idxRecommendations,
database,
Original file line number Diff line number Diff line change
@@ -665,7 +665,8 @@ export class StatementDetails extends React.Component<
const insightsColumns = makeInsightsColumns(
isCockroachCloud,
this.props.hasAdminRole,
false,
true,
true,
);
const tableData: InsightRecommendation[] = [];
if (statementFingerprintInsights) {
Original file line number Diff line number Diff line change
@@ -456,7 +456,8 @@ export class TransactionDetails extends React.Component<
const insightsColumns = makeInsightsColumns(
isCockroachCloud,
this.props.hasAdminRole,
false,
true,
true,
);
const tableData: InsightRecommendation[] = [];
if (transactionInsights) {

0 comments on commit 868b3ce

Please sign in to comment.