From 6e31d9234fec384b5f50735f0d856afae679010c Mon Sep 17 00:00:00 2001 From: ruanhan1988 <2856197796@qq.com> Date: Wed, 28 Oct 2020 14:09:23 +0800 Subject: [PATCH] fix(drill) #1971 --- .../DataDrill/abstract/widgetOperating.ts | 7 +- webapp/app/containers/Dashboard/sagas.ts | 79 +++++++++++-------- webapp/share/containers/Dashboard/sagas.ts | 14 +++- 3 files changed, 60 insertions(+), 40 deletions(-) diff --git a/webapp/app/components/DataDrill/abstract/widgetOperating.ts b/webapp/app/components/DataDrill/abstract/widgetOperating.ts index 95cfade15..55294a8ef 100644 --- a/webapp/app/components/DataDrill/abstract/widgetOperating.ts +++ b/webapp/app/components/DataDrill/abstract/widgetOperating.ts @@ -74,7 +74,7 @@ export default class OperatingWidget extends OperateObjectAbstract { } public initGroups() { - const widget = this.getWidgetById(this.currentWidgetId) + let widget = this.getWidgetById(this.currentWidgetId) if (!widget.initGroups) { const { rows, cols, color, label } = widget const setDefaultEmptyArray = setDefaultReplaceNull((f) => f, []) @@ -94,7 +94,10 @@ export default class OperatingWidget extends OperateObjectAbstract { setDefaultEmptyArray )(label) ] - widget.initGroups = groups + widget = { + ...widget, + initGroups: groups + } return groups } return widget.initGroups diff --git a/webapp/app/containers/Dashboard/sagas.ts b/webapp/app/containers/Dashboard/sagas.ts index be18bf006..d175d12ff 100644 --- a/webapp/app/containers/Dashboard/sagas.ts +++ b/webapp/app/containers/Dashboard/sagas.ts @@ -103,17 +103,14 @@ export function* getDashboardDetail(action: DashboardActionType) { operationWidgetProps.widgetIntoPool(widgets) - const formedViews: IFormedViews = views.reduce( - (obj, view) => { - obj[view.id] = { - ...view, - model: JSON.parse(view.model || '{}'), - variable: JSON.parse(view.variable || '[]') - } - return obj - }, - {} - ) + const formedViews: IFormedViews = views.reduce((obj, view) => { + obj[view.id] = { + ...view, + model: JSON.parse(view.model || '{}'), + variable: JSON.parse(view.variable || '[]') + } + return obj + }, {}) yield put(dashboardDetailLoaded(dashboard, items, widgets, formedViews)) } catch (err) { @@ -484,19 +481,26 @@ export function* getDashboardShareLink(action: DashboardActionType) { loadDashboardShareLinkFail } = DashboardActions - const {id, mode, permission, expired, roles, viewers} = action.payload.params + const { + id, + mode, + permission, + expired, + roles, + viewers + } = action.payload.params let requestData = null - switch(mode) { + switch (mode) { case 'AUTH': - requestData = { mode, expired, permission, roles, viewers } - break - case 'PASSWORD': - case 'NORMAL': - requestData = { mode, expired } - break - default: - break + requestData = { mode, expired, permission, roles, viewers } + break + case 'PASSWORD': + case 'NORMAL': + requestData = { mode, expired } + break + default: + break } try { @@ -506,7 +510,7 @@ export function* getDashboardShareLink(action: DashboardActionType) { data: requestData }) - const { token, password} = result.payload + const { token, password } = result.payload switch (mode) { case 'AUTH': yield put(dashboardAuthorizedShareLinkLoaded(token)) @@ -520,14 +524,13 @@ export function* getDashboardShareLink(action: DashboardActionType) { default: break } - } catch (err) { yield put(loadDashboardShareLinkFail()) errorHandler(err) } } -export function* getWidgetShareLink (action: DashboardActionType) { +export function* getWidgetShareLink(action: DashboardActionType) { if (action.type !== ActionTypes.LOAD_WIDGET_SHARE_LINK) { return } @@ -537,19 +540,27 @@ export function* getWidgetShareLink (action: DashboardActionType) { widgetShareLinkLoaded, loadWidgetShareLinkFail } = DashboardActions - const {id, itemId, mode, expired, permission, roles, viewers} = action.payload.params + const { + id, + itemId, + mode, + expired, + permission, + roles, + viewers + } = action.payload.params let requestData = null - switch(mode) { + switch (mode) { case 'AUTH': - requestData = { mode, expired, permission, roles, viewers } - break - case 'PASSWORD': - case 'NORMAL': - requestData = { mode, expired } - break - default: - break + requestData = { mode, expired, permission, roles, viewers } + break + case 'PASSWORD': + case 'NORMAL': + requestData = { mode, expired } + break + default: + break } try { diff --git a/webapp/share/containers/Dashboard/sagas.ts b/webapp/share/containers/Dashboard/sagas.ts index e975b0234..56e111633 100644 --- a/webapp/share/containers/Dashboard/sagas.ts +++ b/webapp/share/containers/Dashboard/sagas.ts @@ -27,13 +27,16 @@ import { takeLatest, takeEvery } from 'redux-saga/effects' + +import { IWidgetFormed } from 'app/containers/Widget/types' import { ActionTypes } from './constants' import { DashboardActions, DashboardActionType } from './actions' import { makeSelectDashboard, makeSelectItemRelatedWidget, makeSelectItemInfo, - makeSelectFormedViews + makeSelectFormedViews, + makeSelectWidgets } from './selectors' import { makeSelectShareType } from 'share/containers/App/selectors' import { @@ -64,7 +67,6 @@ import { IDashboard, IQueryConditions } from 'app/containers/Dashboard/types' -import { IWidgetFormed } from 'app/containers/Widget/types' import { IShareFormedViews } from 'app/containers/View/types' import { IGlobalControlConditions, @@ -82,7 +84,7 @@ import api from 'utils/api' import { message } from 'antd' import { DownloadTypes } from 'app/containers/App/constants' import { localStorageCRUD, getPasswordUrl } from '../../util' - +import { operationWidgetProps } from 'app/components/DataDrill/abstract/widgetOperating' export function* getDashboard(action: DashboardActionType) { if (action.type !== ActionTypes.LOAD_SHARE_DASHBOARD) { return @@ -110,6 +112,7 @@ export function* getDashboard(action: DashboardActionType) { ...rest, config: dashboardConfigMigrationRecorder(parsedConfig) } + const formedWidgets = widgets.map((widget) => { const { config, ...rest } = widget const parsedConfig: IWidgetConfig = JSON.parse(config) @@ -132,6 +135,8 @@ export function* getDashboard(action: DashboardActionType) { {} ) yield put(dashboardGetted(dashboard, relations, formedWidgets, formedViews)) + const getWidgets: IWidgetFormed = yield select(makeSelectWidgets()) + operationWidgetProps.widgetIntoPool(getWidgets) } catch (err) { yield put(loadDashboardFail()) errorHandler(err) @@ -171,7 +176,8 @@ export function* getWidget(action: DashboardActionType) { {} ) yield put(widgetGetted(formedWidget, formedViews)) - + const getWidgets: IWidgetFormed = yield select(makeSelectWidgets()) + operationWidgetProps.widgetIntoPool(getWidgets) if (resolve) { resolve(formedWidget, formedViews) }