Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#10776] OpenTelemetry > Save the changed layouts when create/edit/delete #11587

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,25 @@ export const OpenTelemetryDashboardFetcher = () => {
buttonVariant={{ variant: 'destructive' }}
onClick={() => {
if (currentDeletingTarget && metrics) {
const targetExceptedMetrics = metrics.filter(
(m) => m.id !== currentDeletingTarget.id,
);
const targetExceptedMetrics = metrics
.filter((m) => m.id !== currentDeletingTarget.id)
?.map((m) => {
const layoutByMetric = state?.layouts?.sm?.find(
(layout) => layout?.i === m?.id,
);

return {
...m,
layout: layoutByMetric
? {
w: layoutByMetric?.w,
h: layoutByMetric?.h,
x: layoutByMetric?.x,
y: layoutByMetric?.y,
}
: m?.layout,
};
});
updateMetricsWithToastMessage(
{
applicationName,
Expand All @@ -316,6 +332,7 @@ export const OpenTelemetryDashboardFetcher = () => {
</AlertDialogContent>
</AlertDialog>
<MetricDefinitionSheet
layouts={state?.layouts}
metric={currentEditingTarget}
open={!!currentEditingTarget}
onOpenChange={(open) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ const metricDefinitionFormSchemaFactory = (t: TFunction) => {
};

export interface MetricDefinitionFormFetcherProps {
layouts?: ReactGridLayout.Layouts;
metric?: OtlpMetricDefUserDefined.Metric;
onComplete?: () => void;
onClickCancel?: () => void;
}

export const MetricDefinitionFormFetcher = ({
layouts,
metric,
onComplete,
onClickCancel,
Expand Down Expand Up @@ -250,35 +252,50 @@ export const MetricDefinitionFormFetcher = ({
};

const handleSubmit = async (data: z.infer<typeof metricDefinitionFormSchema>) => {
if (metric?.id) {
// 수정
updateMetrics({
applicationName,
appMetricDefinitionList: [
...(metrics || []).filter((m) => m.id !== metric?.id),
{
const appMetricDefinitionList = [
...(metrics || []).map((m) => {
const layoutByMetric = layouts?.sm?.find((layout) => layout?.i === m?.id);

const layout = layoutByMetric
? {
w: layoutByMetric?.w,
h: layoutByMetric?.h,
x: layoutByMetric?.x,
y: layoutByMetric?.y,
}
: m?.layout;

if (m?.id === metric?.id) {
return {
...data,
id: metric?.id,
applicationName,
stack: !!data.stack,
stackDetails: data?.stack ? data?.stackDetails : undefined,
layout: {
w: metric?.layout.w,
h: metric?.layout.h,
x: metric?.layout.x,
y: metric?.layout.y,
},
// TODO:
unit: 'byte',
},
],
layout,
};
} else {
return {
...m,
layout,
};
}
}),
];

if (metric?.id) {
// 수정
updateMetrics({
applicationName,
appMetricDefinitionList,
});
} else {
// 신규
updateMetrics({
applicationName,
appMetricDefinitionList: [
...(metrics || []),
...(appMetricDefinitionList || []),
{
...data,
applicationName,
Expand All @@ -287,7 +304,6 @@ export const MetricDefinitionFormFetcher = ({
layout: {
...getNewWidgetLayout(metrics || []),
},
// TODO:
unit: 'byte',
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ import { PreviewChart } from '../charts';
import { OtlpMetricDefUserDefined } from '@pinpoint-fe/constants';

export interface MetricDefinitionSheetProps extends SheetPrimitive.DialogProps {
layouts?: ReactGridLayout.Layouts;
metric?: OtlpMetricDefUserDefined.Metric;
onCancel?: () => void;
}

export const MetricDefinitionSheet = ({
layouts,
metric,
onCancel,
...props
Expand Down Expand Up @@ -50,6 +52,7 @@ export const MetricDefinitionSheet = ({
<PreviewChart />
<Separator />
<MetricDefinitionForm
layouts={layouts}
metric={metric}
onComplete={() => {
onCancel?.();
Expand Down