Skip to content

Commit 8cca37e

Browse files
committed
MAT-9817: Revert changes to consolidate in madie-util.
1 parent baa6acd commit 8cca37e

12 files changed

Lines changed: 54 additions & 2643 deletions

File tree

package-lock.json

Lines changed: 5 additions & 55 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,12 @@
7676
},
7777
"dependencies": {
7878
"@madie/madie-design-system": "^1.2.93",
79-
"@madie/madie-models": "^1.4.73",
79+
"@madie/madie-models": "^1.4.76",
8080
"@mui/icons-material": "^6.5.0",
8181
"@mui/material": "^6.5.0",
8282
"@tanstack/react-table": "^8.21.3",
8383
"ace-builds": "^1.44.0",
8484
"axios": "^1.17.0",
85-
"file-saver": "^2.0.5",
8685
"formik": "^2.4.9",
8786
"lodash": "^4.18.1",
8887
"react": "^17.0.2",
@@ -92,8 +91,7 @@
9291
"single-spa": "^5.9.3",
9392
"single-spa-react": "^4.2.0",
9493
"tailwindcss": "^3.4.1",
95-
"twin.macro": "^3.4.1",
96-
"yup": "^1.7.1"
94+
"twin.macro": "^3.4.1"
9795
},
9896
"types": "dist/madie-madie-admin.d.ts",
9997
"overrides": {

src/components/landing/userManagement/userProfile/UserProfile.test.tsx

Lines changed: 13 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jest.mock("@madie/madie-util", () => ({
3939
})),
4040
useOktaTokens: jest.fn().mockReturnValue({
4141
getAccessToken: () => "test-token",
42-
getUserName: () => "testUser",
42+
getUserName: () => "test_user",
4343
}),
4444
useUserRoles: jest
4545
.fn()
@@ -158,10 +158,7 @@ jest.mock("@madie/madie-util", () => ({
158158
</button>
159159
</div>
160160
) : null,
161-
}));
162-
jest.mock(
163-
"./actionCenter/LibraryShareDialog/LibraryShareDialog",
164-
() => (props: any) =>
161+
LibraryShareDialog: () => (props: any) =>
165162
props.open ? (
166163
<div data-testid="library-share-dialog" data-option={props.option}>
167164
Library Share Dialog
@@ -186,8 +183,16 @@ jest.mock(
186183
Close
187184
</button>
188185
</div>
189-
) : null
190-
);
186+
) : null,
187+
LibraryShareAction: jest.fn((props) => (
188+
<button
189+
data-testid="share-action-btn"
190+
onClick={() => props.onClick?.("Share With")}
191+
>
192+
Share
193+
</button>
194+
)),
195+
}));
191196

192197
const renderAt = (initialEntry: string) =>
193198
render(
@@ -2605,91 +2610,7 @@ describe("UserProfile", () => {
26052610
});
26062611
});
26072612

2608-
describe("library share actions", () => {
2609-
it("opens LibraryShareDialog when Share With is selected for a library", async () => {
2610-
mockAdminSearchMeasures.mockResolvedValue(pageWith([ownedMeasure], 1));
2611-
mockFetchCqlLibraries.mockResolvedValue(pageWith([ownedLibrary], 1));
2612-
2613-
renderAt("/admin/userProfile/test_user");
2614-
2615-
await userEvent.click(await screen.findByTestId("owned-libraries-tab"));
2616-
2617-
await userEvent.click(await screen.findByTestId("checkbox-lib1"));
2618-
2619-
await userEvent.click(await screen.findByTestId("share-action-btn"));
2620-
2621-
await userEvent.click(await screen.findByTestId("Share With-option"));
2622-
2623-
expect(
2624-
await screen.findByTestId("library-share-dialog")
2625-
).toBeInTheDocument();
2626-
2627-
expect(screen.getByTestId("library-share-dialog")).toHaveAttribute(
2628-
"data-option",
2629-
"Share With"
2630-
);
2631-
});
2632-
it("handles successful library share dialog close and displays success toast", async () => {
2633-
mockAdminSearchMeasures.mockResolvedValue(pageWith([ownedMeasure], 1));
2634-
mockFetchCqlLibraries.mockResolvedValue(pageWith([ownedLibrary], 1));
2635-
2636-
renderAt("/admin/userProfile/test_user");
2637-
2638-
await userEvent.click(await screen.findByTestId("owned-libraries-tab"));
2639-
2640-
await userEvent.click(await screen.findByTestId("checkbox-lib1"));
2641-
2642-
await userEvent.click(await screen.findByTestId("share-action-btn"));
2643-
2644-
await userEvent.click(await screen.findByTestId("Share With-option"));
2645-
2646-
const callsBefore = mockFetchCqlLibraries.mock.calls.length;
2647-
2648-
await userEvent.click(
2649-
await screen.findByTestId("library-share-success-btn")
2650-
);
2651-
2652-
expect(
2653-
screen.queryByTestId("library-share-dialog")
2654-
).not.toBeInTheDocument();
2655-
2656-
expect(
2657-
await screen.findByText("Library Successfully Shared")
2658-
).toBeInTheDocument();
2659-
2660-
await waitFor(() => {
2661-
expect(mockFetchCqlLibraries.mock.calls.length).toBeGreaterThan(
2662-
callsBefore
2663-
);
2664-
});
2665-
});
2666-
it("handles library share dialog close with a non-success message", async () => {
2667-
mockAdminSearchMeasures.mockResolvedValue(pageWith([ownedMeasure], 1));
2668-
mockFetchCqlLibraries.mockResolvedValue(pageWith([ownedLibrary], 1));
2669-
2670-
renderAt("/admin/userProfile/test_user");
2671-
2672-
await userEvent.click(await screen.findByTestId("owned-libraries-tab"));
2673-
2674-
await userEvent.click(await screen.findByTestId("checkbox-lib1"));
2675-
2676-
await userEvent.click(await screen.findByTestId("share-action-btn"));
2677-
2678-
await userEvent.click(await screen.findByTestId("Share With-option"));
2679-
2680-
await userEvent.click(
2681-
await screen.findByTestId("library-share-danger-btn")
2682-
);
2683-
2684-
expect(
2685-
screen.queryByTestId("library-share-dialog")
2686-
).not.toBeInTheDocument();
2687-
2688-
expect(
2689-
await screen.findByText("Unable to share library")
2690-
).toBeInTheDocument();
2691-
});
2692-
});
2613+
describe("library share actions", () => {});
26932614

