Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaBondar committed Jan 21, 2025
1 parent 4bccec0 commit 625f6d0
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 24 deletions.
8 changes: 4 additions & 4 deletions apps/chat/src/components/Marketplace/MarketplaceBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,24 @@ import lightBanner from '@/public/images/banners/welcome-light.jpg';
const bannerText = {
title: {
[MarketplaceTabs.HOME]: 'Welcome to DIAL Marketplace',
[MarketplaceTabs.MY_APPLICATIONS]: 'My workspace',
[MarketplaceTabs.MY_WORKSPACE]: 'My workspace',
},
subtitle: {
[MarketplaceTabs.HOME]:
'Explore our AI offerings with your data and see how they boost your productivity!',
[MarketplaceTabs.MY_APPLICATIONS]:
[MarketplaceTabs.MY_WORKSPACE]:
'Here you can manage the AI agents used in your daily work',
},
};

const getBannerSrc = (theme: string, tab: MarketplaceTabs) => {
if (theme === 'dark') {
return tab === MarketplaceTabs.MY_APPLICATIONS
return tab === MarketplaceTabs.MY_WORKSPACE
? darkMyAppsBanner.src
: darkBanner.src;
}

return tab === MarketplaceTabs.MY_APPLICATIONS
return tab === MarketplaceTabs.MY_WORKSPACE
? lightMyAppsBanner.src
: lightBanner.src;
};
Expand Down
4 changes: 2 additions & 2 deletions apps/chat/src/components/Marketplace/MarketplaceFilterbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export const MarketplaceFilterbar = () => {
);

const handleMyAppsClick = useCallback(
() => handleChangeTab(MarketplaceTabs.MY_APPLICATIONS),
() => handleChangeTab(MarketplaceTabs.MY_WORKSPACE),
[handleChangeTab],
);

