-
Notifications
You must be signed in to change notification settings - Fork 1
feat(api chart): allow customizing api chart with query or body parameters #278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,11 +6,12 @@ class ChartContext < ForestAdminDatasourceCustomizer::Context::CollectionCustomi | |
| include ForestAdminDatasourceToolkit::Components::Query | ||
| include ForestAdminDatasourceToolkit::Components::Query::ConditionTree | ||
|
|
||
| attr_reader :composite_record_id | ||
| attr_reader :composite_record_id, :parameters | ||
|
|
||
| def initialize(collection, caller, record_id) | ||
| def initialize(collection, caller, record_id, parameters = {}) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| super(collection, caller) | ||
| @composite_record_id = record_id | ||
| @parameters = (parameters || {}).freeze | ||
| end | ||
|
|
||
| def _composite_record_id=(value) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| module ForestAdminDatasourceCustomizer | ||
| module Decorators | ||
| module Chart | ||
| class DatasourceChartContext < ForestAdminDatasourceCustomizer::Context::AgentCustomizationContext | ||
| attr_reader :parameters | ||
|
|
||
| def initialize(datasource, caller, parameters = {}) | ||
| super(datasource, caller) | ||
| @parameters = (parameters || {}).freeze | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -149,8 +149,8 @@ def get_form(caller, name, data = nil, filter = nil, metas = nil) | |
| end | ||
| end | ||
|
|
||
| def render_chart(caller, name, record_id) | ||
| params = build_params(chart: name, record_id: record_id) | ||
| def render_chart(caller, name, record_id, parameters = {}) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| params = build_params(chart: name, record_id: record_id, parameters: parameters) | ||
| url = "#{@rpc_collection_uri}/chart" | ||
|
|
||
| ForestAdminAgent::Facades::Container.logger.log( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,7 +76,7 @@ def add_chart(name) | |
| schema[:charts] << name | ||
| end | ||
|
|
||
| def render_chart(_caller, name, _record_id) | ||
| def render_chart(_caller, name, _record_id, _parameters = {}) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| raise Exceptions::ForestException, "Chart #{name} is not implemented." | ||
| end | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,8 +71,8 @@ def aggregate(caller, filter, aggregation, limit = nil) | |
| @child_collection.aggregate(caller, refined_filter, aggregation, limit) | ||
| end | ||
|
|
||
| def render_chart(caller, name, record_id) | ||
| @child_collection.render_chart(caller, name, record_id) | ||
| def render_chart(caller, name, record_id, parameters = {}) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| @child_collection.render_chart(caller, name, record_id, parameters) | ||
| end | ||
|
|
||
| protected | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function with many parameters (count = 4): render_chart [qlty:function-parameters]