Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(FR-242): show vfolder list based on delegated user #3070

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
20 changes: 19 additions & 1 deletion react/src/components/VFolderTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,34 @@ const VFolderTable: React.FC<VFolderTableProps> = ({
}
}, [aliasMap, internalForm, aliasBasePath]);

const formInstance = Form.useFormInstance();
const ownerInfo = formInstance.getFieldValue(['owner']);
// valid when owner is enabled and all fields are not undefined
const isValidOwner =
ownerInfo?.enabled &&
(!_.isEmpty(ownerInfo)
? _.every(_.omit(ownerInfo, 'enabled'), (key, value) => {
return key !== undefined;
})
: false);
const ownerEmail = isValidOwner ? ownerInfo.email : undefined;

useEffect(() => {
formInstance.setFieldsValue({ mounts: undefined, vfolderAliasMap: {} });
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isValidOwner]);

Comment on lines +148 to +164
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VFolderTable is not a Form.Item component. Therefore, it can be used outside of a Form. If you want to impose a condition based on a specific user's email, VFolderTable should receive the email as a prop. The email condition is an input of this Component.

const { t } = useTranslation();
const baiRequestWithPromise = useBaiSignedRequestWithPromise();
const currentProject = useCurrentProjectValue();
const [fetchKey, updateFetchKey] = useUpdatableState('first');
const [isPendingRefetch, startRefetchTransition] = useTransition();
const { data: allFolderList } = useSuspenseTanQuery({
queryKey: ['VFolderSelectQuery', fetchKey, currentProject.id],
queryKey: ['VFolderSelectQuery', fetchKey, currentProject.id, ownerEmail],
queryFn: () => {
const search = new URLSearchParams();
search.set('group_id', currentProject.id);
ownerEmail && search.set('owner_user_email', ownerEmail);
return baiRequestWithPromise({
method: 'GET',
url: `/folders?${search.toString()}`,
Expand Down
Loading