Comments (9)
Just a heads up that you can shorten yours a bit using arrow functions like so:
return $this->result($top)
->link(fn($value) => $links[$value]);
from nova-linkable-metrics.
This is in the just released version 4.0.0. It's probably going to be reworked slightly, but borrowed @vesper8's approach for now.
from nova-linkable-metrics.
Thanks. I got it working now. In my case, I'm building up the content for my partition metrics manually, I mean, rather than mapping them to a resource directly, so the most convenient way is still to do it like I am doing it above.
But since your new link
method requires a closure, I was able to get it working this way:
return $this->result($top)
->link(function ($value) use ($links) {
return $links[$value];
});
from nova-linkable-metrics.
Currently, it's just one link for the whole card. However, we're open to a PR to allow your use case.
from nova-linkable-metrics.
Yeah that's exactly what I came for here too!! Thought I had struck gold initially!
from nova-linkable-metrics.
For anyone interested, I've wanted to have clickable items in a partition metric for a long time and I just spent a few hours forking this package and adding this functionality. The way I did it is a bit hacky, but in the end it's super easy.
If you use my latest fork you can now do something like this:
$result = $this->result($top);
$result->partitionLabelLinkMap($partitionLabelLinkMap);
return $result;
Where $partitionLabelLinkMap
is an array with your labels as keys and your link as the value.
So in my case
foreach ($users as $user) {
$top[$user->name] = $user->total;
$partitionLabelLinkMap[$user->name] = sprintf('/nova/resources/users/%d', $user->id);
}
And voila, works like a charm.
To be clear I didn't check if the trend and value metrics still work. Had to do a couple of things to get this package to build on the latest version of node / nova / laravel-mix. I might have broken the trend and value metrics.. but probably not.
from nova-linkable-metrics.
Hey @anderly,
I'm trying out your new release now and can't get it to work.
When I provide my links to ->links($links);
then for some reason I can't explain the return becomes empty.. there are no errors generated but I can see that the api request returns empty.
Here's my basic partition code
$games = $query
->whereNotNull($groupBy)
->groupBy($groupBy)
->selectRaw(sprintf('count(*) as total, %s as lookup', $groupBy))
->orderBy('total', 'desc')
->get();
$top = [];
foreach ($games as $game) {
$lookup = $lookupModel::find($game->lookup);
$name = sprintf('%s - %s', $lookup->eco, $lookup->opening);
$top[$name] = $game->total;
}
return $this->result($top);
Here's the same code but I also create $links
$games = $query
->whereNotNull($groupBy)
->groupBy($groupBy)
->selectRaw(sprintf('count(*) as total, %s as lookup', $groupBy))
->orderBy('total', 'desc')
->get();
$top = [];
foreach ($games as $game) {
$lookup = $lookupModel::find($game->lookup);
$name = sprintf('%s - %s', $lookup->eco, $lookup->opening);
$top[$name] = $game->total;
$links[$name] = $lookup->novaLink();
}
return $this->result($top)->links($links);
The api then returns {"value":null}
As a test if I return this return $this->result($top)->links([]);
Then I also get {"value":null}
Confused because inside BasePartitionMetric.vue
I see
:href="`${item.label in partitionLinks ? partitionLinks[item.label] : '#'}`"
If it can't find the label inside the partitionLinks array then it should just fallback to #
so I don't understand why providing links, whether they be malformed or not, results in {"value":null}
Anyway I'm sure I'm just doing something wrong.
Any chance you could post a small snippet demonstrating how to correctly provide links to partition metrics please?
Many thanks!
from nova-linkable-metrics.
Hi all, the readme has been updated with usage documentation on how to customize partition links. In short, it behaves very similar to customizing partition labels.
You may still want the partition metric card title to have a simple link and that is still supported, but now you may also provide a Closure callback to the new link
method to customize the partition metric links.
from nova-linkable-metrics.
Great to hear. Decided to follow the approach Nova takes with customizing labels by using the Closure because you have full control by building it up as you go with a route and params, etc. or by using your own map array like in your example.
Let me know how it goes and if any issues come up.
Thanks!
from nova-linkable-metrics.
Related Issues (20)
- Range select box is not populating HOT 2
- LinkableTrend trait makes graph dissapear HOT 4
- Adding LinkableValue trait disrupts time formatting HOT 4
- Is this still maintained? HOT 3
- Support for Nova 3? HOT 3
- allowZeroResult() doesn't work with LinkableValue trait. HOT 1
- Document 'import' example results in fatal error HOT 1
- Call to undefined method App\Nova\Metrics\ProfilesToApprove::route()
- How do I link to a specific resource? HOT 2
- ReferenceError: Minimum is not defined
- Compatibility
- Metrics no longer appear when using this package, no error messages. HOT 1
- How can we update the link with value of selected option it's filter when update the particular filter of the card? HOT 2
- Package doesn't load at all with the lastest version of Nova HOT 1
- Metric card is not respecting calls to allowZeroResult() HOT 1
- Nova 4 support? HOT 2
- Link to a specific tab HOT 3
- Metrics card disappears after a split second
- Value metrics will broken when suffix is used
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nova-linkable-metrics.