Code Monkey home page Code Monkey logo

Comments (9)

anderly avatar anderly commented on July 28, 2024 2

@vesper8,

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.

anderly avatar anderly commented on July 28, 2024 1

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.

vesper8 avatar vesper8 commented on July 28, 2024 1

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.

anderly avatar anderly commented on July 28, 2024

@goldmerc,

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.

jonnywilliamson avatar jonnywilliamson commented on July 28, 2024

Yeah that's exactly what I came for here too!! Thought I had struck gold initially!

from nova-linkable-metrics.

vesper8 avatar vesper8 commented on July 28, 2024

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.

vesper8 avatar vesper8 commented on July 28, 2024

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.

anderly avatar anderly commented on July 28, 2024

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.

anderly avatar anderly commented on July 28, 2024

@vesper8,

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.