Skip to content
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

feature: Dashboard filters #9747

Merged
merged 5 commits into from
Nov 20, 2023
Merged

feature: Dashboard filters #9747

merged 5 commits into from
Nov 20, 2023

Conversation

danharrin
Copy link
Member

Closes #7113.

@danharrin danharrin added the enhancement New feature or request label Nov 19, 2023
@danharrin danharrin added this to the v3.1 milestone Nov 19, 2023
@danharrin danharrin self-assigned this Nov 19, 2023
@danharrin danharrin linked an issue Nov 19, 2023 that may be closed by this pull request
@danharrin danharrin assigned zepfietje and unassigned danharrin Nov 19, 2023
@danharrin danharrin merged commit b4f30bf into 3.1 Nov 20, 2023
9 checks passed
@danharrin danharrin deleted the feat/dashboard-filters branch November 20, 2023 14:51
@patriktoth67
Copy link

Hi guys. This feature works perfectly on BaseWidget-s, but sadly doesn't work properly with ChartWidget-s.
If you try to use it on a chart, you can see the values changing in the livewire component, but not in chart.js sadly. It can either update if the pollingInterval is not null, or if you refresh the page. If pollingInterval is 5s, it only updates with the correct filtered data once the 5s is up.

@danharrin
Copy link
Member Author

Please open an issue with a reproduction repository

@danielreales7
Copy link

danielreales7 commented Dec 2, 2023

@danharrin The same thing happens to me with ChartWidget.

If I use protected static ?string $pollingInterval = 'keep-alive'; It is always sending requests to the server, which is wrong.
Widgets should update based on filters.

I can show my code:

`class SalesChart extends ChartWidget
{
use InteractsWithPageFilters;

protected static ?string $heading = 'Total ventas por mes';
protected static ?string $maxHeight = '275px';
protected static ?string $pollingInterval = 'keep-alive';

protected function getData(): array
{
    $startDate = $this->filters['startDate'] ?? null;
    $endDate = $this->filters['endDate'] ?? null;
    $payment_method = $this->filters['payment_method'] ?? null;
    $store_id = Filament::getTenant()->id;

    $data = Trend::query(
        DailySale::when($payment_method, fn(Builder $query) => $query->where('payment_method', $payment_method))
            ->where('store_id', $store_id)
        )
        ->dateColumn('date')
        ->dateAlias('saleDate')
        ->between(
            start: Carbon::parse($startDate),
            end: Carbon::parse($endDate),
        )
        ->perMonth()
        ->sum('total');

    $transformedResults = $data->map(fn ($value) => new TrendValue(
        date: $value->date,
        aggregate: DailySale::castAttribute('total', $value->aggregate)
    ));

    return [
        'datasets' => [
            [
                'label' => 'Total €',
                'data' => $transformedResults->map(fn (TrendValue $value) => $value->aggregate),
            ],
        ],
        'labels' => $data->map(fn (TrendValue $value) => $value->date),
    ];
}

protected function getType(): string
{
    return 'bar';
}

}`

If I set it to null, it doesn't update the char

@danharrin
Copy link
Member Author

Please open an issue with a reproduction repository

@danielreales7
Copy link

Please open an issue with a reproduction repository

Done! #10026

@filamentphp filamentphp locked and limited conversation to collaborators Dec 3, 2023
@danharrin
Copy link
Member Author

Fixed by #10041.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Global dashboard filters
4 participants