Skip to content

refactor: Reafctor CKM-V2 UI#809

Open
Tejasri-Microsoft wants to merge 9 commits intodevfrom
psl-ckm-uirefactoring
Open

refactor: Reafctor CKM-V2 UI#809
Tejasri-Microsoft wants to merge 9 commits intodevfrom
psl-ckm-uirefactoring

Conversation

@Tejasri-Microsoft
Copy link

@Tejasri-Microsoft Tejasri-Microsoft commented Mar 13, 2026

Purpose

This pull request introduces Redux Toolkit and react-redux into the project and refactors state management in the main Dashboard component to use Redux instead of the previous context-based approach. It also updates dependencies and cleans up the API layer to use a centralized HTTP client. The most significant changes are grouped below:

State Management Refactor:

  • Migrated the Dashboard component in App.tsx from using custom context (useAppContext) and manual dispatches to using Redux state and dispatch hooks (useAppDispatch, useAppSelector). All state updates and side effects (such as fetching chat history, loading conversations, and clearing chat history) are now handled via Redux slices and thunks. [1] [2] [3] [4] [5] [6] [7] [8]

  • Replaced direct API calls and manual state updates in Dashboard with Redux async thunks (fetchChatHistory, loadConversation, clearAllChatHistory) and Redux actions (saveConfig, updateCitation). [1] [2] [3] [4] [5]

Dependency and Package Updates:

  • Added @reduxjs/toolkit and react-redux as dependencies in both package.json and package-lock.json, along with their peer and sub-dependencies (redux, redux-thunk, reselect, etc.). [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]

  • Updated lodash-es to version ^4.17.23.

API Layer Improvements:

  • Refactored API methods in api.ts to use a centralized httpClient for HTTP requests, improving error handling and consistency across API calls. [1] [2]

General Code Cleanup:

  • Removed unused code and comments in App.tsx, such as old context-based code and commented-out sections.

These changes lay the groundwork for more scalable and maintainable state management using Redux throughout the application.

Does this introduce a breaking change?

  • Yes
  • No

Golden Path Validation

  • I have tested the primary workflows (the "golden path") to ensure they function correctly without errors.

Deployment Validation

  • I have validated the deployment process successfully and all services are running as expected with this change.

@Tejasri-Microsoft Tejasri-Microsoft self-assigned this Mar 13, 2026
@Tejasri-Microsoft Tejasri-Microsoft marked this pull request as draft March 13, 2026 04:55
@Tejasri-Microsoft Tejasri-Microsoft changed the title Psl ckm uirefactoring Refactor UI components in CKM Mar 13, 2026
@Tejasri-Microsoft Tejasri-Microsoft changed the title Refactor UI components in CKM refactor: Reafctor MACAE-V4 UI Mar 13, 2026
@Tejasri-Microsoft Tejasri-Microsoft changed the title refactor: Reafctor MACAE-V4 UI refactor: Reafctor CKM-V2 UI Mar 13, 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

This PR refactors the CKM-V2 frontend by extracting utilities out of configs/Utils.tsx, replacing the custom React context/reducer state with Redux Toolkit slices + thunks, and introducing a shared httpClient wrapper for API calls.

Changes:

  • Introduces domain-specific utility modules (jsonUtils, messageUtils, chartUtils, apiUtils, chatParsingUtils) with a barrel export and a deprecated shim in configs/Utils.tsx.
  • Migrates app state management from AppProvider/AppReducer to Redux Toolkit (store, slices, selectors, typed hooks, async thunks).
  • Adds an interceptor-based httpClient and refactors api.ts to use it; extracts chat API logic into hooks (useChatApi, useChatHistorySave, useAutoScroll, etc.).

Reviewed changes

