Ma77Ball commented on code in PR #5215:
URL: https://github.com/apache/texera/pull/5215#discussion_r3327095304


##########
frontend/src/app/dashboard/component/user/dataset-card-item/dataset-card-item.component.html:
##########
@@ -0,0 +1,101 @@
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied.  See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+<nz-card
+  nzHoverable
+  class="dataset-card"
+  [nzCover]="coverTpl"
+  [routerLink]="entryLink">
+  <div class="dataset-card-body-link">
+    <span
+      class="card-title"
+      [title]="entry.name">
+      {{ entry.name }}
+    </span>
+
+    <div class="card-meta">
+      <div class="meta-line meta-line--owner">
+        <span
+          class="meta-owner"
+          [title]="entry.ownerName || entry.ownerEmail || 'Unknown'">
+          <texera-user-avatar
+            class="meta-avatar"
+            [googleAvatar]="entry.ownerGoogleAvatar"
+            userColor="#1E90FF"
+            [userName]="entry.ownerName || entry.ownerEmail || 'Unknown'"
+            [isOwner]="entry.ownerId === currentUid">
+          </texera-user-avatar>
+          <span class="meta-owner-name truncate-single-line">
+            {{ entry.ownerName || entry.ownerEmail || 'Unknown' }}
+          </span>
+        </span>
+        <span
+          class="meta-dot"
+          aria-hidden="true"
+          >ยท</span
+        >
+        <span class="meta-updated">Updated {{ 
formatRelativeTime(entry.lastModifiedTime) }}</span>

Review Comment:
   ```suggestion
           <span class="meta-updated">Created {{ 
formatRelativeTime(entry.lastModifiedTime) }}</span>
   ```
   Minor/UX: for datasets `DashboardEntry` sets `lastModifiedTime = 
value.dataset.creationTime`. I think this actually shows the **creation** time. 
Consider relabeling to "Created" or leaving a comment.



##########
frontend/src/app/dashboard/component/user/dataset-card-item/dataset-card-item.component.ts:
##########
@@ -0,0 +1,134 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, 
OnChanges, SimpleChanges } from "@angular/core";
+import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy";
+import { RouterLink } from "@angular/router";
+import { NzCardComponent } from "ng-zorro-antd/card";
+import { NzIconDirective } from "ng-zorro-antd/icon";
+import { DashboardEntry } from "../../../type/dashboard-entry";
+import { UserAvatarComponent } from "../user-avatar/user-avatar.component";
+import { DatasetService } from "../../../service/user/dataset/dataset.service";
+import { HubService } from "../../../../hub/service/hub.service";
+import { formatSize } from "../../../../common/util/size-formatter.util";
+import { formatCount, formatRelativeTime } from 
"../../../../common/util/format.util";
+import { isDefined } from "../../../../common/util/predicate";
+import { DASHBOARD_HUB_DATASET_RESULT_DETAIL, DASHBOARD_USER_DATASET } from 
"../../../../app-routing.constant";
+
+@UntilDestroy()
+@Component({
+  selector: "texera-dataset-card-item",
+  templateUrl: "./dataset-card-item.component.html",
+  styleUrls: ["./dataset-card-item.component.scss"],
+  changeDetection: ChangeDetectionStrategy.OnPush,
+  imports: [RouterLink, NzCardComponent, NzIconDirective, UserAvatarComponent],
+})
+export class DatasetCardItemComponent implements OnChanges {
+  @Input() currentUid: number | undefined;
+  @Input() entry!: DashboardEntry;
+
+  entryLink: string[] = [];
+  coverImageSrc: string = "";
+  readonly defaultCover = "assets/card_background.jpg";
+  likeCount = 0;
+  viewCount = 0;
+  isLiked = false;
+
+  constructor(
+    private datasetService: DatasetService,
+    private hubService: HubService,
+    private cdr: ChangeDetectorRef
+  ) {}
+
+  ngOnChanges(changes: SimpleChanges): void {
+    if (changes["entry"] || changes["currentUid"]) {
+      this.initializeEntry();
+    }
+    if (changes["entry"]) {
+      this.likeCount = this.entry.likeCount ?? 0;
+      this.viewCount = this.entry.viewCount ?? 0;
+      this.isLiked = this.entry.isLiked ?? false;
+    }
+  }
+
+  private initializeEntry(): void {
+    if (this.entry.type !== "dataset" || typeof this.entry.id !== "number") {

Review Comment:
   ```suggestion
       if (!this.entry || this.entry.type !== "dataset" || typeof this.entry.id 
!== "number") {
   ```
   The code in this block always expects an entry; it would be safer to bail 
out early if the entry isn't ready. 



##########
frontend/src/app/dashboard/component/user/dataset-card-item/dataset-card-item.component.ts:
##########
@@ -0,0 +1,134 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, 
OnChanges, SimpleChanges } from "@angular/core";
+import { UntilDestroy, untilDestroyed } from "@ngneat/until-destroy";
+import { RouterLink } from "@angular/router";
+import { NzCardComponent } from "ng-zorro-antd/card";
+import { NzIconDirective } from "ng-zorro-antd/icon";
+import { DashboardEntry } from "../../../type/dashboard-entry";
+import { UserAvatarComponent } from "../user-avatar/user-avatar.component";
+import { DatasetService } from "../../../service/user/dataset/dataset.service";
+import { HubService } from "../../../../hub/service/hub.service";
+import { formatSize } from "../../../../common/util/size-formatter.util";
+import { formatCount, formatRelativeTime } from 
"../../../../common/util/format.util";
+import { isDefined } from "../../../../common/util/predicate";
+import { DASHBOARD_HUB_DATASET_RESULT_DETAIL, DASHBOARD_USER_DATASET } from 
"../../../../app-routing.constant";
+
+@UntilDestroy()
+@Component({
+  selector: "texera-dataset-card-item",
+  templateUrl: "./dataset-card-item.component.html",
+  styleUrls: ["./dataset-card-item.component.scss"],
+  changeDetection: ChangeDetectionStrategy.OnPush,
+  imports: [RouterLink, NzCardComponent, NzIconDirective, UserAvatarComponent],
+})
+export class DatasetCardItemComponent implements OnChanges {
+  @Input() currentUid: number | undefined;
+  @Input() entry!: DashboardEntry;
+
+  entryLink: string[] = [];
+  coverImageSrc: string = "";
+  readonly defaultCover = "assets/card_background.jpg";
+  likeCount = 0;
+  viewCount = 0;
+  isLiked = false;
+
+  constructor(
+    private datasetService: DatasetService,
+    private hubService: HubService,
+    private cdr: ChangeDetectorRef
+  ) {}
+
+  ngOnChanges(changes: SimpleChanges): void {
+    if (changes["entry"] || changes["currentUid"]) {
+      this.initializeEntry();
+    }
+    if (changes["entry"]) {
+      this.likeCount = this.entry.likeCount ?? 0;
+      this.viewCount = this.entry.viewCount ?? 0;
+      this.isLiked = this.entry.isLiked ?? false;
+    }
+  }
+
+  private initializeEntry(): void {
+    if (this.entry.type !== "dataset" || typeof this.entry.id !== "number") {
+      return;
+    }
+    const did = this.entry.id;
+    const owners = this.entry.accessibleUserIds;
+    if (this.currentUid !== undefined && owners.includes(this.currentUid)) {
+      this.entryLink = [DASHBOARD_USER_DATASET, String(did)];
+    } else {
+      this.entryLink = [DASHBOARD_HUB_DATASET_RESULT_DETAIL, String(did)];
+    }
+
+    this.coverImageSrc = this.defaultCover;
+    if (this.entry.coverImageUrl) {
+      this.datasetService
+        .getDatasetCoverUrl(did)
+        .pipe(untilDestroyed(this))
+        .subscribe({
+          next: ({ url }) => {
+            this.coverImageSrc = url ?? this.defaultCover;
+            this.cdr.markForCheck();
+          },
+          error: () => {
+            this.coverImageSrc = this.defaultCover;
+            this.cdr.markForCheck();
+          },
+        });
+    }
+  }
+
+  onCoverError(event: Event): void {
+    const image = event.target as HTMLImageElement;
+    image.onerror = null;
+    image.src = this.defaultCover;
+  }
+
+  toggleLike(): void {
+    if (!isDefined(this.currentUid) || !isDefined(this.entry.id)) return;
+    // optimistic flip; server response reconciles or reverts
+    const previousLiked = this.isLiked;
+    this.isLiked = !previousLiked;
+    this.likeCount += previousLiked ? -1 : 1;
+    this.cdr.markForCheck();
+
+    this.hubService
+      .toggleLike(this.entry.id, this.entry.type, previousLiked)

Review Comment:
   >[!NOTE]
   > (pre-existing, not for this PR): the public hub listing runs with `isLogin 
= false`, so `extendSearchResultsWithHubActivityInfo` skips the `isLiked` 
enrichment and every card starts `isLiked false` regardless of whether the 
signed-in user already liked it. Clicking still optimistically flips and posts 
a like. This matches existing list-item behavior in the hub, so it's consistent 
(just flagging).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to