Убрана ибыточная информация из данных для виджетов
This commit is contained in:
parent
a756677c89
commit
f02d13e3dc
6 changed files with 23 additions and 23 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { IAnyModelType, Instance, types } from 'mobx-state-tree';
|
import { Instance, types } from 'mobx-state-tree';
|
||||||
|
|
||||||
type _WidgetParams = Record<string, any> | null;
|
type _WidgetParams = Record<string, any> | null;
|
||||||
|
|
||||||
|
|
@ -90,7 +90,7 @@ export const Dashboard = types
|
||||||
setWidgetsData: (data: any) => {
|
setWidgetsData: (data: any) => {
|
||||||
for (let i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
const widgetData = data[i]?.data;
|
const widgetData = data[i]?.data;
|
||||||
const widgetId = data[i]?.widget?.id;
|
const widgetId = data[i]?.widgetId;
|
||||||
if (!widgetId || !widgetData) continue;
|
if (!widgetId || !widgetData) continue;
|
||||||
|
|
||||||
const widgets = self.data?.widgets;
|
const widgets = self.data?.widgets;
|
||||||
|
|
@ -147,8 +147,8 @@ export async function WidgetLoadData(widget: IWidget): Promise<void> {
|
||||||
const resp = await fetch(url);
|
const resp = await fetch(url);
|
||||||
if (resp && resp.ok) {
|
if (resp && resp.ok) {
|
||||||
const data = await resp.json();
|
const data = await resp.json();
|
||||||
if (data?.data) {
|
if (data) {
|
||||||
widget.setData(data?.data);
|
widget.setData(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ export type Props = {
|
||||||
export const IssuesList = observer((props: Props): JSX.Element => {
|
export const IssuesList = observer((props: Props): JSX.Element => {
|
||||||
const store = IssuesListBoardsStoreNs.PageStore.create({ loaded: false });
|
const store = IssuesListBoardsStoreNs.PageStore.create({ loaded: false });
|
||||||
onSnapshot(props.store, (state) => {
|
onSnapshot(props.store, (state) => {
|
||||||
if (state?.data?.data) store.setData(state?.data?.data);
|
if (state?.data) store.setData(state?.data);
|
||||||
});
|
});
|
||||||
return <IssuesListBoardsNs.IssuesListBoards store={store} />;
|
return <IssuesListBoardsNs.IssuesListBoards store={store} />;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ export type Props = {
|
||||||
export const Kanban = observer((props: Props): JSX.Element => {
|
export const Kanban = observer((props: Props): JSX.Element => {
|
||||||
const store = KanbanBoardsStoreNs.PageStore.create({ loaded: false });
|
const store = KanbanBoardsStoreNs.PageStore.create({ loaded: false });
|
||||||
onSnapshot(props.store, (state) => {
|
onSnapshot(props.store, (state) => {
|
||||||
if (state?.data?.data) store.setData(state?.data?.data);
|
if (state?.data) store.setData(state?.data);
|
||||||
});
|
});
|
||||||
return <KanbanBoardsNs.KanbanBoards store={store} />;
|
return <KanbanBoardsNs.KanbanBoards store={store} />;
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,18 @@ export type Props = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const IssuesListBoard = observer((props: Props): JSX.Element => {
|
export const IssuesListBoard = observer((props: Props): JSX.Element => {
|
||||||
const list: JSX.Element[] = props.store.data.map((issue) => {
|
const list: JSX.Element[] = [];
|
||||||
return <IssuesListCardNs.IssuesListCard store={issue} key={issue.id} />;
|
const data: any = props.store.data;
|
||||||
});
|
for (let i = 0; i < data.length; i++) {
|
||||||
|
const column = data[i];
|
||||||
|
const issues: any[] = column.issues;
|
||||||
|
for (let j = 0; j < issues.length; j++) {
|
||||||
|
const issue = issues[j];
|
||||||
|
list.push(
|
||||||
|
<IssuesListCardNs.IssuesListCard store={issue} key={issue.id} />,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
let title: JSX.Element;
|
let title: JSX.Element;
|
||||||
if (props.store.metainfo.url) {
|
if (props.store.metainfo.url) {
|
||||||
title = <a href={props.store.metainfo.url}>{props.store.metainfo.title}</a>;
|
title = <a href={props.store.metainfo.url}>{props.store.metainfo.title}</a>;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { AppError, Result, createAppError, fail } from '../utils/result';
|
||||||
import { WidgetsCollectionService } from './widgets-collection.service';
|
import { WidgetsCollectionService } from './widgets-collection.service';
|
||||||
|
|
||||||
export type WidgetWithData = {
|
export type WidgetWithData = {
|
||||||
widget: DashboardModel.Widget;
|
widgetId: string;
|
||||||
data: any;
|
data: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -34,17 +34,14 @@ export class DashboardsDataService {
|
||||||
if (loadRes.result) {
|
if (loadRes.result) {
|
||||||
isSuccess = true;
|
isSuccess = true;
|
||||||
loadRes.result.widgetId = widget.id;
|
loadRes.result.widgetId = widget.id;
|
||||||
results.push({ data: loadRes.result, widget: widget });
|
results.push({ data: loadRes.result, widgetId: widget.id });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isSuccess) throw createAppError('CANNOT_LOAD_DATA');
|
if (!isSuccess) throw createAppError('CANNOT_LOAD_DATA');
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadDataForWidget(
|
async loadDataForWidget(id: string, widgetId: string): Promise<any> {
|
||||||
id: string,
|
|
||||||
widgetId: string,
|
|
||||||
): Promise<WidgetWithData> {
|
|
||||||
const cfg = await this.dashboardsService.load(id);
|
const cfg = await this.dashboardsService.load(id);
|
||||||
const widget = cfg.widgets.find((widget) => {
|
const widget = cfg.widgets.find((widget) => {
|
||||||
return widget.id == widgetId;
|
return widget.id == widgetId;
|
||||||
|
|
@ -56,7 +53,7 @@ export class DashboardsDataService {
|
||||||
widget.dataLoaderParams,
|
widget.dataLoaderParams,
|
||||||
cfg,
|
cfg,
|
||||||
);
|
);
|
||||||
if (loadRes.result) return { widget: widget, data: loadRes.result };
|
if (loadRes.result) return loadRes.result;
|
||||||
throw createAppError('CANNOT_LOAD_DATA');
|
throw createAppError('CANNOT_LOAD_DATA');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,7 @@ export class InteractiveWidget
|
||||||
dashboardParams: any,
|
dashboardParams: any,
|
||||||
): Promise<Result<any, AppError>> {
|
): Promise<Result<any, AppError>> {
|
||||||
const data = await this.dataLoader.load(dataLoaderParams, dashboardParams);
|
const data = await this.dataLoader.load(dataLoaderParams, dashboardParams);
|
||||||
return data.error
|
return data.error ? fail(data.error) : success(data.result);
|
||||||
? fail(data.error)
|
|
||||||
: success({
|
|
||||||
data: data.result,
|
|
||||||
widgetParams: widgetParams,
|
|
||||||
dashboardParams: dashboardParams,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue