buster/web/src/controllers/DashboardController/DashboardViewDashboardContr.../DashboardEditTitle.tsx

62 lines
1.8 KiB
TypeScript
Raw Normal View History

2025-03-22 04:03:43 +08:00
import { useDebounceFn, useMemoizedFn } from '@/hooks';
2025-03-02 08:44:26 +08:00
import { EditableTitle } from '@/components/ui/typography/EditableTitle';
2025-02-06 07:43:18 +08:00
import React from 'react';
2025-04-09 03:32:00 +08:00
import { useUpdateDashboard } from '@/api/buster_rest/dashboards';
import { InputTextArea } from '@/components/ui/inputs/InputTextArea';
2025-02-06 07:43:18 +08:00
2025-03-18 06:55:12 +08:00
export const DASHBOARD_TITLE_INPUT_ID = 'dashboard-title-input';
const descriptionAutoResize = {
minRows: 1,
maxRows: 25
};
2025-02-06 07:43:18 +08:00
export const DashboardEditTitles: React.FC<{
title: string;
description: string;
2025-03-19 04:19:56 +08:00
readOnly?: boolean;
2025-02-08 03:45:47 +08:00
dashboardId: string;
2025-04-09 03:32:00 +08:00
}> = React.memo(({ readOnly, title, description, dashboardId }) => {
const { mutateAsync: onUpdateDashboard } = useUpdateDashboard({
saveToServer: false
});
2025-02-13 14:11:44 +08:00
const onChangeTitle = useMemoizedFn((name: string) => {
2025-03-19 04:19:56 +08:00
if (!readOnly) onUpdateDashboard({ name, id: dashboardId });
2025-02-06 07:43:18 +08:00
});
2025-04-10 04:00:48 +08:00
const onChangeDashboardDescription = useMemoizedFn(
(value: React.ChangeEvent<HTMLTextAreaElement>) => {
2025-03-19 04:19:56 +08:00
if (!readOnly) onUpdateDashboard({ description: value.target.value, id: dashboardId });
2025-04-10 04:00:48 +08:00
}
2025-02-06 07:43:18 +08:00
);
return (
<div className="flex flex-col space-y-1.5">
2025-02-06 07:43:18 +08:00
<EditableTitle
className="w-full truncate"
2025-03-19 04:19:56 +08:00
readOnly={readOnly}
2025-04-10 04:00:48 +08:00
onSetValue={onChangeTitle}
2025-02-06 07:43:18 +08:00
onChange={onChangeTitle}
2025-03-18 06:55:12 +08:00
id={DASHBOARD_TITLE_INPUT_ID}
2025-03-21 06:05:59 +08:00
placeholder="New dashboard"
2025-03-02 14:19:50 +08:00
level={3}>
2025-02-06 07:43:18 +08:00
{title}
</EditableTitle>
2025-03-19 04:19:56 +08:00
{(description || !readOnly) && (
<InputTextArea
2025-03-08 07:02:56 +08:00
variant="ghost"
className={'py-0! pl-0!'}
2025-03-19 04:19:56 +08:00
readOnly={readOnly}
2025-02-06 07:43:18 +08:00
onChange={onChangeDashboardDescription}
defaultValue={description}
autoResize={descriptionAutoResize}
2025-02-06 07:43:18 +08:00
placeholder="Add description..."
/>
)}
</div>
);
});
DashboardEditTitles.displayName = 'DashboardEditTitles';