Skip to content

Commit

Permalink
fix(chat): fix custom apps edit (Issue #2665) (#2673)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Kezik authored Nov 27, 2024
1 parent 55ec50e commit bcbcb6f
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface Props {
onBookmarkClick: (entity: DialAIEntityModel) => void;
}

const ApplicationDetails = ({
export const ApplicationDetails = ({
entity,
isMobileView,
allEntities,
Expand Down Expand Up @@ -96,5 +96,3 @@ const ApplicationDetails = ({
</Modal>
);
};

export default ApplicationDetails;
50 changes: 30 additions & 20 deletions apps/chat/src/components/Marketplace/TabRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import { Translation } from '@/src/types/translation';

import { ApplicationActions } from '@/src/store/application/application.reducers';
import { useAppDispatch, useAppSelector } from '@/src/store/hooks';
import { MarketplaceSelectors } from '@/src/store/marketplace/marketplace.reducers';
import {
MarketplaceActions,
MarketplaceSelectors,
} from '@/src/store/marketplace/marketplace.reducers';
import {
ModelsActions,
ModelsSelectors,
Expand All @@ -36,7 +39,7 @@ import {
import { PublishModal } from '@/src/components/Chat/Publish/PublishWizard';
import { ApplicationWizard } from '@/src/components/Common/ApplicationWizard/ApplicationWizard';
import { ConfirmDialog } from '@/src/components/Common/ConfirmDialog';
import ApplicationDetails from '@/src/components/Marketplace/ApplicationDetails/ApplicationDetails';
import { ApplicationDetails } from '@/src/components/Marketplace/ApplicationDetails/ApplicationDetails';
import { CardsList } from '@/src/components/Marketplace/CardsList';
import { MarketplaceBanner } from '@/src/components/Marketplace/MarketplaceBanner';
import { SearchHeader } from '@/src/components/Marketplace/SearchHeader';
Expand Down Expand Up @@ -223,6 +226,8 @@ export const TabRenderer = ({ screenState }: TabRendererProps) => {
MarketplaceSelectors.selectTrimmedSearchTerm,
);
const allModels = useAppSelector(ModelsSelectors.selectModels);
const detailsModel = useAppSelector(MarketplaceSelectors.selectDetailsModel);
const modelsMap = useAppSelector(ModelsSelectors.selectModelsMap);

const [suggestedResults, setSuggestedResults] = useState<DialAIEntityModel[]>(
[],
Expand All @@ -240,10 +245,6 @@ export const TabRenderer = ({ screenState }: TabRendererProps) => {
entity: ShareEntity & { iconUrl?: string };
action: PublishActions;
}>();
const [detailsModel, setDetailsModel] = useState<{
entity: DialAIEntityModel;
isSuggested?: boolean;
}>();

const isSomeFilterNotEmpty =
searchTerm.length ||
Expand Down Expand Up @@ -343,7 +344,7 @@ export const TabRenderer = ({ screenState }: TabRendererProps) => {
dispatch(ApplicationActions.delete(deleteModel.entity));
}

setDetailsModel(undefined);
dispatch(MarketplaceActions.setDetailsModel(undefined));
}

setDeleteModel(undefined);
Expand Down Expand Up @@ -375,22 +376,29 @@ export const TabRenderer = ({ screenState }: TabRendererProps) => {
);

const handleSetDetailsModel = useCallback(
(entity: DialAIEntityModel, isSuggested?: boolean) => {
setDetailsModel({
entity,
isSuggested: !!isSuggested,
});
(model: DialAIEntityModel, isSuggested?: boolean) => {
dispatch(
MarketplaceActions.setDetailsModel({
reference: model.reference,
isSuggested: !!isSuggested,
}),
);
},
[setDetailsModel],
[dispatch],
);

const handleSetVersion = useCallback(
(entity: DialAIEntityModel) => {
(model: DialAIEntityModel) => {
if (detailsModel) {
setDetailsModel({ ...detailsModel, entity });
dispatch(
MarketplaceActions.setDetailsModel({
...detailsModel,
reference: model.reference,
}),
);
}
},
[setDetailsModel, detailsModel],
[detailsModel, dispatch],
);

const handleCloseApplicationDialog = useCallback(
Expand All @@ -399,8 +407,8 @@ export const TabRenderer = ({ screenState }: TabRendererProps) => {
);

const handleCloseDetailsDialog = useCallback(
() => setDetailsModel(undefined),
[setDetailsModel],
() => dispatch(MarketplaceActions.setDetailsModel(undefined)),
[dispatch],
);

const handleBookmarkClick = useCallback(
Expand All @@ -419,6 +427,8 @@ export const TabRenderer = ({ screenState }: TabRendererProps) => {
[dispatch, installedModelIds],
);

const currentDetailsModel = detailsModel && modelsMap[detailsModel.reference];

return (
<>
<header className="mb-5 md:mb-4 xl:mb-6" data-qa="marketplace-header">
Expand Down Expand Up @@ -460,11 +470,11 @@ export const TabRenderer = ({ screenState }: TabRendererProps) => {
cancelLabel={t('Cancel')}
/>
)}
{detailsModel && (
{currentDetailsModel && (
<ApplicationDetails
onPublish={handleSetPublishEntity}
isMobileView={screenState === ScreenState.MOBILE}
entity={detailsModel.entity}
entity={currentDetailsModel}
onChangeVersion={handleSetVersion}
onClose={handleCloseDetailsDialog}
onDelete={handleDelete}
Expand Down
6 changes: 3 additions & 3 deletions apps/chat/src/store/application/application.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ const updateApplicationEpic: AppEpic = (action$) =>
overwrite: false,
})
.pipe(
switchMap(() =>
of(ApplicationActions.edit(updatedCustomApplication)),
),
switchMap(() => {
return of(ApplicationActions.edit(updatedCustomApplication));
}),
catchError((err) => {
console.error('Failed to update application:', err);
return of(
Expand Down
11 changes: 10 additions & 1 deletion apps/chat/src/store/marketplace/marketplace.reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export interface MarketplaceState {
};
searchTerm: string;
selectedTab: MarketplaceTabs;

applyModelStatus: UploadStatus;
detailsModel: { reference: string; isSuggested: boolean } | undefined;
}

const DEFAULT_FILTERS = {
Expand All @@ -34,6 +34,7 @@ const initialState: MarketplaceState = {
searchTerm: '',
selectedTab: MarketplaceTabs.HOME,
applyModelStatus: UploadStatus.UNINITIALIZED,
detailsModel: undefined,
};

export const marketplaceSlice = createSlice({
Expand Down Expand Up @@ -62,6 +63,14 @@ export const marketplaceSlice = createSlice({
setApplyModelStatus: (state, { payload }: PayloadAction<UploadStatus>) => {
state.applyModelStatus = payload;
},
setDetailsModel: (
state,
{
payload,
}: PayloadAction<{ reference: string; isSuggested: boolean } | undefined>,
) => {
state.detailsModel = payload;
},
},
});

Expand Down
5 changes: 5 additions & 0 deletions apps/chat/src/store/marketplace/marketplace.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ export const selectIsApplyingModel = createSelector(
applyModelStatus !== UploadStatus.UNINITIALIZED &&
applyModelStatus !== UploadStatus.FAILED,
);

export const selectDetailsModel = createSelector(
[rootSelector],
(state) => state.detailsModel,
);

0 comments on commit bcbcb6f

Please sign in to comment.