Copilot reviewed 43 out of 49 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/App/src/utils/messageUtils.ts Extracted UUID + conversation grouping utilities.
src/App/src/utils/jsonUtils.ts Added safe JSON parse/stringify helpers.
src/App/src/utils/index.ts Barrel re-exports for utils.
src/App/src/utils/chatParsingUtils.ts Centralized streaming response parsing helpers.
src/App/src/utils/chartUtils.ts Extracted chart config + layout helpers from old Utils.
src/App/src/utils/apiUtils.ts Added retry/cache/throttle/debounce + error parsing utilities.
src/App/src/store/thunks/chatHistoryThunks.ts Added async thunks for history CRUD operations.
src/App/src/store/store.ts Configured Redux store + RootState/AppDispatch exports.
src/App/src/store/slices/dashboardsSlice.ts Dashboard/filter/chart slice replacing context actions.
src/App/src/store/slices/citationSlice.ts Citation panel state slice.
src/App/src/store/slices/chatSlice.ts Chat message + streaming state slice.
src/App/src/store/slices/chatHistorySlice.ts Conversation list + fetch state slice.
src/App/src/store/slices/appSlice.ts App-level config + selected/generated conversation IDs slice.
src/App/src/store/selectors.ts Added narrow selectors for component subscriptions.
src/App/src/store/hooks.ts Added typed useAppDispatch/useAppSelector hooks.
src/App/src/state/useAppContext.tsx Removed legacy context hook.
src/App/src/state/AppReducer.tsx Removed legacy reducer implementation.
src/App/src/state/AppProvider.tsx Removed legacy provider/context implementation.
src/App/src/state/ActionConstants.tsx Removed legacy action constants.
src/App/src/logo.svg Removed CRA default logo asset.
src/App/src/index.tsx Switched root provider from AppProvider to Redux Provider.
src/App/src/hooks/useTextareaAutoResize.ts Added textarea autoresize hook.
src/App/src/hooks/useDebounce.ts Added generic debouncing hook.
src/App/src/hooks/useChatHistorySave.ts Extracted “persist chat to DB” side-effect into a hook.
src/App/src/hooks/useChatApi.ts Extracted/centralized chat + chart API streaming logic.
src/App/src/hooks/useAutoScroll.ts Added scroll-to-bottom hook with sentinel ref.
src/App/src/hooks/index.ts Barrel re-exports for hooks.
src/App/src/configs/Utils.tsx Replaced implementation with deprecated re-export shim.
src/App/src/components/Citations/Citations.tsx Migrated citations interactions from context to Redux.
src/App/src/components/Citations/AnswerParser.tsx Simplified answer parsing (removed dead/legacy code).
src/App/src/components/CitationPanel/CitationPanel.tsx Migrated close action to Redux; memoized markdown plugins.
src/App/src/components/ChatHistoryPanel/ChatHistoryPanel.tsx Migrated history panel state reads to Redux selectors.
src/App/src/components/ChatHistoryListItemGroups/ChatHistoryListItemGroups.tsx Migrated list grouping + fetching state to Redux.
src/App/src/components/ChatHistoryListItemCell/ChatHistoryListItemCell.tsx Migrated delete/rename flows to thunks + Redux state.
src/App/src/components/ChatChart/ChatChart.tsx Updated chart utils import path.
src/App/src/components/Chat/Chat.tsx Major refactor: uses Redux + extracted hooks; removed inline API logic.
src/App/src/components/ChartFilter/ChartFilter.tsx Migrated filters state to Redux; added debounced topic search.
src/App/src/components/Chart/Chart.tsx Migrated fetch flags/data storage to Redux slice actions.
src/App/src/chartComponents/WordCloudChart.tsx Updated chart utils imports.
src/App/src/chartComponents/TopicTable.tsx Updated chart utils imports.
src/App/src/api/httpClient.ts Added shared fetch wrapper with interceptors, timeout, retries.
src/App/src/api/api.ts Refactored API calls to use httpClient + shared error response factory.
src/App/src/Assets/Reset-icon.svg Removed reset icon asset.
src/App/src/App.tsx Migrated top-level config + history actions to Redux.
src/App/package.json Added Redux deps; minor dependency adjustments.
src/App/package-lock.json Lockfile updates for new deps.
Files not reviewed (1)
  • src/App/package-lock.json: Language not supported

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

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +64 to +81
let lastError: unknown;

