Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
256835b0
Unverified
Commit
256835b0
authored
10 months ago
by
Alexander Polyankin
Committed by
GitHub
10 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Load card metadata recursively (#41963)
parent
5df74763
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
frontend/src/metabase/questions/actions.ts
+49
-15
49 additions, 15 deletions
frontend/src/metabase/questions/actions.ts
with
49 additions
and
15 deletions
frontend/src/metabase/questions/actions.ts
+
49
−
15
View file @
256835b0
...
...
@@ -11,22 +11,56 @@ export interface LoadMetadataOptions {
}
export
const
loadMetadataForCard
=
(
card
:
Card
,
options
?:
LoadMetadataOptions
)
=>
(
card
:
Card
,
options
?:
LoadMetadataOptions
)
=>
async
(
dispatch
:
Dispatch
)
=>
{
await
dispatch
(
loadDependentMetadata
(
card
,
[],
options
));
};
const
loadDependentMetadata
=
(
card
:
Card
,
dependencies
:
Lib
.
DependentItem
[],
options
?:
LoadMetadataOptions
,
)
=>
async
(
dispatch
:
Dispatch
,
getState
:
GetState
)
=>
{
const
question
=
new
Question
(
card
,
getMetadata
(
getState
()));
const
loadAdhocMetadata
=
question
.
isSaved
()
&&
question
.
type
()
!==
"
question
"
;
const
dependencies
=
[...
Lib
.
dependentMetadata
(
question
.
query
())];
if
(
loadAdhocMetadata
)
{
const
tableId
=
getQuestionVirtualTableId
(
question
.
id
());
dependencies
.
push
({
id
:
tableId
,
type
:
"
table
"
});
}
await
dispatch
(
loadMetadataForDependentItems
(
dependencies
,
options
));
if
(
loadAdhocMetadata
)
{
const
questionWithMetadata
=
new
Question
(
card
,
getMetadata
(
getState
()));
const
adhocQuestion
=
questionWithMetadata
.
composeQuestionAdhoc
();
const
adhocDependencies
=
Lib
.
dependentMetadata
(
adhocQuestion
.
query
());
await
dispatch
(
loadMetadataForDependentItems
(
adhocDependencies
,
options
));
const
withAdhocMetadata
=
shouldLoadAdhocMetadata
(
question
);
const
nextDependencies
=
getDependencies
(
question
,
withAdhocMetadata
);
const
dependenciesDiff
=
getDependenciesDiff
(
dependencies
,
nextDependencies
,
);
if
(
dependenciesDiff
.
length
>
0
)
{
await
dispatch
(
loadMetadataForDependentItems
(
dependenciesDiff
,
options
));
const
mergedDependencies
=
[...
dependencies
,
...
dependenciesDiff
];
await
dispatch
(
loadDependentMetadata
(
card
,
mergedDependencies
,
options
));
}
else
if
(
withAdhocMetadata
)
{
const
adhocCard
=
question
.
composeQuestionAdhoc
().
card
();
await
dispatch
(
loadDependentMetadata
(
adhocCard
,
dependencies
,
options
));
}
};
function
shouldLoadAdhocMetadata
(
question
:
Question
)
{
return
question
.
isSaved
()
&&
question
.
type
()
!==
"
question
"
;
}
function
getDependencies
(
question
:
Question
,
withAdhocMetadata
:
boolean
)
{
const
dependencies
=
[...
Lib
.
dependentMetadata
(
question
.
query
())];
if
(
withAdhocMetadata
)
{
const
tableId
=
getQuestionVirtualTableId
(
question
.
id
());
dependencies
.
push
({
id
:
tableId
,
type
:
"
table
"
});
}
return
dependencies
;
}
function
getDependencyKey
(
dependency
:
Lib
.
DependentItem
)
{
return
`
${
dependency
.
type
}
/
${
dependency
.
id
}
`
;
}
function
getDependenciesDiff
(
prevDependencies
:
Lib
.
DependentItem
[],
nextDependencies
:
Lib
.
DependentItem
[],
)
{
const
prevKeys
=
new
Set
(
prevDependencies
.
map
(
getDependencyKey
));
return
nextDependencies
.
filter
(
dep
=>
!
prevKeys
.
has
(
getDependencyKey
(
dep
)));
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment