Skip to content

Commit 09d3dcd

Browse files
author
Michael Buchar
committed
fix(workflow-list): show shared workflows for brand new users (#429)
Closes #413
1 parent 093f532 commit 09d3dcd

File tree

2 files changed

+44
-9
lines changed

2 files changed

+44
-9
lines changed

reana-ui/src/pages/workflowList/WorkflowList.js

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { useDispatch, useSelector } from "react-redux";
1515
import { Container, Dimmer, Dropdown, Icon, Loader } from "semantic-ui-react";
1616
import isEqual from "lodash/isEqual";
1717

18-
import { fetchWorkflows } from "~/actions";
18+
import { fetchUsersSharedWithYou, fetchWorkflows } from "~/actions";
1919
import {
2020
getConfig,
2121
getReanaToken,
@@ -25,6 +25,7 @@ import {
2525
loadingWorkflows,
2626
userHasWorkflows,
2727
getWorkflowRefresh,
28+
getUsersSharedWithYou,
2829
} from "~/selectors";
2930
import { NON_DELETED_STATUSES } from "~/config";
3031
import { Title, Pagination, Search } from "~/components";
@@ -58,6 +59,7 @@ function Workflows() {
5859
const workflows = useSelector(getWorkflows);
5960
const workflowsCount = useSelector(getWorkflowsCount);
6061
const hasUserWorkflows = useSelector(userHasWorkflows);
62+
const usersSharedWithYou = useSelector(getUsersSharedWithYou);
6163
const workflowRefresh = useSelector(getWorkflowRefresh);
6264
const loading = useSelector(loadingWorkflows);
6365
const reanaToken = useSelector(getReanaToken);
@@ -82,17 +84,27 @@ function Workflows() {
8284
const [committedSearch, setCommittedSearch] = useState(initialSearch);
8385

8486
// Owned by derived from URL
85-
const ownedByFilter = useMemo(
86-
() => (searchParams.get("shared") === "true" ? "anybody" : "you"),
87-
[searchParams],
88-
);
87+
const ownedByFilter = useMemo(() => {
88+
const sharedBy = searchParams.get("shared-by");
89+
if (sharedBy) {
90+
// Explicit owner selected, e.g. [email protected]
91+
return sharedBy;
92+
}
93+
// Fallback to "you" vs "anybody" based on `shared`
94+
return searchParams.get("shared") === "true" ? "anybody" : "you";
95+
}, [searchParams]);
8996

9097
// Shared with flag from URL
9198
const sharedWithMode = useMemo(
9299
() => searchParams.get("shared-with") === "true",
93100
[searchParams],
94101
);
95102

103+
// Load information about users who have shared workflows with you
104+
useEffect(() => {
105+
dispatch(fetchUsersSharedWithYou());
106+
}, [dispatch]);
107+
96108
const [sharedWithFilter, setSharedWithFilter] = useState(() =>
97109
searchParams.get("shared-with") === "true" ? "anybody" : undefined,
98110
);
@@ -177,8 +189,19 @@ function Workflows() {
177189
(prev) => {
178190
const qp = new URLSearchParams(prev);
179191
qp.delete("shared-with"); // ensure shared-with mode is off
180-
if (next === "anybody") qp.set("shared", "true");
181-
else qp.delete("shared"); // default is "you"
192+
if (next === "anybody") {
193+
// Show anybody's workflows
194+
qp.set("shared", "true");
195+
qp.delete("shared-by");
196+
} else if (!next || next === "you") {
197+
// Back to "you": default view
198+
qp.delete("shared");
199+
qp.delete("shared-by");
200+
} else {
201+
// Specific owner selected, e.g. [email protected]
202+
qp.delete("shared");
203+
qp.set("shared-by", next);
204+
}
182205
qp.delete("page");
183206
return qp;
184207
},
@@ -192,6 +215,7 @@ function Workflows() {
192215
if (on) {
193216
qp.set("shared-with", "true");
194217
qp.delete("shared");
218+
qp.delete("shared-by");
195219
} else {
196220
qp.delete("shared-with");
197221
}
@@ -266,12 +290,19 @@ function Workflows() {
266290
// owned-by vs shared-with
267291
const inSharedWith = sharedWithMode;
268292

293+
// owned-by -> shared / shared_by mapping:
294+
// - owned_by=you -> shared=false, shared_by undefined
295+
// - owned_by=anybody -> shared=true, shared_by=null
296+
// - owned_by=<user@email> -> shared=false, shared_by=<user@email>
269297
let shared, sharedBy;
270298
if (!inSharedWith) {
271299
if (ownedByFilter === "anybody") {
272300
shared = true;
273301
sharedBy = null;
274-
} else if (ownedByFilter && ownedByFilter !== "you") {
302+
} else if (!ownedByFilter || ownedByFilter === "you") {
303+
shared = false;
304+
} else {
305+
shared = false;
275306
sharedBy = ownedByFilter;
276307
}
277308
}
@@ -387,7 +418,9 @@ function Workflows() {
387418
);
388419
}
389420

390-
if (!hasUserWorkflows) return <Welcome />;
421+
if (!hasUserWorkflows && usersSharedWithYou.length === 0) {
422+
return <Welcome />;
423+
}
391424

392425
// Flatten workflows object to array for rendering
393426
const workflowArray = Object.values(workflows || {});

reana-ui/src/pages/workflowList/components/WorkflowSharingFilter.module.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
> div[aria-atomic="true"] {
2222
max-width: 100%;
2323
white-space: nowrap;
24+
overflow: hidden;
2425
text-overflow: ellipsis;
26+
line-height: 1.2em; /* slightly taller line to prevent clipping of "y" */
2527
}
2628
}

0 commit comments

Comments
 (0)