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

Pr@main/user input #2706

Merged
merged 2 commits into from
Mar 27, 2025
Merged

Pr@main/user input #2706

merged 2 commits into from
Mar 27, 2025

Conversation

wangdan-fit2cloud
Copy link
Contributor

What this PR does / why we need it?

Summary of your change

Please indicate you've done the following:

  • Made sure tests are passing and test coverage is added if needed.
  • Made sure commit message follow the rule of Conventional Commits specification.
  • Considered the docs impact and opened a new docs issue or PR with docs changes if needed.

Copy link

f2c-ci-robot bot commented Mar 27, 2025

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link

f2c-ci-robot bot commented Mar 27, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

res.data.init_field_list &&
res.data.init_field_list.length > 0 &&
res.data.init_field_list.filter((item: any) => item.default_value).length !== res.data.init_field_list.length
res.data.init_field_list.filter((item: any) => item.default_value).length !==
res.data.init_field_list.length
) {
InitParamDrawerRef.value.open(res.data, bool)
row.is_active = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code has several issues and optimizations that can be addressed:

  1. Tabs Handling Issue:
    The v-model of the tabs does not update correctly when selected to "INTERNAL". The event handler tabChangeHandle() should ensure that selectUserId is reset to 'all' and searchValue is cleared when switching between tabs.

  2. Raw Markdown Importing:
    The import statement for raw markdown files (...import.meta.glob('/fx/*/detail.md, ...)seems unnecessary as it will only work in development mode with a build environment. Consider usinguseFetch` or similar methods to dynamically retrieve data during runtime.

  3. Code Duplicity:
    The code snippets around line 407 have duplicative logic where you check if init_fields exist before checking each field's default value. Simplify this condition to:

    if (
      res.data.init_params && // Check init_params first
      res.data.init_field_list &&
      [...]
      res.data.init_field_list.some(item => item.default_value)
    )

Here's the optimized version of the key segments affected by these issues:

<template>
  <!-- Template remains unchanged -->
</template>

<script setup lang='ts'>
import { ref, watch } from 'vue';
import type { Ref } from 'vue';

const functionName = ref('');
const selectUserId: Ref<string> = ref('') as Ref<string>;
const searchValue: Ref<string> = ref('');
// No need for const internalDesc

const { user } = useStore();

watch(
  () => selectUserId.value,
  newVal => {
    if (newVal !== 'all') {
      searchValue.value = ''; // Reset searchValue on userId change
    }
  },
  { immediate: true }
);

async function tabChangeHandle() {
  selectUserId.value = 'all'; // Always set selectUserId to 'all' when changing tabs
  searchValue.value = '';
}

// Rest of the script...

Optimized Code Summary:

  • Removed raw markdown importing which may slow down production runs.
  • Corrected handling of funcType changes to include resetting selectUserId to 'all'.
  • Simplified logical checks for determining whether form fields have defaults.

These optimizations should improve both performance and usability.

if (isUserInput.value && localStorage.getItem(`${accessToken}userForm`)) {
let userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}')
form_data.value = userFormData
}
window.speechSynthesis.cancel()
window.sendMessage = sendMessage
bus.on('on:transcribing', (status: boolean) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few potential areas of improvement and corrections in the given code:

  1. Undefined Check: The function toggleUserInput uses firsUserInput.value = false and showUserInput.value = false. Ensure that firsUserInput and showUserInput are properly initialized before being used.

  2. Nullish Coalescing Operator: Consider using the nullish coalescing operator (??) when accessing properties like localStorage.getItem() to avoid errors if localStorage is not supported.

  3. Stringify/Parse JSON Safely: When handling local storage, ensure that you parse and stringify objects safely by checking their validity. Use methods like JSON.parse(...) with defaults to prevent crashes.

  4. Logical Order: In sendMessage function, there's an unnecessary nested condition inside the check for userFormRef.value?.checkInputParam(). Move it outside if necessary.

Here’s an updated version of the relevant parts of the code with some improvements:

function toggleUserInput() {
  if (userFormRef.value?.checkInputParam()) {
    firsUserInput.value ??= false;
    showUserInput.value ??= false;
  }
}

function sendMessage(val: string, other_params_data?: any, chat?: chatType) {
  const shouldProcessInput = !!userFormRef.value?.checkInputParam();

  // Show input if needed after processing
  if (!shouldProcessInput && isUserInput.value) {
    showUserInput.value = true;
  }

  if (!loading.value && props.applicationDetails?.name) {
    if (shouldProcessInput) {
      let userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}') ?? {};
      const newData = Object.fromEntries(
        Object.entries<Object>(form_data.value).filter(([key]) =>
          Object.prototype.hasOwnProperty.call(userFormData, key)
        )
      );
      localStorage.setItem(`${accessToken}userForm`, JSON.stringify(newData));
    }

    handleDebounceClick(val, other_params_data, chat);
  }
}
  1. Additional Comments: Add comments where appropriate to explain complex logic or steps for future reference.

These changes aim to improve the robustness and readability of the代码 while maintaining its functionality.

}
const cancelHandle = () => {
emit('cancel')
}
defineExpose({ checkInputParam })
onMounted(() => {
firstMounted.value = true
handleInputFieldList()
})
</script>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provided code is generally well-written with proper imports, data declarations, watcher functions, and event emitters. However, there are a few minor improvements and optimizations that can be made:

  1. Avoid using useRef for strings: Since params.accessToken will always return a string, you don't need to wrap it in ref. Use let or const directly.

  2. Simplify watch, handle default values properly for showUderInput.

  3. Remove redundant check in handleConfirmHandle:

// Original check for required input parameters
if (checkInputParam()) {
  emit('confirm');
}

If checkInputParam() already checks if the user has filled out the necessary fields and emits an error message if not, this can be removed since the logic might have been intended to prevent confirm action in such cases, but removing it doesn't alter the functionality significantly unless needed otherwise.

  1. Remove unnecessary line breaks within template literals inside single quotes (''). The current format seems correct though, so no change is needed here.

By making these small adjustments, you could make the code cleaner and slightly more efficient. Keep up the good practices!

@wangdan-fit2cloud wangdan-fit2cloud merged commit 378de21 into main Mar 27, 2025
4 checks passed
@wangdan-fit2cloud wangdan-fit2cloud deleted the pr@main/user-input branch March 27, 2025 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants