Skip to content

Commit

Permalink
Remove localstorage actions
Browse files Browse the repository at this point in the history
  • Loading branch information
luanfreitasdev committed Oct 1, 2024
1 parent 5aabadc commit be1d9ad
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 38 deletions.
2 changes: 1 addition & 1 deletion dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"/powergrid.js": "/powergrid.js?id=294e0648790446137adc832e2e9a972b",
"/powergrid.js": "/powergrid.js?id=c934be2b60db85114d2975c8c6e4565e",
"/bootstrap5.css": "/bootstrap5.css?id=a27af22343149104b2aa3283d8fd502b",
"/tailwind.css": "/tailwind.css?id=924477e2afcb2cb56aa392e266ee56ca"
}
2 changes: 1 addition & 1 deletion dist/powergrid.js

Large diffs are not rendered by default.

29 changes: 0 additions & 29 deletions resources/js/components/pg-render-actions.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,7 @@
export default (params) => ({
rowId: params?.rowId ?? null,
storageKey: null,
cookieKey: null,
parentId: params?.parentId ?? null,
init() {
this.setKeys();

window.addEventListener('beforeunload', () => {
localStorage.removeItem(this.storageKey);
document.cookie = this.cookieKey + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
});
},

setKeys() {
if (this.rowId) {
this.storageKey = `pg_session_${this.$wire.tableName}_row_${this.rowId}`;
this.cookieKey = `pg_cookie_${this.$wire.tableName}_row_${this.rowId}`;

return;
}

this.storageKey = `pg_session_${this.$wire.tableName}_header_actions`;
this.cookieKey = `pg_cookie_${this.$wire.tableName}_header_actions`;
},

toHtml() {
const value = localStorage.getItem(this.storageKey)

if (typeof value === 'string' && value.length > 0) {
return value;
}

let actions = null;
const wireId = this.parentId ?? this.$wire.id;

Expand Down
1 change: 0 additions & 1 deletion resources/js/components/pg-row-attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export default (params) => ({
}
})
}

},

getAttributes() {
Expand Down
10 changes: 4 additions & 6 deletions src/DataSource/Processors/DataSourceBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ public static function transform(

private static function processRows(BaseCollection $results, PowerGridComponent $component): BaseCollection
{
$fields = collect($component->fields()->fields);
$cookiePrefix = 'pg_cookie_' . $component->tableName . '_row_';
$fields = collect($component->fields()->fields);

if ($component->paginateRaw) {
$results = collect((array) data_get($results, 'hits'))->pluck('document');
Expand All @@ -128,14 +127,13 @@ private static function processRows(BaseCollection $results, PowerGridComponent
$renderActionRules = method_exists($component, 'actionRules');
$actionsHtml = &static::$actionsHtml;

return $results->map(function ($row, $index) use ($component, $fields, $loopInstance, $renderActions, $renderActionRules, $cookiePrefix, &$actionsHtml) {
return $results->map(function ($row, $index) use ($component, $fields, $loopInstance, $renderActions, $renderActionRules, &$actionsHtml) {
$row = (object) $row;
$data = $fields->map(fn ($field) => $field($row, $index));

$rowId = data_get($row, $component->realPrimaryKey);
$hasCookieActionsForRow = isset($_COOKIE[$cookiePrefix . $rowId]);
$rowId = data_get($row, $component->realPrimaryKey);

if ($renderActions && !$hasCookieActionsForRow) {
if ($renderActions) {
try {
$actions = collect($component->actions($row)) // @phpstan-ignore-line
->map(function ($action) use ($row, $component, $renderActionRules) {
Expand Down

0 comments on commit be1d9ad

Please sign in to comment.