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

feat(chat): Add the application shared with the user to a "My workspace" (Issue 2955) #2961

Draft
wants to merge 4 commits into
base: development
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion apps/chat/src/components/Marketplace/ApplicationCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export const ApplicationCard = ({
triggerIconSize={18}
className="m-0 xl:invisible group-hover:xl:visible"
/>
{!isMyApp && (
{!isMyApp && !entity.sharedWithMe && (
<Tooltip
tooltip={
installedModelIds.has(entity.reference)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,35 +200,36 @@ export const ApplicationDetailsFooter = ({
</button>
</Tooltip>
)}
{isMyApp ? (
<Tooltip tooltip={t(getDisabledTooltip(entity, 'Delete'))}>
<button
disabled={isModifyDisabled}
onClick={() => onDelete(entity)}
className="icon-button"
data-qa="application-delete"
>
<IconTrashX size={24} />
</button>
</Tooltip>
) : (
<Tooltip
tooltip={
installedModelIds.has(entity.reference)
? t('Remove from My workspace')
: t('Add to My workspace')
}
isTriggerClickable
>
<button
onClick={() => onBookmarkClick(entity)}
className="icon-button"
data-qa="application-bookmark"
{!entity.sharedWithMe &&
(isMyApp ? (
<Tooltip tooltip={t(getDisabledTooltip(entity, 'Delete'))}>
<button
disabled={isModifyDisabled}
onClick={() => onDelete(entity)}
className="icon-button"
data-qa="application-delete"
>
<IconTrashX size={24} />
</button>
</Tooltip>
) : (
<Tooltip
tooltip={
installedModelIds.has(entity.reference)
? t('Remove from My workspace')
: t('Add to My workspace')
}
isTriggerClickable
>
<Bookmark size={24} />
</button>
</Tooltip>
)}
<button
onClick={() => onBookmarkClick(entity)}
className="icon-button"
data-qa="application-bookmark"
>
<Bookmark size={24} />
</button>
</Tooltip>
))}

{isApplicationId(entity.id) && (isMyApp || isPublicApp) && (
<Tooltip tooltip={isPublicApp ? t('Unpublish') : t('Publish')}>
Expand Down
9 changes: 5 additions & 4 deletions apps/chat/src/store/models/models.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,11 @@ const getInstalledModelIdsEpic: AppEpic = (action$, state$) =>
const allModels = ModelsSelectors.selectModels(state$.value);

return allModels
.filter((model) =>
model.id.startsWith(
getRootId({ featureType: FeatureType.Application }),
),
.filter(
(model) =>
model.id.startsWith(
getRootId({ featureType: FeatureType.Application }),
) || model.sharedWithMe,
)
.map((app) => app.reference);
}),
Expand Down
57 changes: 37 additions & 20 deletions apps/chat/src/store/share/share.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,30 +899,47 @@ const getSharedListingSuccessEpic: AppEpic = (action$, state$) =>
} else {
//TODO make request for the shared applications to add them into the state when share invitation is accepted.
//TODO new action-service needs to be created.
//TODO add all shared with me agents to installedModels

// const sharedReferences: string[] = []; //part of TODO uncomment or remove if not needed;
const updateSharedActions = payload.resources.entities
.map((sharedItem) => {
const sharedModel = modelsMap[sharedItem.id];

actions.push(
...(payload.resources.entities
.map((sharedItem) => {
const sharedModel = modelsMap[sharedItem.id];
if (sharedModel) {
return ModelsActions.updateLocalModels({
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's not good to dispatch a lot of similar actions.
It's better to collect array of { reference, updatedValues } and dispatch one action updateLocalModels for this collection/array instead

reference: sharedModel.reference,
updatedValues: {
sharedWithMe: true,
permissions: sharedItem.permissions,
},
});
}
return undefined;
})
.filter(Boolean) as AnyAction[];

if (updateSharedActions.length) {
updateSharedActions.push(ModelsActions.getInstalledModelIds());

const { acceptedId } = ShareSelectors.selectAcceptedEntityInfo(
state$.value,
);

if (sharedModel) {
// sharedReferences.push(sharedModel.reference); //part of TODO uncomment or remove if not needed;
const acceptedApplicationReference =
acceptedId && modelsMap[acceptedId]?.reference;

return ModelsActions.updateLocalModels({
reference: sharedModel.reference,
updatedValues: {
sharedWithMe: true,
permissions: sharedItem.permissions,
},
});
}
return undefined;
})
.filter(Boolean) as AnyAction[]),
);
if (acceptedApplicationReference) {
updateSharedActions.push(
MarketplaceActions.setDetailsModel({
reference: acceptedApplicationReference,
isSuggested: false,
}),
);
}

actions.push(...updateSharedActions);
}

actions.push(ShareActions.resetAcceptedEntityInfo());
}
}

Expand Down
Loading