@@ -18,6 +18,7 @@ import { FiltersModel } from '../filters';
1818import { QueriesModel } from '../queries' ;
1919import { SQLSnippetsModel } from '../sql-snippets' ;
2020
21+ import { TAdditionalQueryInfo } from '~/api-caller/request' ;
2122import {
2223 formatSQLSnippet ,
2324 getInitialFiltersConfig ,
@@ -29,10 +30,10 @@ import {
2930 TPayloadForSQL ,
3031 TPayloadForViz ,
3132} from '~/model' ;
32- import { PanelModelInstance , PanelsModel } from '../panels' ;
33- import { getInitialDashboardViewsModel , ViewsModel } from '../views' ;
3433import { payloadToDashboardState } from '~/utils/dashboard-state' ;
35- import { TAdditionalQueryInfo } from '~/api-caller/request' ;
34+ import { UsageRegs } from '~/utils/usage' ;
35+ import { PanelsModel } from '../panels' ;
36+ import { getInitialDashboardViewsModel , ViewsModel } from '../views' ;
3637
3738const _ContentModel = types
3839 . model ( {
@@ -233,12 +234,11 @@ const _ContentModel = types
233234 } ,
234235 get sqlSnippetsUsage ( ) {
235236 const usages : SQLSnippetUsageType [ ] = [ ] ;
236- const reg = / (?< = s q l _ s n i p p e t s \. ) ( [ ^ } . ] + ) / gm;
237237 self . queries . current . forEach ( ( q ) => {
238238 if ( ! q . typedAsSQL ) {
239239 return ;
240240 }
241- const keys = _ . uniq ( q . sql . match ( reg ) ) ;
241+ const keys = _ . uniq ( q . sql . match ( UsageRegs . sqlSnippet ) ) ;
242242 keys . forEach ( ( k ) => {
243243 usages . push ( {
244244 queryID : q . id ,
@@ -285,6 +285,42 @@ const _ContentModel = types
285285 self . panels . append ( getNewPanel ( id ) ) ;
286286 self . views . findByID ( viewID ) ?. appendPanelID ( id ) ;
287287 } ,
288+ applyJSONSchema ( partialSchema : AnyObject ) {
289+ const { panels, filters, definition = { } } = partialSchema ;
290+ const { queries, sqlSnippets, mock_context } = definition ;
291+
292+ // PANELS
293+ if ( Array . isArray ( panels ) ) {
294+ const newPanels = panels . map ( ( p ) => ( {
295+ ...p ,
296+ id : new Date ( ) . getTime ( ) . toString ( ) ,
297+ } ) ) ;
298+ self . panels . appendMultiple ( newPanels ) ;
299+
300+ const panelIDs = newPanels . map ( ( p ) => p . id ) ;
301+ self . views . VIE ?. appendPanelIDs ( panelIDs ) ;
302+ }
303+
304+ // FILTERS
305+ if ( Array . isArray ( filters ) ) {
306+ self . filters . appendMultiple ( filters ) ;
307+ }
308+
309+ // QUERIES
310+ if ( Array . isArray ( queries ) ) {
311+ self . queries . appendMultiple ( queries ) ;
312+ }
313+
314+ // SQL SNIPPETS
315+ if ( Array . isArray ( sqlSnippets ) ) {
316+ self . sqlSnippets . appendMultiple ( sqlSnippets ) ;
317+ }
318+
319+ // MOCK_CONTEXT
320+ if ( mock_context && Object . keys ( mock_context ) . length > 0 ) {
321+ self . mock_context . defaults ( mock_context ) ;
322+ }
323+ } ,
288324 } ) )
289325 . actions ( ( self ) => {
290326 function setupAutoSave ( ) {
0 commit comments