Skip to content

Commit

Permalink
wip: fix dynamic display of community vcs in vcs block
Browse files Browse the repository at this point in the history
  • Loading branch information
reactoholic committed Feb 3, 2025
1 parent f56ce02 commit b662dc1
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/domain/access/RoleSetAdmin/useRoleSetAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const useRoleSetAdmin = ({
}
}

// @@@ WIP ~ #7539 - Трябва да рифечваш това тук, за да се показуват ВиСи-тата в "http://localhost:3000/spacejoin/community"
const {
data: roleSetData,
loading: loadingRoleSetData,
Expand All @@ -130,7 +131,6 @@ const useRoleSetAdmin = ({
includeVirtualContributors: contributorTypes.includes(RoleSetContributorType.Virtual),
},
skip: skip || !canReadRoleSet || !roleSetId || loadingRoleSet || !relevantRoles || relevantRoles.length === 0,
fetchPolicy: 'network-only',
});

const data = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import {
useDeleteInnovationHubMutation,
useDeleteInnovationPackMutation,
useDeleteSpaceMutation,
useRoleSetRoleAssignmentQuery,
useDeleteVirtualContributorOnAccountMutation,
} from '@/core/apollo/generated/apollo-hooks';
import {
AuthorizationPrivilege,
LicenseEntitlement,
LicenseEntitlementType,
RoleName,
RoleSetContributorType,
SpaceLevel,
SpaceVisibility,
} from '@/core/apollo/generated/graphql-schema';
Expand Down Expand Up @@ -46,6 +49,11 @@ const enum Entities {
InnovationHub = 'InnovationHub',
}

const contributorTypes = [
RoleSetContributorType.User,
RoleSetContributorType.Virtual,
RoleSetContributorType.Organization,
];
const SHORT_NON_SPACE_DESCRIPTION = 'components.deleteEntity.confirmDialog.descriptionShort';

interface AccountProfile {
Expand Down Expand Up @@ -148,12 +156,13 @@ export const ContributorAccountView = ({ accountHostName, account, loading }: Co

const { virtualContributors, innovationPacks, innovationHubs } = useMemo(
() => ({
virtualContributors: account?.virtualContributors ?? [],
virtualContributors: account?.virtualContributors ?? [], // @@@ WIP ~ #7539
innovationPacks: account?.innovationPacks ?? [],
innovationHubs: account?.innovationHubs ?? [],
}),
[account]
);
console.log('@@@ ACCOUNT.VCs >>>', virtualContributors);

const privileges = account?.authorization?.myPrivileges ?? [];

Expand Down Expand Up @@ -232,6 +241,20 @@ export const ContributorAccountView = ({ accountHostName, account, loading }: Co
refetchQueries: ['AccountInformation'],
});

// @@@ WIP ~ #7539 - ЗА ДА РИФЕЧНА COMMUNITY VC-ТАТА ДИНАМИЧНО ТРЯБВА ДА ЗНАМ КЪМ КОЙ SPACE Е ДАДЕНОТО VC, ЗАЩОТО
// ROLE–SET_ID-ТО СЕ ВЗИМА ОТ СПЕЙСА, А НЯМАМ ДОСТЪП ДО СПЕЙСА ОТ ТУК!!!!!!!!!!!!
const { refetch: refetchRoleSetData } = useRoleSetRoleAssignmentQuery({
variables: {
roleSetId: 'ROLE_SET_ID', // @@@ TEST
roles: [RoleName.Member, RoleName.Lead],
includeUsers: contributorTypes.includes(RoleSetContributorType.User),
includeOrganizations: contributorTypes.includes(RoleSetContributorType.Organization),
includeVirtualContributors: contributorTypes.includes(RoleSetContributorType.Virtual),
},
// skip: !roleSetId,
});

// @@@ WIP ~ #7539
const deleteVC = () => {
if (!selectedId) {
return;
Expand All @@ -243,6 +266,9 @@ export const ContributorAccountView = ({ accountHostName, account, loading }: Co
ID: selectedId,
},
},
onCompleted: () => {
refetchRoleSetData(); // @@@ WIP ~ #7539
},
});
};

Expand Down Expand Up @@ -317,7 +343,7 @@ export const ContributorAccountView = ({ accountHostName, account, loading }: Co
case Entities.Space:
return deleteSpace();
case Entities.VirtualContributor:
return deleteVC();
return deleteVC(); // @@@ WIP ~ #7539 - Този метод трие VC
case Entities.InnovationPack:
return deletePack();
case Entities.InnovationHub:
Expand Down Expand Up @@ -555,7 +581,7 @@ export const ContributorAccountView = ({ accountHostName, account, loading }: Co
entity={getEntityName(entity)}
open={deleteDialogOpen}
onClose={clearDeleteState}
onDelete={deleteEntity}
onDelete={deleteEntity} // @@@ WIP ~ #7539 - Този метод трие VC
description={entity === Entities.Space ? undefined : SHORT_NON_SPACE_DESCRIPTION}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const UserAdminAccountPage = () => {
},
skip: !userData?.lookup.user?.account?.id,
});
console.log('<UserAdminAccountPage /> ACCOUNT_DATA >>>', accountData);