for (let attempt = 0; attempt <= retries; attempt++) {
try {
return await fn();
} catch (error) {
lastError = error;
if (attempt === retries || !shouldRetry(error, attempt)) break;

// Exponential delay + small random jitter (0 – 20 % of delay)
const delay = baseDelay * Math.pow(factor, attempt);
const jitter = delay * 0.2 * Math.random();
await new Promise((r) => setTimeout(r, delay + jitter));
}
}

throw lastError;
}
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

This PR refactors the CKM-V2 UI by migrating state management from a custom React context/reducer to Redux Toolkit, extracting utilities into domain-focused modules, and introducing a shared HTTP client + reusable hooks to reduce duplication.

Changes:

  • Replaced AppProvider/custom reducer pattern with Redux Toolkit store, slices, selectors, and async thunks.
  • Split the former monolithic configs/Utils.tsx into src/utils/* and added new parsing helpers for streaming chat responses.
  • Centralized API calls via a singleton httpClient with interceptors, timeouts, and optional retry behavior.

Reviewed changes

Copilot reviewed 43 out of 49 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/App/src/utils/messageUtils.ts New message/history utilities (UUID + history bucketing).
src/App/src/utils/jsonUtils.ts Adds safe JSON parse/stringify helpers.
src/App/src/utils/index.ts New barrel exports for src/utils.
src/App/src/utils/chatParsingUtils.ts Centralizes streaming answer/citations + chart parsing logic.
src/App/src/utils/chartUtils.ts Extracts chart constants and layout helpers from old Utils.
src/App/src/utils/apiUtils.ts Adds retry/cache/throttle/debounce + error parsing utilities.
src/App/src/store/thunks/chatHistoryThunks.ts Introduces async thunks for chat history operations.
src/App/src/store/store.ts Configures Redux store and exports RootState/AppDispatch types.
src/App/src/store/slices/dashboardsSlice.ts New dashboards slice replacing reducer cases.
src/App/src/store/slices/citationSlice.ts New citation slice replacing reducer cases.
src/App/src/store/slices/chatSlice.ts New chat slice and extraReducers for history thunks.
src/App/src/store/slices/chatHistorySlice.ts New chatHistory slice and thunk lifecycle handling.
src/App/src/store/slices/appSlice.ts New app slice for config, IDs, selection, spinner.
src/App/src/store/selectors.ts Adds narrow selectors for memoization-friendly access.
src/App/src/store/hooks.ts Adds typed useAppDispatch/useAppSelector hooks.
src/App/src/state/useAppContext.tsx Removes context hook (migration to Redux).
src/App/src/state/AppReducer.tsx Removes legacy reducer (migration to Redux).
src/App/src/state/AppProvider.tsx Removes legacy context provider (migration to Redux).
src/App/src/state/ActionConstants.tsx Removes legacy action constants (migration to Redux).
src/App/src/logo.svg Removes CRA default logo asset.
src/App/src/index.tsx Wraps app with Redux <Provider store={store}>.
src/App/src/hooks/useTextareaAutoResize.ts New hook for textarea auto-resize behavior.
src/App/src/hooks/useDebounce.ts New hook for debounced values (used in filters).
src/App/src/hooks/useChatHistorySave.ts Extracts “save chat history” side-effect into a hook.
src/App/src/hooks/useChatApi.ts Extracts chat API streaming + chart flows into a hook.
src/App/src/hooks/useAutoScroll.ts New hook for scroll-to-bottom behavior.
src/App/src/hooks/index.ts Barrel exports for hooks.
src/App/src/configs/Utils.tsx Deprecated shim re-exporting from new src/utils/*.
src/App/src/components/Citations/Citations.tsx Migrates citation interactions from context to Redux.
src/App/src/components/Citations/AnswerParser.tsx Simplifies answer parsing (returns answer + citations).
src/App/src/components/CitationPanel/CitationPanel.tsx Migrates citation panel close action to Redux + memoizes plugins.
src/App/src/components/ChatHistoryPanel/ChatHistoryPanel.tsx Migrates state reads to Redux selectors.
src/App/src/components/ChatHistoryListItemGroups/ChatHistoryListItemGroups.tsx Uses Redux selectors + new segregateItems util.
src/App/src/components/ChatHistoryListItemCell/ChatHistoryListItemCell.tsx Migrates delete/rename flows to thunks + Redux state.
src/App/src/components/ChatChart/ChatChart.tsx Updates chart config import to new chartUtils.
src/App/src/components/Chat/Chat.tsx Refactors monolithic chat logic into hooks + Redux usage.
src/App/src/components/ChartFilter/ChartFilter.tsx Migrates filters to Redux and debounces topic search.
src/App/src/components/Chart/Chart.tsx Migrates dashboards state/actions to Redux slice APIs.
src/App/src/chartComponents/WordCloudChart.tsx Updates chart helper imports to new chartUtils.
src/App/src/chartComponents/TopicTable.tsx Updates color imports to new chartUtils.
src/App/src/api/httpClient.ts Adds shared HTTP client with interceptors, timeout, retry.
src/App/src/api/api.ts Refactors API functions to use httpClient + helpers.
src/App/src/Assets/Reset-icon.svg Removes unused reset icon asset.
src/App/src/App.tsx Migrates app bootstrapping/data loading to Redux thunks/slices.
src/App/package.json Adds RTK + react-redux; bumps lodash-es patch.
src/App/package-lock.json Locks new Redux dependencies.
Files not reviewed (1)
  • src/App/package-lock.json: Language not supported

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

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +228 to +230
? Array.isArray(msg.citations) && typeof msg.citations[0] === "string"
? parseCitationFromMessage(msg.citations)
: msg.citations
Comment on lines +86 to +91
export function parseChartContent(runningText: string): ChartParseResult {
const splitRunningText = runningText.split("}{");
const parsedChartResponse = safeParse<any>(
"{" + splitRunningText[splitRunningText.length - 1],
null
);
Comment on lines +63 to +66
// /.auth/me is an absolute path outside the API base URL
const response = await httpClient.request<Response>("/.auth/me", {
rawResponse: true,
});
Comment on lines +61 to +66
// Sort descending by updatedAt
items.sort(
(a, b) =>
new Date(b.updatedAt ?? new Date()).getTime() -
new Date(a.updatedAt ?? new Date()).getTime()
);
Comment on lines +66 to +69
const parseCitationFromMessage = useCallback((message: any) => {
const toolMessage = safeParse<{ citations?: string[] }>("{" + message, {});
return toolMessage?.citations ?? [];
}, []);
Tejasri-Microsoft and others added 6 commits March 13, 2026 16:11
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Roopan-Microsoft Roopan-Microsoft marked this pull request as ready for review March 16, 2026 11:31
@microsoft-github-policy-service

@Tejasri-Microsoft please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"
Contributor License Agreement

Contribution License Agreement

This Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
and conveys certain license rights to Microsoft Corporation and its affiliates (“Microsoft”) for Your
contributions to Microsoft open source projects. This Agreement is effective as of the latest signature
date below.

  1. Definitions.
    “Code” means the computer software code, whether in human-readable or machine-executable form,
    that is delivered by You to Microsoft under this Agreement.
    “Project” means any of the projects owned or managed by Microsoft and offered under a license
    approved by the Open Source Initiative (www.opensource.org).
    “Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any
    Project, including but not limited to communication on electronic mailing lists, source code control
    systems, and issue tracking systems that are managed by, or on behalf of, the Project for the purpose of
    discussing and improving that Project, but excluding communication that is conspicuously marked or
    otherwise designated in writing by You as “Not a Submission.”
    “Submission” means the Code and any other copyrightable material Submitted by You, including any
    associated comments and documentation.
  2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any
    Project. This Agreement covers any and all Submissions that You, now or in the future (except as
    described in Section 4 below), Submit to any Project.
  3. Originality of Work. You represent that each of Your Submissions is entirely Your original work.
    Should You wish to Submit materials that are not Your original work, You may Submit them separately
    to the Project if You (a) retain all copyright and license information that was in the materials as You
    received them, (b) in the description accompanying Your Submission, include the phrase “Submission
    containing materials of a third party:” followed by the names of the third party and any licenses or other
    restrictions of which You are aware, and (c) follow any other instructions in the Project’s written
    guidelines concerning Submissions.
  4. Your Employer. References to “employer” in this Agreement include Your employer or anyone else
    for whom You are acting in making Your Submission, e.g. as a contractor, vendor, or agent. If Your
    Submission is made in the course of Your work for an employer or Your employer has intellectual
    property rights in Your Submission by contract or applicable law, You must secure permission from Your
    employer to make the Submission before signing this Agreement. In that case, the term “You” in this
    Agreement will refer to You and the employer collectively. If You change employers in the future and
    desire to Submit additional Submissions for the new employer, then You agree to sign a new Agreement
    and secure permission from the new employer before Submitting those Submissions.
  5. Licenses.
  • Copyright License. You grant Microsoft, and those who receive the Submission directly or
    indirectly from Microsoft, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license in the
    Submission to reproduce, prepare derivative works of, publicly display, publicly perform, and distribute
    the Submission and such derivative works, and to sublicense any or all of the foregoing rights to third
    parties.
  • Patent License. You grant Microsoft, and those who receive the Submission directly or
    indirectly from Microsoft, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license under
    Your patent claims that are necessarily infringed by the Submission or the combination of the
    Submission with the Project to which it was Submitted to make, have made, use, offer to sell, sell and
    import or otherwise dispose of the Submission alone or with the Project.
  • Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement.
    No additional licenses or rights whatsoever (including, without limitation, any implied licenses) are
    granted by implication, exhaustion, estoppel or otherwise.
  1. Representations and Warranties. You represent that You are legally entitled to grant the above
    licenses. You represent that each of Your Submissions is entirely Your original work (except as You may
    have disclosed under Section 3). You represent that You have secured permission from Your employer to
    make the Submission in cases where Your Submission is made in the course of Your work for Your
    employer or Your employer has intellectual property rights in Your Submission by contract or applicable
    law. If You are signing this Agreement on behalf of Your employer, You represent and warrant that You
    have the necessary authority to bind the listed employer to the obligations contained in this Agreement.
    You are not expected to provide support for Your Submission, unless You choose to do so. UNLESS
    REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, AND EXCEPT FOR THE WARRANTIES
    EXPRESSLY STATED IN SECTIONS 3, 4, AND 6, THE SUBMISSION PROVIDED UNDER THIS AGREEMENT IS
    PROVIDED WITHOUT WARRANTY OF ANY KIND, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY OF
    NONINFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
  2. Notice to Microsoft. You agree to notify Microsoft in writing of any facts or circumstances of which
    You later become aware that would make Your representations in this Agreement inaccurate in any
    respect.
  3. Information about Submissions. You agree that contributions to Projects and information about
    contributions may be maintained indefinitely and disclosed publicly, including Your name and other
    information that You submit with Your Submission.
  4. Governing Law/Jurisdiction. This Agreement is governed by the laws of the State of Washington, and
    the parties consent to exclusive jurisdiction and venue in the federal courts sitting in King County,
    Washington, unless no federal subject matter jurisdiction exists, in which case the parties consent to
    exclusive jurisdiction and venue in the Superior Court of King County, Washington. The parties waive all
    defenses of lack of personal jurisdiction and forum non-conveniens.
  5. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and
    supersedes any and all prior agreements, understandings or communications, written or oral, between
    the parties relating to the subject matter hereof. This Agreement may be assigned by Microsoft.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants