1+ import _ , { pick } from 'lodash' ;
12import type { DeepNonNullable } from 'utility-types' ;
23
4+ import Dash from '../../../../server/components/sdk/dash' ;
5+ import { DASH_ENTRY_RELEVANT_FIELDS } from '../../../../server/constants' ;
36import type { ChartsStats } from '../../../types/charts' ;
7+ import { EntryScope } from '../../../types/common' ;
48import { createAction , createTypedAction } from '../../gateway-utils' ;
59import { getTypedApi } from '../../simple-schema' ;
610import { getEntryVisualizationType } from '../helpers' ;
@@ -11,19 +15,63 @@ import {
1115 prepareDatasetData ,
1216 prepareWidgetDatasetData ,
1317} from '../helpers/dash' ;
14- import { deleteDashArgsSchema , deleteDashResultSchema } from '../schemas/dash' ;
18+ import {
19+ createDashArgsSchema ,
20+ createDashResultSchema ,
21+ deleteDashArgsSchema ,
22+ deleteDashResultSchema ,
23+ getDashArgsSchema ,
24+ getDashResultSchema ,
25+ updateDashArgsSchema ,
26+ updateDashResultSchema ,
27+ } from '../schemas/dash' ;
1528import type {
1629 CollectChartkitStatsArgs ,
1730 CollectChartkitStatsResponse ,
1831 CollectDashStatsArgs ,
1932 CollectDashStatsResponse ,
33+ CreateDashResponse ,
2034 GetEntriesDatasetsFieldsArgs ,
2135 GetEntriesDatasetsFieldsResponse ,
2236 GetWidgetsDatasetsFieldsArgs ,
2337 GetWidgetsDatasetsFieldsResponse ,
38+ UpdateDashResponse ,
2439} from '../types' ;
2540
2641export const dashActions = {
42+ // WIP
43+ __getDashboard__ : createTypedAction (
44+ {
45+ paramsSchema : getDashArgsSchema ,
46+ resultSchema : getDashResultSchema ,
47+ } ,
48+ async ( _ , args , { headers, ctx} ) => {
49+ const { dashboardId, includePermissions, includeLinks, branch, revId} = args ;
50+
51+ if ( ! dashboardId || dashboardId === 'null' ) {
52+ throw new Error ( `Not found ${ dashboardId } id` ) ;
53+ }
54+
55+ const result = await Dash . read (
56+ dashboardId ,
57+ {
58+ includePermissions : includePermissions ? includePermissions ?. toString ( ) : '0' ,
59+ includeLinks : includeLinks ? includeLinks ?. toString ( ) : '0' ,
60+ ...( branch ? { branch} : { branch : 'published' } ) ,
61+ ...( revId ? { revId} : { } ) ,
62+ } ,
63+ headers ,
64+ ctx ,
65+ { forceMigrate : true } ,
66+ ) ;
67+
68+ if ( result . scope !== EntryScope . Dash ) {
69+ throw new Error ( 'No entry found' ) ;
70+ }
71+
72+ return pick ( result , DASH_ENTRY_RELEVANT_FIELDS ) as any ;
73+ } ,
74+ ) ,
2775 // WIP
2876 __deleteDashboard__ : createTypedAction (
2977 {
@@ -41,6 +89,39 @@ export const dashActions = {
4189 return { } ;
4290 } ,
4391 ) ,
92+ // WIP
93+ __updateDashboard__ : createTypedAction (
94+ {
95+ paramsSchema : updateDashArgsSchema ,
96+ resultSchema : updateDashResultSchema ,
97+ } ,
98+ async ( _ , args , { headers, ctx} ) => {
99+ const { entryId} = args ;
100+
101+ const I18n = ctx . get ( 'i18n' ) ;
102+
103+ return ( await Dash . update ( entryId as any , args as any , headers , ctx , I18n , {
104+ forceMigrate : true ,
105+ } ) ) as unknown as UpdateDashResponse ;
106+ } ,
107+ ) ,
108+ // WIP
109+ __createDashboard__ : createTypedAction (
110+ {
111+ paramsSchema : createDashArgsSchema ,
112+ resultSchema : createDashResultSchema ,
113+ } ,
114+ async ( _ , args , { headers, ctx} ) => {
115+ const I18n = ctx . get ( 'i18n' ) ;
116+
117+ return ( await Dash . create (
118+ args as any ,
119+ headers ,
120+ ctx ,
121+ I18n ,
122+ ) ) as unknown as CreateDashResponse ;
123+ } ,
124+ ) ,
44125
45126 collectDashStats : createAction < CollectDashStatsResponse , CollectDashStatsArgs > (
46127 async ( _ , args , { ctx} ) => {
0 commit comments