return (
<UserAdminLayout currentTab={SettingsSection.Account}>
Expand Down
1 change: 1 addition & 0 deletions src/domain/journey/space/SpaceContext/SpaceContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ const SpaceContextProvider: FC<SpaceProviderProps> = ({ children }) => {
const collaborationId = space?.collaboration?.id ?? '';
const calloutsSetId = space?.collaboration?.calloutsSet?.id ?? '';
const roleSetId = space?.community?.roleSet?.id ?? '';
console.log('@@@ roleSetId >>>', roleSetId);
const isPrivate = space && space.settings.privacy?.mode === SpacePrivacyMode.Private;

const contextPrivileges = space?.context?.authorization?.myPrivileges ?? NO_PRIVILEGES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,22 @@ const EntityConfirmDeleteDialog: FC<EntityConfirmDeleteDialogProps> = ({
setChecked(false);
onClose();
};

const [handleDelete, loading] = useLoadingState(async () => {
await onDelete();
setChecked(false);
});

return (
<Dialog open={open} onClose={handleClose}>
<DialogHeader
onClose={handleClose}
title={t('components.deleteEntity.confirmDialog.title', { entity: entity })}
/>
<DialogHeader onClose={handleClose} title={t('components.deleteEntity.confirmDialog.title', { entity })} />
<DialogContent>
<Gutters disablePadding>
<Box sx={{ wordWrap: 'break-word' }}>
<Caption>
{t(description ?? 'components.deleteEntity.confirmDialog.description', { entity: entity })}{' '}
</Caption>
<Caption>{t(description ?? 'components.deleteEntity.confirmDialog.description', { entity })} </Caption>
<FormControlLabel
control={<Checkbox checked={checked} onChange={() => setChecked(!checked)} />}
label={<Caption>{t('components.deleteEntity.confirmDialog.checkbox', { entity: entity })}</Caption>}
label={<Caption>{t('components.deleteEntity.confirmDialog.checkbox', { entity })}</Caption>}
/>
<Actions justifyContent="flex-end" paddingTop={gutters()}>
<Button onClick={handleClose}>{t('buttons.cancel')}</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const ChooseCommunity = ({ onClose, onSubmit, vcName = '', spaces, loading }: Ch
setConfirmDialogOpen(false);
};

// @@@ WIP ~ #7539
const listItems = useMemo(() => {
const result: SelectableKnowledgeSpace[] = [];
const addSelectableSpace = (space: SelectableSpace) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
useAllSpaceSubspacesLazyQuery,
refetchMyResourcesQuery,
useRefreshBodyOfKnowledgeMutation,
useRoleSetRoleAssignmentQuery,
} from '@/core/apollo/generated/apollo-hooks';
import {
AiPersonaBodyOfKnowledgeType,
Expand All @@ -19,6 +20,7 @@ import {
CreateCalloutInput,
CreateVirtualContributorOnAccountMutationVariables,
LicensingCredentialBasedPlanType,
RoleSetContributorType,
} from '@/core/apollo/generated/graphql-schema';
import CreateNewVirtualContributor, { VirtualContributorFromProps } from './CreateNewVirtualContributor';
import LoadingState from './LoadingState';
Expand Down Expand Up @@ -74,6 +76,12 @@ export type SelectableSpace = {
subspaces?: SelectableSpace[];
};

const contributorTypes = [
RoleSetContributorType.User,
RoleSetContributorType.Organization,
RoleSetContributorType.Virtual,
];

const useVirtualContributorWizard = (): useVirtualContributorWizardProvided => {
const { t } = useTranslation();
const { user } = useUserContext();
Expand All @@ -82,6 +90,7 @@ const useVirtualContributorWizard = (): useVirtualContributorWizardProvided => {

const [dialogOpen, setDialogOpen] = useState(false);
const [step, setStep] = useState<Step>(steps.initial);
const [selectedRoleSetId, setSelectedRoleSetId] = useState<string>();

const [targetAccount, setTargetAccount] = useState<UserAccountProps>();
const [accountName, setAccountName] = useState<string>();
Expand All @@ -91,6 +100,18 @@ const useVirtualContributorWizard = (): useVirtualContributorWizardProvided => {
const [availableExistingSpaces, setAvailableExistingSpaces] = useState<SelectableSpace[]>([]);
const [availableExistingSpacesLoading, setAvailableExistingSpacesLoading] = useState(false);

// @@@ WIP ~ #7539
const { refetch: refetchRoleSetData } = useRoleSetRoleAssignmentQuery({
variables: {
roleSetId: selectedRoleSetId!, // `skip: !selectedRoleSetId` ensures selectedRoleSetId's presence.
roles: [RoleName.Member, RoleName.Lead],
includeUsers: contributorTypes.includes(RoleSetContributorType.User),
includeOrganizations: contributorTypes.includes(RoleSetContributorType.Organization),
includeVirtualContributors: contributorTypes.includes(RoleSetContributorType.Virtual),
},
skip: !selectedRoleSetId,
});

const startWizard = (initAccount: UserAccountProps | undefined, accountName?: string) => {
setTargetAccount(initAccount);
setAccountName(accountName);
Expand Down Expand Up @@ -461,6 +482,8 @@ const useVirtualContributorWizard = (): useVirtualContributorWizardProvided => {

// ###STEP 'chooseCommunityStep' - Choose Community
const onChooseCommunity = async (selectedSpace: SelectableKnowledgeSpace) => {
setSelectedRoleSetId(selectedSpace?.roleSetId);

let spaceId: string | undefined = selectedSpace?.id;
if (!createdVc) {
return;
Expand All @@ -478,6 +501,8 @@ const useVirtualContributorWizard = (): useVirtualContributorWizardProvided => {
if (addToCommunity) {
addVCCreationCache(createdVc.id);
await navigateToTryYourVC(undefined, spaceId);

refetchRoleSetData(); // Re-fetch in order to display community VC dynamically
} else {
notifyErrorOnAddToCommunity();
handleCloseWizard();
Expand Down

0 comments on commit b662dc1

Please sign in to comment.