Skip to content

Commit eb23e36

Browse files
committed
fix: data replacement in case of pre build apply filters
1 parent d3e6b0d commit eb23e36

File tree

4 files changed

+26
-7
lines changed

4 files changed

+26
-7
lines changed

src/Shared/Components/Plugin/PluginList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const PluginList = ({
3232
appId: appId ? +appId : null,
3333
})
3434

35-
handleDataUpdateForPluginResponse(pluginDataResponse)
35+
handleDataUpdateForPluginResponse(pluginDataResponse, true)
3636
} catch (error) {
3737
showError(error)
3838
} finally {

src/Shared/Components/Plugin/PluginListContainer.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,13 @@ const PluginListContainer = ({
9797

9898
const handleDataUpdateForPluginResponse: PluginListProps['handleDataUpdateForPluginResponse'] = (
9999
pluginResponse,
100+
appendResponse = false,
100101
) => {
101102
const clonedPluginDataStore = structuredClone(pluginDataStore)
102-
const { pluginStore: newPluginStore, totalCount: responseTotalCount } = pluginResponse
103-
const { parentPluginStore, pluginVersionStore } = newPluginStore
103+
const {
104+
pluginStore: { parentPluginStore, pluginVersionStore },
105+
totalCount: responseTotalCount,
106+
} = pluginResponse
104107

105108
Object.keys(parentPluginStore).forEach((key) => {
106109
if (!clonedPluginDataStore.parentPluginStore[key]) {
@@ -117,14 +120,21 @@ const PluginListContainer = ({
117120
handlePluginDataStoreUpdate(clonedPluginDataStore)
118121
handleUpdateTotalCount(responseTotalCount)
119122

120-
const newPluginList: typeof pluginList = structuredClone(pluginList)
123+
const newPluginList: typeof pluginList = appendResponse ? structuredClone(pluginList) : []
124+
const newPluginListMap = newPluginList.reduce(
125+
(acc, plugin) => {
126+
acc[plugin.parentPluginId] = true
127+
return acc
128+
},
129+
{} as Record<number, true>,
130+
)
121131

122132
Object.keys(parentPluginStore).forEach((key) => {
123-
// TODO: Can convert to map
124-
if (!newPluginList.find((plugin) => plugin.parentPluginId === +key)) {
133+
if (!newPluginListMap[key]) {
125134
newPluginList.push({
126135
parentPluginId: +key,
127136
})
137+
newPluginListMap[key] = true
128138
}
129139
})
130140

src/Shared/Components/Plugin/types.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,15 @@ export interface PluginListProps
167167
PluginListContainerProps,
168168
'pluginDataStore' | 'handlePluginSelection' | 'selectedPluginsMap' | 'isSelectable' | 'showCardBorder'
169169
> {
170-
handleDataUpdateForPluginResponse: (pluginResponse: Awaited<ReturnType<typeof getPluginStoreData>>) => void
170+
handleDataUpdateForPluginResponse: (
171+
pluginResponse: Awaited<ReturnType<typeof getPluginStoreData>>,
172+
/**
173+
* If true, the response would be appended to the existing data
174+
* if false, the existing data would be replaced with the new data
175+
* default value is false
176+
*/
177+
appendResponse?: boolean,
178+
) => void
171179
handleClearFilters: () => void
172180
pluginList: PluginListContainerProps['parentPluginList']
173181
totalCount: PluginListContainerProps['parentTotalCount']

src/Shared/Components/ReactSelect/utils.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ export const MenuListWithApplyButton = ({
191191
}: MenuListProps & { handleApplyFilter: () => void }) => (
192192
<>
193193
<components.MenuList {...props} />
194+
{/* TODO: Check not working look into this */}
194195
{props.selectProps.options.length > 0 && (
195196
<div className="p-8 dc__position-sticky dc__bottom-0 dc__border-top-n1 bcn-0 dc__bottom-radius-4">
196197
<button

0 commit comments

Comments
 (0)