Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1544,10 +1544,50 @@ describe("UnshareFromMe Confirmation Dialog component", () => {
/>
);

expect(screen.getByTestId("share-confirmation-dialog")).toBeInTheDocument();
expect(
await screen.findByTestId("share-confirmation-dialog")
).toBeInTheDocument();
expect(screen.queryByTestId("share-dialog")).toBeNull();
});

it("should unshare the passed unshareFromUser (not the logged-in user) and show the measure name", async () => {
const mockOnSave = jest.fn();
mockMeasureServiceApi.unshareMeasures = mockUnshareMeasures;
render(
<ShareDialog
measures={[mockMeasure1, mockMeasure2]}
open={true}
option="UnshareFromMe"
onClose={jest.fn()}
onSave={mockOnSave}
unshareFromUser="userId1"
/>
);

const dialog = await screen.findByTestId("share-confirmation-dialog");
expect(dialog).toHaveTextContent(mockMeasure1.measureName);
expect(dialog).toHaveTextContent(mockMeasure2.measureName);

// The target user is the passed profile user, not the logged-in "test user".
expect(dialog).toHaveTextContent("userId1");
expect(dialog).not.toHaveTextContent("test user");

await userEvent.click(
await screen.findByTestId("share-confirmation-dialog-accept-button")
);

await waitFor(() => {
expect(mockUnshareMeasures).toHaveBeenCalledWith(expect.any(Map));
});
const requestMap = mockUnshareMeasures.mock.calls[0][0] as Map<
string,
string[]
>;

expect(requestMap.get(mockMeasure1.id)).toEqual(["userId1"]);
expect(requestMap.get(mockMeasure2.id)).toEqual(["userId1"]);
});

it("should close Share dialog and call onClose when option is 'Share With'", async () => {
const onCloseMock = jest.fn();

Expand Down Expand Up @@ -1607,7 +1647,9 @@ describe("UnshareFromMe Confirmation Dialog component", () => {
/>
);

expect(screen.getByTestId("share-confirmation-dialog")).toBeInTheDocument();
expect(
await screen.findByTestId("share-confirmation-dialog")
).toBeInTheDocument();
expect(screen.queryByTestId("share-dialog")).toBeNull();

const cancelButton = screen.getByTestId(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
onClose: Function;
onSave: Function;
isAdmin?: boolean;
// HARP id to unshare from on the "UnshareFromMe" path. Defaults to the
// logged-in user in the Measures workspace while the Admin User Profile passes the
// profile user being viewed.
unshareFromUser?: string;
}

interface SharedMeasure {
Expand Down Expand Up @@ -116,9 +120,13 @@
onClose,
onSave,
isAdmin,
unshareFromUser,
}: ShareDialogProps) => {
const { getUserName } = useOktaTokens();
const userName = getUserName();
// User whose access is removed on the "UnshareFromMe" path: the profile user
// in the Admin User Profile or defaults to the logged-in user if no unshareFromUser provided.
const unshareTargetUser = unshareFromUser ?? userName;

const showShareDialog = option === "Share With" || option === "Unshare";

Expand Down Expand Up @@ -161,7 +169,7 @@
});
};

const updateUnsharedMeasuresRequest = (measureId, harpId) => {

Check warning on line 172 in src/components/measureActions/dialogs/shareDialog/ShareDialog.tsx

View workflow job for this annotation

GitHub Actions / Checkout, install, lint, build and test with coverage (20)

The 'updateUnsharedMeasuresRequest' function makes the dependencies of useCallback Hook (at line 448) change on every render. Move it inside the useCallback callback. Alternatively, wrap the definition of 'updateUnsharedMeasuresRequest' in its own useCallback() Hook

Check warning on line 172 in src/components/measureActions/dialogs/shareDialog/ShareDialog.tsx

View workflow job for this annotation

GitHub Actions / Checkout, install, lint, build and test with coverage (18)

The 'updateUnsharedMeasuresRequest' function makes the dependencies of useCallback Hook (at line 448) change on every render. Move it inside the useCallback callback. Alternatively, wrap the definition of 'updateUnsharedMeasuresRequest' in its own useCallback() Hook

Check warning on line 172 in src/components/measureActions/dialogs/shareDialog/ShareDialog.tsx

View workflow job for this annotation

GitHub Actions / Checkout, install, lint, build and test with coverage (22)

The 'updateUnsharedMeasuresRequest' function makes the dependencies of useCallback Hook (at line 448) change on every render. Move it inside the useCallback callback. Alternatively, wrap the definition of 'updateUnsharedMeasuresRequest' in its own useCallback() Hook
setUnshareMeasuresRequest((map) => {
const current = map.get(measureId) || [];
current.push(harpId);
Expand Down Expand Up @@ -344,7 +352,7 @@
} finally {
setLoading(false);
}
}, [open]);

Check warning on line 355 in src/components/measureActions/dialogs/shareDialog/ShareDialog.tsx

View workflow job for this annotation

GitHub Actions / Checkout, install, lint, build and test with coverage (20)

React Hook useCallback has missing dependencies: 'measureServiceApi', 'measures', and 'table'. Either include them or remove the dependency array

Check warning on line 355 in src/components/measureActions/dialogs/shareDialog/ShareDialog.tsx

View workflow job for this annotation

GitHub Actions / Checkout, install, lint, build and test with coverage (18)

React Hook useCallback has missing dependencies: 'measureServiceApi', 'measures', and 'table'. Either include them or remove the dependency array

Check warning on line 355 in src/components/measureActions/dialogs/shareDialog/ShareDialog.tsx

View workflow job for this annotation

GitHub Actions / Checkout, install, lint, build and test with coverage (22)

React Hook useCallback has missing dependencies: 'measureServiceApi', 'measures', and 'table'. Either include them or remove the dependency array

// Resets state and closes the Share/Unshare dialog
const handleShareDialogClose = () => {
Expand Down Expand Up @@ -593,7 +601,7 @@
];

return columnDefs;
}, [measures, option]);

Check warning on line 604 in src/components/measureActions/dialogs/shareDialog/ShareDialog.tsx

View workflow job for this annotation

GitHub Actions / Checkout, install, lint, build and test with coverage (20)

React Hook useMemo has an unnecessary dependency: 'measures'. Either exclude it or remove the dependency array

Check warning on line 604 in src/components/measureActions/dialogs/shareDialog/ShareDialog.tsx

View workflow job for this annotation

GitHub Actions / Checkout, install, lint, build and test with coverage (18)

React Hook useMemo has an unnecessary dependency: 'measures'. Either exclude it or remove the dependency array

Check warning on line 604 in src/components/measureActions/dialogs/shareDialog/ShareDialog.tsx

View workflow job for this annotation

GitHub Actions / Checkout, install, lint, build and test with coverage (22)

React Hook useMemo has an unnecessary dependency: 'measures'. Either exclude it or remove the dependency array

const table = useReactTable({
data: sharedMeasures,
Expand Down Expand Up @@ -623,22 +631,22 @@

useEffect(() => {
onRowSelectionChange();
}, [rowSelection]);

Check warning on line 634 in src/components/measureActions/dialogs/shareDialog/ShareDialog.tsx

View workflow job for this annotation

GitHub Actions / Checkout, install, lint, build and test with coverage (20)

React Hook useEffect has a missing dependency: 'onRowSelectionChange'. Either include it or remove the dependency array

Check warning on line 634 in src/components/measureActions/dialogs/shareDialog/ShareDialog.tsx

View workflow job for this annotation

GitHub Actions / Checkout, install, lint, build and test with coverage (18)

React Hook useEffect has a missing dependency: 'onRowSelectionChange'. Either include it or remove the dependency array

Check warning on line 634 in src/components/measureActions/dialogs/shareDialog/ShareDialog.tsx

View workflow job for this annotation

GitHub Actions / Checkout, install, lint, build and test with coverage (22)

React Hook useEffect has a missing dependency: 'onRowSelectionChange'. Either include it or remove the dependency array

useEffect(() => {
// Only trigger when dialog is open and the option is UnshareFromMe
if (option === "UnshareFromMe" && open) {
// Prepare the unshare request
// Only trigger once the dialog is open, the option is UnshareFromMe, and the
// shared measures have loaded.
if (option === "UnshareFromMe" && open && sharedMeasures.length) {
const directUnshareRequest = new Map<string, string[]>();
measures.forEach((measure) => {
directUnshareRequest.set(measure.id, [userName]);
sharedMeasures.forEach((sharedMeasure) => {
directUnshareRequest.set(sharedMeasure.measureId, [unshareTargetUser]);
});
setUnshareMeasuresRequest(directUnshareRequest);

// Open the confirmation dialog
setConfirmationDialogOpen(true);
}
}, [option, open, measures, userName]);
}, [option, open, sharedMeasures, unshareTargetUser]);

// export user list in Excel format for admin users
const handleExportUserList = async (e) => {
Expand Down
Loading