Expand Down Expand Up @@ -249,7 +249,7 @@ export const MarketplaceFilterbar = () => {
onClick={handleMyAppsClick}
caption={t('My workspace')}
Icon={IconHome2}
selected={selectedTab === MarketplaceTabs.MY_APPLICATIONS}
selected={selectedTab === MarketplaceTabs.MY_WORKSPACE}
dataQa="my-applications"
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion apps/chat/src/components/Marketplace/SearchHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export const SearchHeader = ({
className="w-full rounded border border-primary bg-transparent py-2.5 pl-[38px] pr-3 leading-4 outline-none placeholder:text-secondary focus-visible:border-accent-primary"
/>
</div>
{selectedTab === MarketplaceTabs.MY_APPLICATIONS && (
{selectedTab === MarketplaceTabs.MY_WORKSPACE && (
<AddAppButton menuItems={menuItems} />
)}
</div>
Expand Down
6 changes: 3 additions & 3 deletions apps/chat/src/components/Marketplace/TabRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ export const TabRenderer = ({ screenState }: TabRendererProps) => {
installedModelIds.has(entity.reference);

const entitiesForTab =
selectedTab === MarketplaceTabs.MY_APPLICATIONS
selectedTab === MarketplaceTabs.MY_WORKSPACE
? filteredEntities.filter(isInstalledModel)
: filteredEntities;

const shouldSuggest =
selectedTab === MarketplaceTabs.MY_APPLICATIONS && isSomeFilterNotEmpty;
selectedTab === MarketplaceTabs.MY_WORKSPACE && isSomeFilterNotEmpty;

const groupedEntities = groupModelsAndSaveOrder(
entitiesForTab.concat(shouldSuggest ? filteredEntities : []),
Expand Down Expand Up @@ -481,7 +481,7 @@ export const TabRenderer = ({ screenState }: TabRendererProps) => {
onEdit={handleEditApplication}
onBookmarkClick={handleBookmarkClick}
allEntities={allModels}
isMyAppsTab={selectedTab === MarketplaceTabs.MY_APPLICATIONS}
isMyAppsTab={selectedTab === MarketplaceTabs.MY_WORKSPACE}
isSuggested={detailsModel.isSuggested}
/>
)}
Expand Down
6 changes: 3 additions & 3 deletions apps/chat/src/constants/marketplace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EntityType } from '../types/common';
export enum MarketplaceQueryParams {
fromConversation = 'fromConversation',
model = 'model',
workspace = 'workspace',
tab = 'tab',
types = 'types',
topics = 'topics',
search = 'search',
Expand All @@ -17,8 +17,8 @@ export enum FilterTypes {
}

export enum MarketplaceTabs {
HOME = 'HOME',
MY_APPLICATIONS = 'MY_APPLICATIONS',
HOME = 'marketplace',
MY_WORKSPACE = 'workspace',
}

export enum DeleteType {
Expand Down
21 changes: 10 additions & 11 deletions apps/chat/src/store/marketplace/marketplace.epics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import {
selectSelectedTab,
} from './marketplace.selectors';

import isNil from 'lodash/isNil';
import { ParsedUrlQueryInput } from 'querystring';
import { ParsedUrlQueryInput, parse } from 'querystring';

const addToQuery = (
query: ParsedUrlQueryInput,
Expand All @@ -51,13 +50,15 @@ const setQueryParamsEpic: AppEpic = (action$, state$, { router }) =>
),
switchMap(() => {
const state = state$.value;
const query = router.query;
const query = parse(window.location.search.slice(1));
// workspace tab
const selectedTab = selectSelectedTab(state);
addToQuery(
query,
MarketplaceQueryParams.workspace,
selectedTab === MarketplaceTabs.MY_APPLICATIONS ? '1' : undefined,
MarketplaceQueryParams.tab,
selectedTab === MarketplaceTabs.MY_WORKSPACE
? MarketplaceTabs.MY_WORKSPACE
: undefined,
);
// application link
const reference = selectDetailsModel(state)?.reference;
Expand Down Expand Up @@ -97,11 +98,11 @@ const setQueryParamsEpic: AppEpic = (action$, state$, { router }) =>
}),
);

const initQueryParamsEpic: AppEpic = (action$, state$, { router }) =>
const initQueryParamsEpic: AppEpic = (action$, state$) =>
action$.pipe(
filter(MarketplaceActions.initQueryParams.match),
switchMap(() => {
const query = router.query;
const query = parse(window.location.search.slice(1));
const state = state$.value;

const actions: Observable<AnyAction>[] = [];
Expand Down Expand Up @@ -131,13 +132,11 @@ const initQueryParamsEpic: AppEpic = (action$, state$, { router }) =>
// workspace tab
const workSpaceTab =
query[MarketplaceQueryParams.fromConversation] ||
!isNil(query[MarketplaceQueryParams.workspace]);
query[MarketplaceQueryParams.tab] === MarketplaceTabs.MY_WORKSPACE;
actions.push(
of(
MarketplaceActions.setSelectedTab(
workSpaceTab
? MarketplaceTabs.MY_APPLICATIONS
: MarketplaceTabs.HOME,
workSpaceTab ? MarketplaceTabs.MY_WORKSPACE : MarketplaceTabs.HOME,
),
),
);
Expand Down
4 changes: 4 additions & 0 deletions apps/chat/src/store/marketplace/marketplace.reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface MarketplaceState {
searchTerm: string;
selectedTab: MarketplaceTabs;
applyModelStatus: UploadStatus;
applyModelId?: string;
detailsModel: { reference: string; isSuggested: boolean } | undefined;
}

Expand Down Expand Up @@ -64,6 +65,9 @@ export const marketplaceSlice = createSlice({
setApplyModelStatus: (state, { payload }: PayloadAction<UploadStatus>) => {
state.applyModelStatus = payload;
},
setApplyModelId: (state, { payload }: PayloadAction<string>) => {
state.applyModelId = payload;
},
setDetailsModel: (
state,
{
Expand Down

0 comments on commit 625f6d0

Please sign in to comment.