From 1b9d4ce8114683d95e8b073ebc2b9ba0b5b61399 Mon Sep 17 00:00:00 2001 From: Vadim Ogievetsky Date: Sat, 26 Oct 2019 17:58:26 -0700 Subject: [PATCH] Web console: Memoize all the functional components and improve transform step highlighting (#8757) * Fix transform table * memoize all components * use named functions --- .../components/action-cell/action-cell.tsx | 4 +-- .../components/action-icon/action-icon.tsx | 4 +-- .../center-message/center-message.tsx | 4 +-- .../clearable-input/clearable-input.tsx | 4 +-- .../src/components/deferred/deferred.tsx | 6 ++-- .../external-link/external-link.tsx | 4 +-- .../src/components/header-bar/header-bar.tsx | 4 +-- web-console/src/components/loader/loader.tsx | 4 +-- .../refresh-button/refresh-button.tsx | 4 +-- .../components/rule-editor/rule-editor.tsx | 4 +-- .../src/components/show-value/show-value.tsx | 4 +-- .../src/components/table-cell/table-cell.tsx | 4 +-- .../table-column-selector.tsx | 6 ++-- .../view-control-bar/view-control-bar.tsx | 4 +-- .../src/dialogs/about-dialog/about-dialog.tsx | 4 +-- .../async-action-dialog.tsx | 6 ++-- .../datasource-table-action-dialog.tsx | 6 ++-- .../edit-context-dialog.tsx | 6 ++-- .../dialogs/history-dialog/history-dialog.tsx | 4 +-- .../lookup-edit-dialog/lookup-edit-dialog.tsx | 4 +-- .../query-history-dialog.tsx | 6 ++-- .../query-plan-dialog/query-plan-dialog.tsx | 4 +-- .../segment-table-action-dialog.tsx | 6 ++-- .../show-value-dialog/show-value-dialog.tsx | 4 +-- .../src/dialogs/spec-dialog/spec-dialog.tsx | 4 +-- .../supervisor-table-action-dialog.tsx | 6 ++-- .../table-action-dialog.tsx | 6 ++-- .../task-table-action-dialog.tsx | 6 ++-- web-console/src/utils/render-spy.ts | 29 +++++++++++++++++++ .../datasource-view.spec.tsx.snap | 8 ++--- .../home-view-card/home-view-card.tsx | 4 +-- web-console/src/views/home-view/home-view.tsx | 4 +-- .../example-picker/example-picker.tsx | 4 +-- .../filter-table/filter-table.tsx | 4 +-- .../views/load-data-view/load-data-view.tsx | 13 +++++++-- .../parse-data-table/parse-data-table.tsx | 4 +-- .../parse-time-table/parse-time-table.tsx | 4 +-- .../schema-table/schema-table.tsx | 4 +-- .../transform-table/transform-table.spec.tsx | 2 +- .../transform-table/transform-table.tsx | 20 +++++++++---- .../__snapshots__/lookups-view.spec.tsx.snap | 8 ++--- .../__snapshots__/query-view.spec.tsx.snap | 2 +- .../number-menu-items/number-menu-items.tsx | 4 +-- .../string-menu-items/string-menu-items.tsx | 4 +-- .../time-menu-items/time-menu-items.tsx | 4 +-- .../query-extra-info/query-extra-info.tsx | 4 +-- .../query-view/query-output/query-output.tsx | 4 +-- .../__snapshots__/segments-view.spec.tsx.snap | 8 ++--- .../__snapshots__/servers-view.spec.tsx.snap | 8 ++--- .../__snapshots__/tasks-view.spec.tsx.snap | 16 +++++----- web-console/src/visualization/chart-axis.tsx | 4 +-- .../src/visualization/stacked-bar-chart.tsx | 4 +-- 52 files changed, 184 insertions(+), 118 deletions(-) create mode 100644 web-console/src/utils/render-spy.ts diff --git a/web-console/src/components/action-cell/action-cell.tsx b/web-console/src/components/action-cell/action-cell.tsx index 6b13dd84102..2bc8988df00 100644 --- a/web-console/src/components/action-cell/action-cell.tsx +++ b/web-console/src/components/action-cell/action-cell.tsx @@ -34,7 +34,7 @@ export interface ActionCellProps { actions?: BasicAction[]; } -export function ActionCell(props: ActionCellProps) { +export const ActionCell = React.memo(function ActionCell(props: ActionCellProps) { const { onDetail, actions } = props; const actionsMenu = actions ? basicActionsToMenu(actions) : null; @@ -48,4 +48,4 @@ export function ActionCell(props: ActionCellProps) { )} ); -} +}); diff --git a/web-console/src/components/action-icon/action-icon.tsx b/web-console/src/components/action-icon/action-icon.tsx index 36e558d365d..6e16883a898 100644 --- a/web-console/src/components/action-icon/action-icon.tsx +++ b/web-console/src/components/action-icon/action-icon.tsx @@ -28,8 +28,8 @@ export interface ActionIconProps { onClick?: () => void; } -export function ActionIcon(props: ActionIconProps) { +export const ActionIcon = React.memo(function ActionIcon(props: ActionIconProps) { const { className, icon, onClick } = props; return ; -} +}); diff --git a/web-console/src/components/center-message/center-message.tsx b/web-console/src/components/center-message/center-message.tsx index a600ddfd52c..206f68d7e5f 100644 --- a/web-console/src/components/center-message/center-message.tsx +++ b/web-console/src/components/center-message/center-message.tsx @@ -24,7 +24,7 @@ export interface CenterMessageProps { children?: ReactNode; } -export function CenterMessage(props: CenterMessageProps) { +export const CenterMessage = React.memo(function CenterMessage(props: CenterMessageProps) { const { children } = props; return ( @@ -32,4 +32,4 @@ export function CenterMessage(props: CenterMessageProps) {
{children}
); -} +}); diff --git a/web-console/src/components/clearable-input/clearable-input.tsx b/web-console/src/components/clearable-input/clearable-input.tsx index 1764e69c239..9ea33a1bef6 100644 --- a/web-console/src/components/clearable-input/clearable-input.tsx +++ b/web-console/src/components/clearable-input/clearable-input.tsx @@ -28,7 +28,7 @@ export interface ClearableInputProps { placeholder: string; } -export function ClearableInput(props: ClearableInputProps) { +export const ClearableInput = React.memo(function ClearableInput(props: ClearableInputProps) { const { className, value, onChange, placeholder } = props; return ( @@ -42,4 +42,4 @@ export function ClearableInput(props: ClearableInputProps) { placeholder={placeholder} /> ); -} +}); diff --git a/web-console/src/components/deferred/deferred.tsx b/web-console/src/components/deferred/deferred.tsx index e12ad1bd844..38264483171 100644 --- a/web-console/src/components/deferred/deferred.tsx +++ b/web-console/src/components/deferred/deferred.tsx @@ -16,10 +16,12 @@ * limitations under the License. */ +import React from 'react'; + export interface DeferredProps { content: () => JSX.Element; } -export function Deferred(props: DeferredProps) { +export const Deferred = React.memo(function Deferred(props: DeferredProps) { return props.content(); -} +}); diff --git a/web-console/src/components/external-link/external-link.tsx b/web-console/src/components/external-link/external-link.tsx index b8127621126..f79d7507efe 100644 --- a/web-console/src/components/external-link/external-link.tsx +++ b/web-console/src/components/external-link/external-link.tsx @@ -23,7 +23,7 @@ export interface ExternalLinkProps { children?: ReactNode; } -export function ExternalLink(props: ExternalLinkProps) { +export const ExternalLink = React.memo(function ExternalLink(props: ExternalLinkProps) { const { href, children } = props; return ( @@ -31,4 +31,4 @@ export function ExternalLink(props: ExternalLinkProps) { {children} ); -} +}); diff --git a/web-console/src/components/header-bar/header-bar.tsx b/web-console/src/components/header-bar/header-bar.tsx index 7b78bf2f74d..12b4a756c03 100644 --- a/web-console/src/components/header-bar/header-bar.tsx +++ b/web-console/src/components/header-bar/header-bar.tsx @@ -132,7 +132,7 @@ export interface HeaderBarProps { hideLegacy: boolean; } -export function HeaderBar(props: HeaderBarProps) { +export const HeaderBar = React.memo(function HeaderBar(props: HeaderBarProps) { const { active, hideLegacy } = props; const [aboutDialogOpen, setAboutDialogOpen] = useState(false); const [doctorDialogOpen, setDoctorDialogOpen] = useState(false); @@ -264,4 +264,4 @@ export function HeaderBar(props: HeaderBarProps) { )} ); -} +}); diff --git a/web-console/src/components/loader/loader.tsx b/web-console/src/components/loader/loader.tsx index a182d2fcb1f..36c4498c55b 100644 --- a/web-console/src/components/loader/loader.tsx +++ b/web-console/src/components/loader/loader.tsx @@ -25,7 +25,7 @@ export interface LoaderProps { loading?: boolean; // This is needed so that this component can be used as a LoadingComponent in react table } -export function Loader(props: LoaderProps) { +export const Loader = React.memo(function Loader(props: LoaderProps) { const { loadingText, loading } = props; if (!loading) return null; @@ -59,4 +59,4 @@ export function Loader(props: LoaderProps) { ); -} +}); diff --git a/web-console/src/components/refresh-button/refresh-button.tsx b/web-console/src/components/refresh-button/refresh-button.tsx index 5d0df279e82..180316159a3 100644 --- a/web-console/src/components/refresh-button/refresh-button.tsx +++ b/web-console/src/components/refresh-button/refresh-button.tsx @@ -27,7 +27,7 @@ export interface RefreshButtonProps { localStorageKey?: LocalStorageKeys; } -export function RefreshButton(props: RefreshButtonProps) { +export const RefreshButton = React.memo(function RefreshButton(props: RefreshButtonProps) { const { onRefresh, localStorageKey } = props; const intervals = [ { label: '5 seconds', value: 5000 }, @@ -49,4 +49,4 @@ export function RefreshButton(props: RefreshButtonProps) { localStorageKey={localStorageKey} /> ); -} +}); diff --git a/web-console/src/components/rule-editor/rule-editor.tsx b/web-console/src/components/rule-editor/rule-editor.tsx index 7c12f156832..be8a738de57 100644 --- a/web-console/src/components/rule-editor/rule-editor.tsx +++ b/web-console/src/components/rule-editor/rule-editor.tsx @@ -43,7 +43,7 @@ export interface RuleEditorProps { moveDown: (() => void) | null; } -export function RuleEditor(props: RuleEditorProps) { +export const RuleEditor = React.memo(function RuleEditor(props: RuleEditorProps) { const { rule, onChange, tiers, onDelete, moveUp, moveDown } = props; const [isOpen, setIsOpen] = useState(true); if (!rule) return null; @@ -223,4 +223,4 @@ export function RuleEditor(props: RuleEditorProps) { ); -} +}); diff --git a/web-console/src/components/show-value/show-value.tsx b/web-console/src/components/show-value/show-value.tsx index 9e161e87af2..59afd2f07de 100644 --- a/web-console/src/components/show-value/show-value.tsx +++ b/web-console/src/components/show-value/show-value.tsx @@ -30,7 +30,7 @@ export interface ShowValueProps { jsonValue?: string; } -export function ShowValue(props: ShowValueProps) { +export const ShowValue = React.memo(function ShowValue(props: ShowValueProps) { const { endpoint, downloadFilename, jsonValue } = props; return (
@@ -57,4 +57,4 @@ export function ShowValue(props: ShowValueProps) {
); -} +}); diff --git a/web-console/src/components/table-cell/table-cell.tsx b/web-console/src/components/table-cell/table-cell.tsx index d02aeca5a76..e252cc9cc34 100644 --- a/web-console/src/components/table-cell/table-cell.tsx +++ b/web-console/src/components/table-cell/table-cell.tsx @@ -51,7 +51,7 @@ export interface TableCellProps { unparseable?: boolean; } -export function TableCell(props: TableCellProps): JSX.Element { +export const TableCell = React.memo(function TableCell(props: TableCellProps) { const { value, timestamp, unparseable } = props; const [showValue, setShowValue] = useState(); @@ -97,4 +97,4 @@ export function TableCell(props: TableCellProps): JSX.Element { return null; } } -} +}); diff --git a/web-console/src/components/table-column-selector/table-column-selector.tsx b/web-console/src/components/table-column-selector/table-column-selector.tsx index 4e006bc85da..1602afa9538 100644 --- a/web-console/src/components/table-column-selector/table-column-selector.tsx +++ b/web-console/src/components/table-column-selector/table-column-selector.tsx @@ -30,7 +30,9 @@ interface TableColumnSelectorProps { tableColumnsHidden: string[]; } -export function TableColumnSelector(props: TableColumnSelectorProps) { +export const TableColumnSelector = React.memo(function TableColumnSelector( + props: TableColumnSelectorProps, +) { const { columns, onChange, tableColumnsHidden } = props; const checkboxes = ( @@ -54,4 +56,4 @@ export function TableColumnSelector(props: TableColumnSelectorProps) {