summaryrefslogtreecommitdiff
path: root/src/components/Composables/usePowerControl.ts
AgeCommit message (Collapse)AuthorFilesLines
2026-06-09Implemented Power page with VueQuery and Composition APINikhil Ashoka1-0/+184
This change switches power control to the EnvironmentMetrics-based Redfish endpoint, derives minimum and maximum power cap values dynamically from Redfish data, and updates ControlMode and SetPoint handling to align with the latest schema. Key changes: 1. Power control API and Redfish types: - Removes src/api/services/powerControlService.ts; fetching and PATCH are handled in the composable using shared Redfish utilities - Adds EnvironmentMetrics and PowerLimitWatts types in src/api/types/redfish.ts with proper ControlMode enum ('Automatic' | 'Disabled' | 'Manual' | 'Override') - Chassis gains an EnvironmentMetrics link - Composable resolves the Chassis collection via useRedfishCollection<Chassis>('/redfish/v1/Chassis'), picks the first chassis with EnvironmentMetrics, and fetches that resource with useQuery; mutation sends PATCH and invalidates queries to refetch fresh server state (returns Promise<void>; view owns user-facing messages) 2. Power control composable (src/components/Composables/usePowerControl.ts): - Replaces Vuex PowerControlStore with a Composition API-based composable - Uses useRedfishRoot() and useRedfishCollection for cached ServiceRoot and Chassis; uses TanStack Query to load and cache EnvironmentMetrics power data - Configures staleTime (30s freshness window) and refetchInterval (30s automatic polling when tab visible) for live power consumption updates - Note: Only controls the first Chassis with EnvironmentMetrics in multi-chassis systems (intentional for current use case) - Forwards AbortSignal to API calls for proper request cancellation - Reuses shouldRetry function from useAllSubResources - Derives dynamic min and max power cap values from Redfish PowerLimitWatts.AllowableMin/Max - Provides a mutation for submitting updated SetPoint and ControlMode; omits SetPoint when disabling to avoid sending invalid values - Handles all ControlMode enum values (Automatic, Disabled, Manual, Override); UI sets Automatic/Disabled but preserves Manual/Override when read from server - Type-safe parameters (number | null instead of string coercion) 3. Toast composable and global plugin: - useToast.ts (renamed from .js) uses bootstrap-vue-next useToast() with TypeScript types; keeps successToast/errorToast API with i18n titles - Type restricted to string for simplicity; includes TODO for potential VNode support expansion if needed - src/plugins/toast.js continues to expose global $toast for Options API - BVToastMixin.js updated to use modelValue and extract VNode content for consistency with bootstrap-vue-next 0.40.8 - Both implementations use isStatus: true for consistent toast styling with status icons 4. Views modernization: - Refactors src/views/ResourceManagement/Power.vue to use <script setup>, usePowerControl(), and the new toast composable; submitForm uses try/catch and t('pageServerPowerOperations.toast.*') for success/error toasts - Implements value caching to preserve user's typed input when toggling power cap checkbox on/off - Guards form sync watcher with v$.value?.$dirty check to prevent overwriting in-progress edits during background refetch - Loader semantics: show on first load (isLoading) and mutations, but render cached data instantly on subsequent visits with silent background refetch (avoids flicker) - Renamed validator from 'between' to 'withinPowerCapRange' to avoid confusion with Vuelidate's built-in validator - Handles all ControlMode values (Automatic, Disabled, Manual, Override) in form state synchronization - Refactors src/views/Overview/OverviewPower.vue to read from the power control composable instead of Vuex; implements settled computed to emit overview-power-complete only when chassis collection is fetched AND either no EnvironmentMetrics exists or metrics query has completed (prevents premature completion) - Shows power cap for all active control modes (Automatic, Manual, Override) - Removes mapState/mapActions usage and related Vuex wiring 5. Store cleanup and typing: - Deletes src/store/modules/ResourceManagement/PowerControlStore.js - Removes PowerControlStore registration from src/store/index.js - Updates src/store/api.d.ts to match actual implementation (set_auth_token with snake_case, accepts string | null | undefined) - Adds src/i18n.d.ts to provide basic typing for the shared api Tested-by: Manual testing on development server - Power consumption and cap values load correctly from EnvironmentMetrics with automatic 30-second polling (refetchInterval) when tab is visible - Min and max power cap values reflect dynamic limits from Redfish - Updating the power cap and enable state sends correct SetPoint and ControlMode values; SetPoint is omitted when disabling - All ControlMode values (Automatic, Disabled, Manual, Override) are handled correctly - User's typed values are preserved when toggling power cap checkbox - Form edits are not overwritten by background refetch (dirty state guard) - Success/error toasts show localized messages with consistent modelValue-based timing and status icons - Overview power card reflects updated power state; overview loader waits for both chassis and metrics queries to settle before completing - Request cancellation works properly on component unmount Change-Id: Ic61631efd8790150a5e2914822f1dd25bd77305a Signed-off-by: Nikhil Ashoka <a.nikhil@ibm.com>