kunwp1 commented on code in PR #9267:
URL: https://github.com/apache/texera/pull/9267#discussion_r4463247300


##########
frontend/src/app/workspace/component/hugging-face-image-upload/hugging-face-image-upload.component.ts:
##########
@@ -71,14 +70,7 @@ export class HuggingFaceImageUploadComponent extends 
FieldType<FieldTypeConfig>
 
     try {
       const dataUrl = await this.compressImage(file);
-      this.fileName = file.name;
-      this.formControl.setValue(dataUrl);
-      if (typeof this.key === "string" && this.model) {
-        this.model[this.key] = dataUrl;
-      }
-      this.formControl.markAsDirty();
-      this.formControl.markAsTouched();
-      this.formControl.updateValueAndValidity();
+      this.setMediaValue(dataUrl, file.name);
     } catch {
       this.errorMessage = "Could not prepare this image. Try a smaller image 
file.";
       input.value = "";

Review Comment:
   Now that `resetSelection` lives in the base, the image's two rejection paths 
(this one and the wrong-type check above) could use it too. 



##########
frontend/src/app/workspace/component/hugging-face-media-upload.base.ts:
##########
@@ -0,0 +1,65 @@
+/**
+ * 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 { Directive } from "@angular/core";
+import { FieldType, FieldTypeConfig } from "@ngx-formly/core";
+
+@Directive()
+export abstract class HuggingFaceMediaUploadBase extends 
FieldType<FieldTypeConfig> {
+  fileName = "";
+  errorMessage = "";
+
+  abstract get hasMedia(): boolean;
+  abstract get mediaFallbackLabel(): string;
+  abstract get previewSrc(): string;

Review Comment:
   The base could own `hasMedia` and `previewSrc` too. Each subclass still 
carries `hasImage`/`hasAudio`, a `hasMedia` that forwards to it, and a 
`previewSrc`, and the two copies differ only in the `data:image/` vs 
`data:audio/` prefix.
   
   I suggest to have an abstract `dataUrlPrefix` and `mediaFallbackLabel` as a 
readonly field rather than a getter.



-- 
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