Skip to content

Feat(heuristics): Add optional weights feature toggle in settings#1833

Open
rakshityadav1868 wants to merge 1 commit intoruxailab:developfrom
rakshityadav1868:adding-weight-toggle-btn
Open

Feat(heuristics): Add optional weights feature toggle in settings#1833
rakshityadav1868 wants to merge 1 commit intoruxailab:developfrom
rakshityadav1868:adding-weight-toggle-btn

Conversation

@rakshityadav1868
Copy link
Contributor

fixes #1830

Overview

Add an optional "Enable Weights Feature" toggle in the Settings tab of the Edit Test page, allowing admins to control whether the Weights tab is visible and accessible for heuristic studies.

Changes Made

1. Data Model Update

  • Modified HeuristicStudy.js to include useWeights boolean field (default: false)
  • Added useWeights to toFirestore() method for persistence

2. Settings UI Enhancement

  • Added toggle switch in HeuristicsSettings.vue to enable/disable weights feature

3. Frontend Logic

  • Updated EditTest.vue to conditionally show/hide Weights tab based on useWeights flag
  • Added watcher to automatically adjust active tab index when Weights tab visibility changes

4. Internationalization

  • Added translations in all supported languages:
    • English, Spanish, French, German, Portuguese, Russian, Hindi, Arabic, Chinese, Japanese
  • New i18n keys:
    • HeuristicsSettings.titles.enableWeights: Label for toggle
    • HeuristicsSettings.messages.enableWeightsDescription: Description text
Screen.Recording.2026-03-08.at.12.46.23.AM.mp4

Signed-off-by: Rakshit Yadav <yadavrakshit60@gmail.com>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 7, 2026

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a per-heuristic-study useWeights flag and exposes it in the Edit Test “Settings” tab so admins can toggle visibility/access to the Weights tab.

Changes:

  • Extend HeuristicStudy to persist a new boolean useWeights field to Firestore.
  • Add a new “Enable Weights Feature” toggle to HeuristicsSettings.vue and conditionally render the Weights tab/content in EditTest.vue.
  • Add i18n strings for the new toggle across supported locales.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/ux/Heuristic/views/EditTest.vue Conditionally renders the Weights tab and adjusts tab indices when visibility changes.
src/ux/Heuristic/models/HeuristicStudy.js Adds useWeights to the heuristic study model and persistence.
src/ux/Heuristic/components/HeuristicsSettings.vue Adds settings UI toggle and commits useWeights into Vuex.
src/app/plugins/locales/en.json Adds i18n keys for the toggle label/description.
src/app/plugins/locales/es.json Adds i18n keys for the toggle label/description.
src/app/plugins/locales/fr.json Adds i18n keys for the toggle label/description.
src/app/plugins/locales/de.json Adds i18n keys for the toggle label/description.
src/app/plugins/locales/pt_br.json Adds i18n keys for the toggle label/description.
src/app/plugins/locales/ru.json Adds i18n keys for the toggle label/description.
src/app/plugins/locales/hi.json Adds i18n keys for the toggle label/description.
src/app/plugins/locales/ar.json Adds i18n keys for the toggle label/description.
src/app/plugins/locales/zh.json Adds i18n keys for the toggle label/description.
src/app/plugins/locales/ja.json Adds i18n keys for the toggle label/description.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +148 to +157
// Watch for changes in showWeightsTab to fix index
watch(showWeightsTab, (newVal, oldVal) => {
// If weights tab visibility changed and we're currently on or past the weights tab
if (newVal !== oldVal) {
if (!newVal && index.value > 1) {
// Weights tab is now hidden and index is on Settings (was 3, should be 2)
index.value = 2
}
}
})
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

The watcher only corrects the active tab when weights are disabled. If weights are enabled while the user is on Settings (index 2 when weights are hidden), the current index will now point to the Weights tab and the UI will unexpectedly jump away from Settings. Consider updating the watcher to also handle the false→true transition (and generally clamp index to the highest available tab based on showWeightsTab/showSettingsTab).

Suggested change
// Watch for changes in showWeightsTab to fix index
watch(showWeightsTab, (newVal, oldVal) => {
// If weights tab visibility changed and we're currently on or past the weights tab
if (newVal !== oldVal) {
if (!newVal && index.value > 1) {
// Weights tab is now hidden and index is on Settings (was 3, should be 2)
index.value = 2
}
}
})
// Watch for changes in tab visibility to keep the active index valid
watch(
[showWeightsTab, showSettingsTab],
([weightsVisible, settingsVisible], [oldWeightsVisible]) => {
// Handle the case where weights are enabled while the user is on Settings.
// When weights are hidden, SETTINGS has index 2; when weights are shown,
// WEIGHTS becomes 2 and SETTINGS moves to 3. If we don't adjust here,
// the user would unexpectedly jump from SETTINGS to WEIGHTS.
if (!oldWeightsVisible && weightsVisible && settingsVisible && index.value === 2) {
index.value = 3
return
}
// In all cases, clamp the index to the highest available tab based on visibility.
let maxIndex = 1 // HEURISTICS (0) and OPTIONS (1) are always present
if (weightsVisible) {
maxIndex = 2
}
if (settingsVisible) {
maxIndex = weightsVisible ? 3 : 2
}
if (index.value > maxIndex) {
index.value = maxIndex
}
}
)

Copilot uses AI. Check for mistakes.
const windowWidth = ref(window.innerWidth)
const showSettingsTab = computed(() => !props.isTemplate)
const test = computed(() => store.getters.test)
const showWeightsTab = computed(() => test.value.useWeights ?? false)
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

In template preview mode, showWeightsTab is derived solely from test.useWeights. The template preview payload currently provides testWeights but not useWeights, so weights will never be shown in the preview even if the template contains weights. Either include useWeights in the template payload or derive the preview visibility from existing data (e.g., non-empty testWeights) / default to showing weights for templates.

Suggested change
const showWeightsTab = computed(() => test.value.useWeights ?? false)
const showWeightsTab = computed(() => {
if (props.isTemplate) {
const weights = props.templateTest?.testWeights
if (Array.isArray(weights)) {
return weights.length > 0
}
return !!weights
}
return test.value?.useWeights ?? false
})

Copilot uses AI. Check for mistakes.
<HeuristicsSettings
v-if="showSettingsTab && index == 3"
v-if="showSettingsTab && (showWeightsTab ? index == 3 : index == 2)"
:is-template="isTemplate"
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

Changes made inside HeuristicsSettings (like toggling useWeights) currently won’t make the Save button appear because this component doesn’t emit a change event and the parent only sets change = true for other tabs. Consider emitting a change event from HeuristicsSettings when useWeights changes and wiring it up here so the user can persist the toggle.

Suggested change
:is-template="isTemplate"
:is-template="isTemplate"
@change="change = true"

Copilot uses AI. Check for mistakes.
Comment on lines +154 to +158
set: (value) => {
store.commit('SET_TEST', {
...test.value,
useWeights: value,
})
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

Toggling useWeights commits to Vuex but doesn’t notify the parent view that there are unsaved changes, so the toggle can’t be persisted unless the user edits something else first. Consider emitting a change event (or otherwise setting the parent’s change flag) from this setter / switch update handler.

Copilot uses AI. Check for mistakes.
@github-actions github-actions bot added stale and removed stale labels Mar 15, 2026
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.

feat(heuristics): weights must be hidden on "test" tab

2 participants