Browse Source

fix error status chanhing

pull/12/head
vargburz 2 years ago
parent
commit
308f6386ab
  1. 39
      src/panels/corpglory-dataexporter-panel/components/Panel.tsx

39
src/panels/corpglory-dataexporter-panel/components/Panel.tsx

@ -59,14 +59,19 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) {
const [selectedTimeRange, setTimeRange] = useState<TimeRange>(timeRange); const [selectedTimeRange, setTimeRange] = useState<TimeRange>(timeRange);
const [panelStatus, setPanelStatus] = useState<PanelStatus>(PanelStatus.LOADING); const [panelStatus, setPanelStatus] = useState<PanelStatus>(PanelStatus.LOADING);
const [isStatusError, setStatusError] = useState<boolean>(false); function setPanelStatusWithValidate(status: PanelStatus): void {
if (panelStatus === PanelStatus.DATASOURCE_ERROR || panelStatus === PanelStatus.PERMISSION_ERROR) {
return;
}
return setPanelStatus(status);
}
const [errorMessage, setErrorMessage] = useState<string | null>(null); const [errorMessage, setErrorMessage] = useState<string | null>(null);
const timeZoneName = convertTimeZoneTypeToName(timeZone); const timeZoneName = convertTimeZoneTypeToName(timeZone);
if (contextSrv.user.orgRole !== OrgRole.Admin) { if (contextSrv.user.orgRole !== OrgRole.Admin) {
// TODO: it shouldn't be overriten setPanelStatusWithValidate(PanelStatus.PERMISSION_ERROR);
setPanelStatus(PanelStatus.PERMISSION_ERROR);
} }
useEffect(() => { useEffect(() => {
@ -123,17 +128,7 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) {
setTasksDataFrame(dataFrame); setTasksDataFrame(dataFrame);
}, [tasks]); // eslint-disable-line react-hooks/exhaustive-deps }, [tasks]); // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => { useEffect(fetchTasks, []); // eslint-disable-line react-hooks/exhaustive-deps
if (isStatusError) {
return;
}
setPanelStatus(panelStatus);
if (panelStatus === PanelStatus.DATASOURCE_ERROR || panelStatus === PanelStatus.PERMISSION_ERROR) {
setStatusError(true);
}
}, [panelStatus]); // eslint-disable-line react-hooks/exhaustive-deps
useEffect(refresh, []); // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => { useEffect(() => {
if (queries === null) { if (queries === null) {
@ -142,26 +137,26 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) {
setQueriesDataFrame(getDataFrameForQueriesTable(queries)); setQueriesDataFrame(getDataFrameForQueriesTable(queries));
}, [queries]); // eslint-disable-line react-hooks/exhaustive-deps }, [queries]); // eslint-disable-line react-hooks/exhaustive-deps
function refresh(): void { function fetchTasks(): void {
getTasks() getTasks()
.then((tasks) => { .then((tasks) => {
setTasks(tasks); setTasks(tasks);
setPanelStatus(PanelStatus.OK); setPanelStatusWithValidate(PanelStatus.OK);
for (let task of tasks) { for (let task of tasks) {
if (task.progress?.status === ExportStatus.EXPORTING) { if (task.progress?.status === ExportStatus.EXPORTING) {
setTimeout(refresh, 1000); setTimeout(fetchTasks, 1000);
return; return;
} }
} }
}) })
.catch((err) => { .catch((err) => {
setPanelStatus(PanelStatus.DATASOURCE_ERROR); setPanelStatusWithValidate(PanelStatus.DATASOURCE_ERROR);
console.error('some error', err); console.error('some error', err);
setErrorMessage(`${err.name}: ${err.message}`); setErrorMessage(`${err.name}: ${err.message}`);
}); });
} }
eventBus.subscribe(RefreshEvent, refresh); eventBus.subscribe(RefreshEvent, fetchTasks);
function getDatasourceByUid(uid?: string): DataSourceSettings | undefined { function getDatasourceByUid(uid?: string): DataSourceSettings | undefined {
if (_.isNil(uid)) { if (_.isNil(uid)) {
@ -204,7 +199,7 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) {
}, },
}); });
refresh(); fetchTasks();
onCloseModal(); onCloseModal();
unselectAllQueries(); unselectAllQueries();
@ -431,8 +426,8 @@ export function Panel({ width, height, timeRange, eventBus, timeZone }: Props) {
); );
const permissionErrorDiv = ( const permissionErrorDiv = (
<div> <div>
<p>Permission Error.</p> <p> Permission Error. </p>
<div> DataExporter panel availabel only for Admins </div> <div> DataExporter panel available only for Admins. </div>
</div> </div>
); );
const mainDiv = ( const mainDiv = (

Loading…
Cancel
Save