Skip to content

Commit be4c100

Browse files
committed
OU-1264: address review comments
1 parent 2052c6f commit be4c100

7 files changed

Lines changed: 22 additions & 14 deletions

File tree

web/src/components/dashboards/perses/PersesWrapper.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,12 @@ export function PersesWrapper({ children, project }: PersesWrapperProps) {
400400
);
401401
}
402402

403-
function InnerWrapper({ children, project }) {
403+
interface InnerWrapperProps {
404+
children?: React.ReactNode;
405+
project: string;
406+
}
407+
408+
function InnerWrapper({ children, project }: InnerWrapperProps) {
404409
const [dashboardName] = useQueryParam(QueryParams.Dashboard, StringParam);
405410
const { data } = usePluginBuiltinVariableDefinitions();
406411
const { persesDashboard, persesDashboardLoading } = useFetchPersesDashboard(

web/src/components/dashboards/perses/dashboard-app.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { useUpdateDashboardMutation } from './dashboard-api';
2929
import { useTranslation } from 'react-i18next';
3030
import { useToast } from './ToastProvider';
3131
import { useSearchParams } from 'react-router';
32-
import { useExternalPanelAddition } from './useExternalPanelAddition';
32+
import { setupExternalPanelAddition } from './setupExternalPanelAddition';
3333

3434
export interface DashboardAppProps {
3535
dashboardResource: DashboardResource | EphemeralDashboardResource;
@@ -125,7 +125,9 @@ export const OCPDashboardApp = (props: DashboardAppProps): ReactElement => {
125125
}
126126
};
127127

128-
useExternalPanelAddition({ isEditMode, onEditButtonClick });
128+
// Register hooks related to exposing adding panels from external intergrations.
129+
// See components/ols-tool-ui/helpers/AddToDashboardButton.tsx for example use.
130+
setupExternalPanelAddition({ isEditMode, onEditButtonClick });
129131

130132
const updateDashboardMutation = useUpdateDashboardMutation();
131133

web/src/components/dashboards/perses/useExternalPanelAddition.ts renamed to web/src/components/dashboards/perses/setupExternalPanelAddition.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { useDispatch, useSelector } from 'react-redux';
33
import { useDashboardActions, useDashboardStore } from '@perses-dev/dashboards';
44
import { dashboardsOpened, dashboardsPersesPanelExternallyAdded } from '../../../store/actions';
55

6-
interface UseExternalPanelAdditionOptions {
6+
interface SetupExternalPanelAdditionOptions {
77
isEditMode: boolean;
88
onEditButtonClick: () => void;
99
}
1010

11-
export function useExternalPanelAddition({
11+
export function setupExternalPanelAddition({
1212
isEditMode,
1313
onEditButtonClick,
14-
}: UseExternalPanelAdditionOptions) {
14+
}: SetupExternalPanelAdditionOptions) {
1515
const dispatch = useDispatch();
1616
const addPersesPanelExternally: any = useSelector(
1717
(s: any) => s.plugins?.mcp?.dashboards?.addPersesPanelExternally,
@@ -67,7 +67,7 @@ export function useExternalPanelAddition({
6767
addPersesPanelExternally,
6868
]);
6969

70-
// Advertise when custom dashboard is opened/closed
70+
// Advertise when a dashboard is opened/closed
7171
useEffect(() => {
7272
dispatch(dashboardsOpened(true));
7373
return () => {

web/src/components/ols-tool-ui/ShowTimeseries.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { OlsToolUIPersesWrapper } from './helpers/OlsToolUIPersesWrapper';
77
import { AddToDashboardButton } from './helpers/AddToDashboardButton';
88
import { useTimeRange } from './helpers/useTimeRange';
99

10-
type ExecuteRangeQueryTool = {
10+
type ShowTimeseriesTool = {
1111
args: {
1212
title: string;
1313
description: string;
@@ -18,7 +18,7 @@ type ExecuteRangeQueryTool = {
1818
};
1919
};
2020

21-
export const ShowTimeseries: React.FC<{ tool: ExecuteRangeQueryTool }> = ({ tool }) => {
21+
export const ShowTimeseries: React.FC<{ tool: ShowTimeseriesTool }> = ({ tool }) => {
2222
const { t } = useTranslation(process.env.I18N_NAMESPACE);
2323
const { query, title, description, start, end, duration } = tool.args;
2424
const timeRange = useTimeRange(start, end, duration);

web/src/components/ols-tool-ui/helpers/AddToDashboardButton.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,13 @@ export const AddToDashboardButton: React.FC<AddToDashboardButtonProps> = ({
6060
}) => {
6161
const dispatch = useDispatch();
6262
const { t } = useTranslation(process.env.I18N_NAMESPACE);
63-
const isCustomDashboardOpen: boolean = useSelector(
64-
(s: any) => s.plugins?.mcp?.dashboards?.isOpened,
65-
);
63+
const isDashboardOpen: boolean = useSelector((s: any) => s.plugins?.mcp?.dashboards?.isOpened);
6664
const addToPersesDashboard = React.useCallback(() => {
6765
const panelDefinition = createPanelDefinition(query, name, description);
6866
dispatch(dashboardsAddPersesPanelExternally(panelDefinition));
6967
}, [query, name, description, dispatch]);
7068

71-
if (!isCustomDashboardOpen) {
69+
if (!isDashboardOpen) {
7270
// No dashboard is opened - nothing to add to.
7371
return null;
7472
}

web/src/store/actions.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ type Actions = {
224224
dashboardsSetPollInterval: typeof dashboardsSetPollInterval;
225225
dashboardsSetTimespan: typeof dashboardsSetTimespan;
226226
dashboardsVariableOptionsLoaded: typeof dashboardsVariableOptionsLoaded;
227+
dashboardsOpened: typeof dashboardsOpened;
228+
dashboardsPersesPanelExternallyAdded: typeof dashboardsPersesPanelExternallyAdded;
229+
dashboardsAddPersesPanelExternally: typeof dashboardsAddPersesPanelExternally;
227230
queryBrowserAddQuery: typeof queryBrowserAddQuery;
228231
queryBrowserDuplicateQuery: typeof queryBrowserDuplicateQuery;
229232
queryBrowserDeleteAllQueries: typeof queryBrowserDeleteAllQueries;

web/src/store/store.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export type ObserveState = {
2929
timespan: number;
3030
variables: Record<string, Variable>;
3131
isOpened: boolean;
32-
addPersesPanelExternally: PanelDefinition;
32+
addPersesPanelExternally: PanelDefinition | null;
3333
};
3434
incidentsData: {
3535
incidents: Array<any>;

0 commit comments

Comments
 (0)