Убрана ибыточная информация из данных для виджетов

This commit is contained in:
Pavel Gnedov 2023-11-04 18:17:35 +07:00
parent a756677c89
commit f02d13e3dc
6 changed files with 23 additions and 23 deletions

View file

@ -1,5 +1,5 @@
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;
@ -90,7 +90,7 @@ export const Dashboard = types
setWidgetsData: (data: any) => {
for (let i = 0; i < data.length; i++) {
const widgetData = data[i]?.data;
const widgetId = data[i]?.widget?.id;
const widgetId = data[i]?.widgetId;
if (!widgetId || !widgetData) continue;
const widgets = self.data?.widgets;
@ -147,8 +147,8 @@ export async function WidgetLoadData(widget: IWidget): Promise<void> {
const resp = await fetch(url);
if (resp && resp.ok) {
const data = await resp.json();
if (data?.data) {
widget.setData(data?.data);
if (data) {
widget.setData(data);
}
}
}

View file

@ -12,7 +12,7 @@ export type Props = {
export const IssuesList = observer((props: Props): JSX.Element => {
const store = IssuesListBoardsStoreNs.PageStore.create({ loaded: false });
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} />;
});

View file

@ -11,7 +11,7 @@ export type Props = {
export const Kanban = observer((props: Props): JSX.Element => {
const store = KanbanBoardsStoreNs.PageStore.create({ loaded: false });
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} />;
});

View file

@ -9,9 +9,18 @@ export type Props = {
};
export const IssuesListBoard = observer((props: Props): JSX.Element => {
const list: JSX.Element[] = props.store.data.map((issue) => {
return <IssuesListCardNs.IssuesListCard store={issue} key={issue.id} />;
});
const list: JSX.Element[] = [];
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;
if (props.store.metainfo.url) {
title = <a href={props.store.metainfo.url}>{props.store.metainfo.title}</a>;

View file

@ -5,7 +5,7 @@ import { AppError, Result, createAppError, fail } from '../utils/result';
import { WidgetsCollectionService } from './widgets-collection.service';
export type WidgetWithData = {
widget: DashboardModel.Widget;
widgetId: string;
data: any;
};
@ -34,17 +34,14 @@ export class DashboardsDataService {
if (loadRes.result) {
isSuccess = true;
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');
return results;
}
async loadDataForWidget(
id: string,
widgetId: string,
): Promise<WidgetWithData> {
async loadDataForWidget(id: string, widgetId: string): Promise<any> {
const cfg = await this.dashboardsService.load(id);
const widget = cfg.widgets.find((widget) => {
return widget.id == widgetId;
@ -56,7 +53,7 @@ export class DashboardsDataService {
widget.dataLoaderParams,
cfg,
);
if (loadRes.result) return { widget: widget, data: loadRes.result };
if (loadRes.result) return loadRes.result;
throw createAppError('CANNOT_LOAD_DATA');
}

View file

@ -16,13 +16,7 @@ export class InteractiveWidget
dashboardParams: any,
): Promise<Result<any, AppError>> {
const data = await this.dataLoader.load(dataLoaderParams, dashboardParams);
return data.error
? fail(data.error)
: success({
data: data.result,
widgetParams: widgetParams,
dashboardParams: dashboardParams,
});
return data.error ? fail(data.error) : success(data.result);
}
}