Skip to content

Commit aed1bc5

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

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(
@@ -2664,91 +2669,7 @@ describe("UserProfile", () => {
26642669
});
26652670
});
26662671

2667-
describe("library share actions", () => {
2668-
it("opens LibraryShareDialog when Share With is selected for a library", async () => {
2669-
mockAdminSearchMeasures.mockResolvedValue(pageWith([ownedMeasure], 1));
2670-
mockFetchCqlLibraries.mockResolvedValue(pageWith([ownedLibrary], 1));
2671-
2672-
renderAt("/admin/userProfile/test_user");
2673-
2674-
await userEvent.click(await screen.findByTestId("owned-libraries-tab"));
2675-
2676-
await userEvent.click(await screen.findByTestId("checkbox-lib1"));
2677-
2678-
await userEvent.click(await screen.findByTestId("share-action-btn"));
2679-
2680-
await userEvent.click(await screen.findByTestId("Share With-option"));
2681-
2682-
expect(
2683-
await screen.findByTestId("library-share-dialog")
2684-
).toBeInTheDocument();
2685-
2686-
expect(screen.getByTestId("library-share-dialog")).toHaveAttribute(
2687-
"data-option",
2688-
"Share With"
2689-
);
2690-
});
2691-
it("handles successful library share dialog close and displays success toast", async () => {
2692-
mockAdminSearchMeasures.mockResolvedValue(pageWith([ownedMeasure], 1));
2693-
mockFetchCqlLibraries.mockResolvedValue(pageWith([ownedLibrary], 1));
2694-
2695-
renderAt("/admin/userProfile/test_user");
2696-
2697-
await userEvent.click(await screen.findByTestId("owned-libraries-tab"));
2698-
2699-
await userEvent.click(await screen.findByTestId("checkbox-lib1"));
2700-
2701-
await userEvent.click(await screen.findByTestId("share-action-btn"));
2702-
2703-
await userEvent.click(await screen.findByTestId("Share With-option"));
2704-
2705-
const callsBefore = mockFetchCqlLibraries.mock.calls.length;
2706-
2707-
await userEvent.click(
2708-
await screen.findByTestId("library-share-success-btn")
2709-
);
2710-
2711-
expect(
2712-
screen.queryByTestId("library-share-dialog")
2713-
).not.toBeInTheDocument();
2714-
2715-
expect(
2716-
await screen.findByText("Library Successfully Shared")
2717-
).toBeInTheDocument();
2718-
2719-
await waitFor(() => {
2720-
expect(mockFetchCqlLibraries.mock.calls.length).toBeGreaterThan(
2721-
callsBefore
2722-
);
2723-
});
2724-
});
2725-
it("handles library share dialog close with a non-success message", async () => {
2726-
mockAdminSearchMeasures.mockResolvedValue(pageWith([ownedMeasure], 1));
2727-
mockFetchCqlLibraries.mockResolvedValue(pageWith([ownedLibrary], 1));
2728-
2729-
renderAt("/admin/userProfile/test_user");
2730-
2731-
await userEvent.click(await screen.findByTestId("owned-libraries-tab"));
2732-
2733-
await userEvent.click(await screen.findByTestId("checkbox-lib1"));
2734-
2735-
await userEvent.click(await screen.findByTestId("share-action-btn"));
2736-
2737-
await userEvent.click(await screen.findByTestId("Share With-option"));
2738-
2739-
await userEvent.click(
2740-
await screen.findByTestId("library-share-danger-btn")
2741-
);
2742-
2743-
expect(
2744-
screen.queryByTestId("library-share-dialog")
2745-
).not.toBeInTheDocument();
2746-
2747-
expect(
2748-
await screen.findByText("Unable to share library")
2749-
).toBeInTheDocument();
2750-
});
2751-
});
2672+
describe("library share actions", () => {});
27522673

27532674
describe("transfer action", () => {
27542675
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 =
@@ -326,6 +327,8 @@ const MeasureStatusChips = ({ measure }: { measure: any }) => (
326327

327328
const UserProfile = () => {
328329
const { harpId } = useParams<{ harpId: string }>() as { harpId: string };
330+
const { getUserName } = useOktaTokens();
331+
const userName = getUserName();
329332
const userServiceApi = useRef(useUserServiceApi()).current;
330333
const measureServiceApi = useRef(useMeasureServiceApi()).current;
331334
const cqlLibraryServiceApi = useRef(useCqlLibraryServiceApi()).current;
@@ -424,7 +427,6 @@ const UserProfile = () => {
424427
setExpandedLibraryRows([]);
425428
setSelectedExpandedLibraryRowIds([]);
426429
}, []);
427-
428430
useEffect(() => {
429431
const controller = new AbortController();
430432
userServiceApi
@@ -1477,7 +1479,7 @@ const UserProfile = () => {
14771479
if (draft) {
14781480
await cqlLibraryServiceApi.deleteDraft(id);
14791481
} else {
1480-
await cqlLibraryServiceApi.deleteLibrary(id, harpId);
1482+
await cqlLibraryServiceApi.deleteLibrary(id, userName);
14811483
}
14821484

14831485
setToastType("success");
@@ -1501,6 +1503,7 @@ const UserProfile = () => {
15011503
closeDeleteDialog,
15021504
libraryTable,
15031505
harpId,
1506+
getUserName,
15041507
]);
15051508
const handleContinueDialog = useCallback(() => {
15061509
setDownloadState(null);
@@ -1705,11 +1708,12 @@ const UserProfile = () => {
17051708
>
17061709
<LibraryActionCenter
17071710
libraries={selectedLibraries}
1708-
activeTab={activeTab}
1711+
activeTab={activeTab - 2}
17091712
onDelete={openDeleteDialog}
17101713
onShare={handleLibraryShare}
17111714
disabledReason={deleteDisabledReason}
17121715
canDelete={canDelete}
1716+
userName={getUserName()}
17131717
/>
17141718
</div>
17151719
)}

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)