Skip to content

Commit a57a97a

Browse files
authored
StatsHouse UI: Show info link for exist metric in error (#1977)
1 parent 756de61 commit a57a97a

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

statshouse-ui/src/admin/pages/CreatePage.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
66

77
import * as React from 'react';
8-
import { useNavigate } from 'react-router-dom';
8+
import { Link, useNavigate } from 'react-router-dom';
99
import { IMetric } from '../models/metric';
1010
import { saveMetric } from '../api/saveMetric';
11-
import { maxTagsSize } from '../../common/settings';
11+
import { maxTagsSize } from '@/common/settings';
1212
import { getDefaultTag } from '../storages/MetricFormValues/reducer';
13+
import { useMetricMeta } from '@/hooks/useMetricMeta';
1314

1415
export function CreatePage(props: { yAxisSize: number }) {
1516
const { yAxisSize } = props;
@@ -64,7 +65,9 @@ export function EditFormCreate() {
6465
<span className="visually-hidden">Loading...</span>
6566
</div>
6667
) : error ? (
67-
<span className="text-danger">{error}</span>
68+
<span className="text-danger">
69+
{error} <MetricInfo metricName={name} />
70+
</span>
6871
) : success ? (
6972
<span className="text-success">{success}</span>
7073
) : null}
@@ -122,3 +125,18 @@ function useSubmitCreate(name: string) {
122125
success,
123126
};
124127
}
128+
129+
type MetricInfoProps = { metricName: string };
130+
131+
function MetricInfo({ metricName }: MetricInfoProps) {
132+
const meta = useMetricMeta(metricName, true);
133+
if (!meta) {
134+
return null;
135+
}
136+
return (
137+
<span>
138+
{meta.disable && <span>and disabled. </span>}
139+
<Link to={`/admin/edit/${metricName}`}>Edit</Link> <Link to={`/view?s=${metricName}`}>View</Link>
140+
</span>
141+
);
142+
}

0 commit comments

Comments
 (0)