26942615
describe("transfer action", () => {
26952616
const ownedMeasureRow = {

src/components/landing/userManagement/userProfile/UserProfile.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
adminUserStore,
1515
useFeatureFlags,
1616
ExportDialog,
17+
LibraryShareDialog,
1718
ViewHRModal,
1819
ViewMeasureHistoryDialog,
1920
CompareVersionsDialog,
@@ -22,6 +23,7 @@ import {
2223
exportMeasure as downloadMeasureExport,
2324
formatCmsId,
2425
checkUserCanEdit,
26+
useOktaTokens,
2527
} from "@madie/madie-util";
2628
import {
2729
ColumnDef,
@@ -53,7 +55,6 @@ import {
5355
import ActionCenter from "./actionCenter/ActionCenter";
5456
import "./UserProfile.scss";
5557
import LibraryActionCenter from "./actionCenter/LibraryActionCenter";
56-
import LibraryShareDialog from "./actionCenter/LibraryShareDialog/LibraryShareDialog";
5758
import _ from "lodash";
5859

5960
type Ownership =
@@ -325,6 +326,8 @@ const MeasureStatusChips = ({ measure }: { measure: any }) => (
325326

326327
const UserProfile = () => {
327328
const { harpId } = useParams<{ harpId: string }>() as { harpId: string };
329+
const { getUserName } = useOktaTokens();
330+
const userName = getUserName();
328331
const userServiceApi = useRef(useUserServiceApi()).current;
329332
const measureServiceApi = useRef(useMeasureServiceApi()).current;
330333
const cqlLibraryServiceApi = useRef(useCqlLibraryServiceApi()).current;
@@ -423,7 +426,6 @@ const UserProfile = () => {
423426
setExpandedLibraryRows([]);
424427
setSelectedExpandedLibraryRowIds([]);
425428
}, []);
426-
427429
useEffect(() => {
428430
const controller = new AbortController();
429431
userServiceApi
@@ -1476,7 +1478,7 @@ const UserProfile = () => {
14761478
if (draft) {
14771479
await cqlLibraryServiceApi.deleteDraft(id);
14781480
} else {
1479-
await cqlLibraryServiceApi.deleteLibrary(id, harpId);
1481+
await cqlLibraryServiceApi.deleteLibrary(id, userName);
14801482
}
14811483

14821484
setToastType("success");
@@ -1500,6 +1502,7 @@ const UserProfile = () => {
15001502
closeDeleteDialog,
15011503
libraryTable,
15021504
harpId,
1505+
getUserName,
15031506
]);
15041507
const handleContinueDialog = useCallback(() => {
15051508
setDownloadState(null);
@@ -1704,11 +1707,12 @@ const UserProfile = () => {
17041707
>
17051708
<LibraryActionCenter
17061709
libraries={selectedLibraries}
1707-
activeTab={activeTab}
1710+
activeTab={activeTab - 2}
17081711
onDelete={openDeleteDialog}
17091712
onShare={handleLibraryShare}
17101713
disabledReason={deleteDisabledReason}
17111714
canDelete={canDelete}
1715+
userName={getUserName()}
17121716
/>
17131717
</div>
17141718
)}

src/components/landing/userManagement/userProfile/actionCenter/LibraryActionCenter.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from "react";
22
import { type CqlLibrary } from "@madie/madie-models";
33

44
import DeleteAction from "./deleteAction/DeleteAction";
5-
import AdminLibraryShareAction from "./LibraryShareAction/LibraryShareAction";
5+
import { LibraryShareAction } from "@madie/madie-util";
66

77
interface PropTypes {
88
libraries: CqlLibrary[];
@@ -12,6 +12,7 @@ interface PropTypes {
1212
onShare?: (option: string) => void;
1313
disabledReason?: string;
1414
target?: string;
15+
userName: string;
1516
}
1617

1718
export default function LibraryActionCenter({
@@ -22,12 +23,18 @@ export default function LibraryActionCenter({
2223
onDelete,
2324
onShare,
2425
disabledReason,
26+
userName,
2527
}: PropTypes) {
2628
return (
2729
<div className="action-center" data-testid="action-center">
28-
<AdminLibraryShareAction
30+
<LibraryShareAction
2931
libraries={libraries}
3032
onClick={onShare}
33+
canEdit={true}
34+
userName={userName}
35+
owners={libraries.map((library) => library.librarySet?.owner)}
36+
// doesn't matter
37+
isSharedWithUser={false}
3138
activeTab={activeTab}
3239
/>
3340
<DeleteAction

0 commit comments

Comments
 (0)