Skip to content

Commit 80bfa4b

Browse files
committed
feat: add shouldHideLabel in filter chips
1 parent 6060512 commit 80bfa4b

File tree

9 files changed

+45
-20
lines changed

9 files changed

+45
-20
lines changed

src/Common/Constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export const ROUTES = {
9292
CONFIG_CD_PIPELINE: 'config/cd-pipeline',
9393
MODULE_CONFIGURED: 'module/config',
9494
RESOURCE_HISTORY_DEPLOYMENT: 'resource/history/deployment',
95-
PLUGIN_GLOBAL_DETAIL: 'plugin/global/detail',
95+
PLUGIN_GLOBAL_DETAIL_V2: 'plugin/global/detail/v2',
9696
PLUGIN_GLOBAL_LIST_V2: 'plugin/global/list/v2',
9797
PLUGIN_GLOBAL_LIST_TAGS: 'plugin/global/list/tags',
9898
}

src/Shared/Components/FilterChips/FilterChips.component.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const FilterChip = ({
2424
handleRemoveFilter,
2525
getFormattedLabel = noop,
2626
getFormattedValue = noop,
27+
shouldHideLabel = false,
2728
}: FilterChipProps) => {
2829
const removeFilter = () => {
2930
handleRemoveFilter(label, value)
@@ -34,9 +35,10 @@ const FilterChip = ({
3435
const valueToDisplay = getFormattedValue(label, value) ?? value
3536

3637
return (
38+
(labelToDisplay || shouldHideLabel) &&
3739
valueToDisplay && (
3840
<div className="flexbox flex-align-center br-4 dc__border dc__bg-n50 pl-6 pr-6 pt-2 pb-2 dc__user-select-none h-24 dc__gap-6 fs-12 lh-20 cn-9 fw-4 dc__ellipsis-right">
39-
{labelToDisplay && (
41+
{!shouldHideLabel && (
4042
<>
4143
<span className="fw-6 dc__capitalize">{labelToDisplay}</span>
4244
<span className="dc__divider h-24" />
@@ -67,6 +69,7 @@ const FilterChips = <T = Record<string, unknown>,>({
6769
getFormattedValue,
6870
className = '',
6971
clearButtonClassName = '',
72+
shouldHideLabel,
7073
}: FilterChipsProps<T>) => {
7174
const handleRemoveFilter = (filterKey, valueToRemove) => {
7275
const updatedFilterConfig = JSON.parse(JSON.stringify(filterConfig))
@@ -98,6 +101,7 @@ const FilterChips = <T = Record<string, unknown>,>({
98101
handleRemoveFilter={handleRemoveFilter}
99102
getFormattedLabel={getFormattedLabel}
100103
getFormattedValue={getFormattedValue}
104+
shouldHideLabel={shouldHideLabel}
101105
/>
102106
))
103107
) : (
@@ -108,6 +112,7 @@ const FilterChips = <T = Record<string, unknown>,>({
108112
handleRemoveFilter={handleRemoveFilter}
109113
getFormattedLabel={getFormattedLabel}
110114
getFormattedValue={getFormattedValue}
115+
shouldHideLabel={shouldHideLabel}
111116
/>
112117
),
113118
)}

src/Shared/Components/FilterChips/types.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,15 @@ export interface FilterChipProps {
3737
* If passed, the label will be formatted accordingly
3838
*/
3939
getFormattedValue?: (filterKey: string, filterValue: unknown) => ReactNode
40+
/**
41+
* If true, would hide the label
42+
* @default false
43+
*/
44+
shouldHideLabel?: boolean
4045
}
4146

4247
export interface FilterChipsProps<T = Record<string, unknown>>
43-
extends Pick<FilterChipProps, 'getFormattedLabel' | 'getFormattedValue'> {
48+
extends Pick<FilterChipProps, 'getFormattedLabel' | 'getFormattedValue' | 'shouldHideLabel'> {
4449
/**
4550
* Current filter configuration
4651
*/

src/Shared/Components/Plugin/PluginCard.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,12 @@ const PluginCard = ({
4646
<div className="flexbox-col dc__gap-12">
4747
<div className="flexbox-col dc__gap-8">
4848
<div className="flexbox-col dc__gap-4">
49-
<h4 className="m-0 dc__truncate--clamp-3 cn-9 fs-13 fw-6 lh-20">
50-
{name}
51-
49+
<div className="flexbox dc__gap-4">
50+
<h4 className="m-0 dc__truncate--clamp-3 cn-9 fs-13 fw-6 lh-20">{name}</h4>
5251
{!isSelectable && (
5352
<span className="dc__truncate--clamp-3 cn-7 fs-12 fw-4 lh-20">({pluginVersion})</span>
5453
)}
55-
</h4>
54+
</div>
5655

5756
<span className="dc__truncate cn-7 fs-12 fw-4 lh-16">By {updatedBy || 'Devtron'}</span>
5857
</div>
@@ -62,6 +61,7 @@ const PluginCard = ({
6261
</div>
6362

6463
{/* Tag container */}
64+
{/* TODO: Make component since re-usable */}
6565
<div className="flexbox dc__gap-6 flex-wrap">
6666
{tags.map((tag) => (
6767
<div className="flexbox px-6 br-4 bcn-1 dc__align-items-center dc__mxw-160" key={tag}>

src/Shared/Components/Plugin/PluginList.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { useState } from 'react'
2-
import { PluginListProps } from './types'
2+
import { useParams } from 'react-router'
3+
import PluginCard from './PluginCard'
34
import { DetectBottom } from '../DetectBottom'
4-
import { GenericEmptyState, GenericFilterEmptyState, showError } from '../../../Common'
5+
import { PluginListParamsType, PluginListProps } from './types'
6+
import { GenericEmptyState, GenericFilterEmptyState, Progressing, showError } from '../../../Common'
57
import { getPluginStoreData } from './service'
6-
import PluginCard from './PluginCard'
78

89
const PluginList = ({
910
pluginDataStore,
@@ -16,6 +17,8 @@ const PluginList = ({
1617
isSelectable,
1718
handleClearFilters,
1819
}: PluginListProps) => {
20+
const { appId } = useParams<PluginListParamsType>()
21+
1922
const [isLoadingMorePlugins, setIsLoadingMorePlugins] = useState<boolean>(false)
2023
const handleLoadMore = async () => {
2124
setIsLoadingMorePlugins(true)
@@ -24,7 +27,7 @@ const PluginList = ({
2427
searchKey,
2528
offset: pluginList.length,
2629
selectedTags,
27-
appId: undefined,
30+
appId: appId ? +appId : null,
2831
})
2932

3033
handleDataUpdateForPluginResponse(pluginDataResponse)
@@ -36,7 +39,7 @@ const PluginList = ({
3639
}
3740

3841
if (!pluginList.length) {
39-
if (!!searchKey || !selectedTags.length) {
42+
if (!!searchKey || !!selectedTags.length) {
4043
return <GenericFilterEmptyState handleClearFilters={handleClearFilters} />
4144
}
4245

@@ -77,6 +80,8 @@ const PluginList = ({
7780
/>
7881
))}
7982

83+
{isLoadingMorePlugins && <Progressing />}
84+
8085
{totalCount > pluginList.length && !isLoadingMorePlugins && <DetectBottom callback={handleLoadMore} />}
8186
</>
8287
)

src/Shared/Components/Plugin/PluginListContainer.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const PluginListContainer = ({
2525
handlePluginSelection,
2626
// Selected plugins Section
2727
isSelectable,
28-
selectedPluginsMap,
28+
selectedPluginsMap = {},
2929
// Plugin list Section
3030
persistFilters,
3131
parentPluginList,
@@ -60,7 +60,6 @@ const PluginListContainer = ({
6060

6161
const { searchKey, selectedTags, showSelectedPlugins } = filters || {}
6262

63-
const pluginDataDependency = persistFilters ? [pluginList] : [searchKey, appId, selectedTags]
6463
// TODO: Add abortController as well
6564
const [isLoadingPluginData, pluginData, pluginDataError, reloadPluginData] = useAsync(
6665
() =>
@@ -70,14 +69,19 @@ const PluginListContainer = ({
7069
offset: 0,
7170
appId: appId ? +appId : null,
7271
}),
73-
pluginDataDependency,
72+
// TODO: Test if this is correct since new reference is created every time
73+
persistFilters ? [pluginList] : [searchKey, appId, selectedTags],
7474
persistFilters ? !pluginList.length : true,
7575
)
7676

77-
const [areTagsLoading, tags, tagsError, reloadTags] = useAsync(getAvailablePluginTags, [], !availableTags?.length)
77+
const [areTagsLoading, tags, tagsError, reloadTags] = useAsync(
78+
() => getAvailablePluginTags(appId ? +appId : null),
79+
[],
80+
!availableTags?.length,
81+
)
7882

7983
useEffect(() => {
80-
if (!isLoadingPluginData && !tagsError && pluginData) {
84+
if (!areTagsLoading && !tagsError && tags) {
8185
handleUpdateAvailableTags(tags)
8286
}
8387
}, [areTagsLoading, tags, tagsError])
@@ -105,7 +109,9 @@ const PluginListContainer = ({
105109
handleUpdateTotalCount(responseTotalCount)
106110

107111
const newPluginList: typeof pluginList = structuredClone(pluginList)
112+
108113
Object.keys(parentPluginStore).forEach((key) => {
114+
// TODO: Can convert to map
109115
if (!newPluginList.find((plugin) => plugin.parentPluginId === +key)) {
110116
newPluginList.push({
111117
parentPluginId: +key,
@@ -229,6 +235,7 @@ const PluginListContainer = ({
229235
clearFilters={handleClearFilters}
230236
className="p-0 w-100 pt-4"
231237
clearButtonClassName="dc__no-background-imp dc__no-border-imp dc__tab-focus"
238+
shouldHideLabel
232239
/>
233240
)}
234241

src/Shared/Components/Plugin/PluginTagSelect.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useMemo, useState } from 'react'
22
import ReactSelect, { MenuListProps } from 'react-select'
3-
import { OptionType } from '../../../Common'
3+
import { Option, OptionType } from '../../../Common'
44
import { commonSelectStyles, LoadingIndicator, MenuListWithApplyButton } from '../ReactSelect'
55
import { GenericSectionErrorState } from '../GenericSectionErrorState'
66
import { PluginTagSelectProps } from './types'
@@ -45,6 +45,7 @@ const PluginTagSelect = ({
4545
<MenuListWithApplyButton {...props} handleApplyFilter={handleApplyFilters} />
4646
)
4747

48+
// TODO: Look if should close menu on apply
4849
return (
4950
<ReactSelect
5051
styles={commonSelectStyles}
@@ -57,6 +58,7 @@ const PluginTagSelect = ({
5758
LoadingIndicator,
5859
NoOptionsMessage: renderNoOptionsMessage,
5960
MenuList: renderMenuList,
61+
Option,
6062
}}
6163
isLoading={isLoading}
6264
onChange={handleLocalSelection}
@@ -67,6 +69,7 @@ const PluginTagSelect = ({
6769
maxMenuHeight={300}
6870
onMenuClose={handleMenuClose}
6971
inputId="plugin-tag-select"
72+
className="w-200"
7073
/>
7174
)
7275
}

src/Shared/Components/Plugin/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export type PluginListContainerProps = BasePluginListContainerProps &
129129
/**
130130
* Map of parentId to boolean
131131
*/
132-
selectedPluginsMap: Record<number, boolean>
132+
selectedPluginsMap: Record<number, true>
133133
}
134134
)
135135

src/Shared/Components/Plugin/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const parseMinimalPluginVersionsDTO = (
1212
description: pluginVersion.description || '',
1313
name: pluginVersion.name || '',
1414
pluginVersion: pluginVersion.pluginVersion || '',
15-
isLatest: false,
15+
isLatest: pluginVersion.isLatest || false,
1616
}))
1717
}
1818

0 commit comments

Comments
 (0)