2025-03-04 21:09:54 +08:00
|
|
|
import { useMemo } from 'react';
|
2025-02-07 22:50:53 +08:00
|
|
|
|
2025-03-04 21:09:54 +08:00
|
|
|
import { Input } from '@grafana/ui';
|
2025-02-07 22:50:53 +08:00
|
|
|
import { t } from 'app/core/internationalization';
|
|
|
|
|
import { OptionsPaneCategoryDescriptor } from 'app/features/dashboard/components/PanelEditor/OptionsPaneCategoryDescriptor';
|
|
|
|
|
import { OptionsPaneItemDescriptor } from 'app/features/dashboard/components/PanelEditor/OptionsPaneItemDescriptor';
|
|
|
|
|
|
|
|
|
|
import { useLayoutCategory } from '../layouts-shared/DashboardLayoutSelector';
|
2025-03-10 15:03:55 +08:00
|
|
|
import { useEditPaneInputAutoFocus } from '../layouts-shared/utils';
|
2025-02-07 22:50:53 +08:00
|
|
|
|
|
|
|
|
import { TabItem } from './TabItem';
|
|
|
|
|
|
|
|
|
|
export function getEditOptions(model: TabItem): OptionsPaneCategoryDescriptor[] {
|
|
|
|
|
const { layout } = model.useState();
|
|
|
|
|
|
2025-03-20 17:37:27 +08:00
|
|
|
const tabCategory = useMemo(
|
|
|
|
|
() =>
|
|
|
|
|
new OptionsPaneCategoryDescriptor({ title: '', id: 'tab-item-options' }).addItem(
|
|
|
|
|
new OptionsPaneItemDescriptor({
|
|
|
|
|
title: t('dashboard.tabs-layout.tab-options.title-option', 'Title'),
|
|
|
|
|
render: () => <TabTitleInput tab={model} />,
|
|
|
|
|
})
|
|
|
|
|
),
|
|
|
|
|
[model]
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const layoutCategory = useLayoutCategory(layout);
|
|
|
|
|
|
|
|
|
|
return [tabCategory, layoutCategory];
|
2025-02-07 22:50:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function TabTitleInput({ tab }: { tab: TabItem }) {
|
|
|
|
|
const { title } = tab.useState();
|
2025-03-10 15:03:55 +08:00
|
|
|
const ref = useEditPaneInputAutoFocus();
|
2025-02-07 22:50:53 +08:00
|
|
|
|
2025-03-10 15:03:55 +08:00
|
|
|
return <Input ref={ref} value={title} onChange={(e) => tab.onChangeTitle(e.currentTarget.value)} />;
|
2025-02-07 22:50:53 +08:00
|
|
|
}
|