Skip to content

Commit d3cbab7

Browse files
committed
refactor: Code optimization + review fixes
1 parent 31d0b9e commit d3cbab7

File tree

8 files changed

+35
-22
lines changed

8 files changed

+35
-22
lines changed

src/Pages/ChartStore/ChartDetails/ChartDetailsAbout.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,13 @@ const ChartMetaData = ({
4747
if (Array.isArray(subtitle)) {
4848
return subtitle.map((item) =>
4949
isLink && item ? (
50-
<a className="m-0 fs-13 lh-20 fw-4 dc__break-word" href={item} target="_blank" rel="noreferrer">
50+
<a
51+
key={item}
52+
className="m-0 fs-13 lh-20 fw-4 dc__break-word"
53+
href={item}
54+
target="_blank"
55+
rel="noreferrer"
56+
>
5157
{item}
5258
</a>
5359
) : (

src/Pages/ChartStore/ChartDetails/ChartDetailsPresetValues.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {
2424
PresetValuesTableRowActionsOnHoverComponent,
2525
PresetValuesTableViewWrapper,
2626
} from './ChartDetailsTableComponents'
27+
import { CHART_DETAILS_NEW_PRESET_VALUE_ID } from './constants'
2728
import { fetchChartValuesTemplateList } from './services'
2829
import {
2930
ChartDetailsRouteParams,
@@ -40,7 +41,7 @@ const renderEmptyStateButton = (path: string) => () => (
4041
startIcon={<Icon name="ic-add" color={null} />}
4142
size={ComponentSizeType.medium}
4243
component={ButtonComponentType.link}
43-
linkProps={{ to: `${path}${URLS.PRESET_VALUES}/0` }}
44+
linkProps={{ to: `${path}${URLS.PRESET_VALUES}/${CHART_DETAILS_NEW_PRESET_VALUE_ID}` }}
4445
/>
4546
)
4647

src/Pages/ChartStore/ChartDetails/ChartDetailsReadme.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
SelectPickerVariantType,
1313
} from '@devtron-labs/devtron-fe-common-lib'
1414

15+
import { URLS } from '@Config/routes'
16+
1517
import { ChartDetailsReadmeProps } from './types'
1618

1719
const renderEmptyStateButton =
@@ -63,7 +65,7 @@ export const ChartDetailsReadme = ({
6365
isLoading={isLoading}
6466
error={error}
6567
progressingProps={{ size: 24 }}
66-
errorScreenManagerProps={{ code: error?.code, reload }}
68+
errorScreenManagerProps={{ code: error?.code, reload, redirectURL: URLS.CHARTS_DISCOVER }}
6769
>
6870
{!readme ? (
6971
<GenericEmptyState

src/Pages/ChartStore/ChartDetails/ChartDetailsTableComponents.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { getAppId } from '@Components/v2/appDetails/k8Resource/nodeDetail/nodeDe
2424
import { Moment12HourFormat } from '@Config/constants'
2525
import { URLS } from '@Config/routes'
2626

27-
import { CHART_DETAILS_PORTAL_CONTAINER_ID } from './constants'
27+
import { CHART_DETAILS_NEW_PRESET_VALUE_ID, CHART_DETAILS_PORTAL_CONTAINER_ID } from './constants'
2828
import {
2929
ChartDetailsRouteParams,
3030
DeploymentsTableCellComponentProps,
@@ -161,7 +161,9 @@ export const PresetValuesTableViewWrapper = ({
161161
text="Create Preset"
162162
size={ComponentSizeType.medium}
163163
component={ButtonComponentType.link}
164-
linkProps={{ to: `${generatePath(path, { chartId })}${URLS.PRESET_VALUES}/0` }}
164+
linkProps={{
165+
to: `${generatePath(path, { chartId })}${URLS.PRESET_VALUES}/${CHART_DETAILS_NEW_PRESET_VALUE_ID}`,
166+
}}
165167
/>
166168
)}
167169
</div>
@@ -277,7 +279,7 @@ const DeploymentsTableActionMenuCellComponent = ({ row, onDelete }: DeploymentsT
277279

278280
return (
279281
<ActionMenu
280-
id="chart-details-deployments-table-action-menu"
282+
id={`chart-details-deployments-table-action-menu-${row.id}`}
281283
onClick={handleClick}
282284
options={[
283285
{
@@ -292,8 +294,8 @@ const DeploymentsTableActionMenuCellComponent = ({ row, onDelete }: DeploymentsT
292294
},
293295
]}
294296
buttonProps={{
295-
dataTestId: 'chart-details-deployments-table-action-menu-delete',
296-
ariaLabel: 'chart-details-deployments-table-action-menu-delete',
297+
dataTestId: `chart-details-deployments-table-action-menu-delete-${row.id}`,
298+
ariaLabel: `chart-details-deployments-table-action-menu-delete-${row.id}`,
297299
showAriaLabelInTippy: false,
298300
icon: <Icon name="ic-more-vertical" color={null} />,
299301
variant: ButtonVariantType.borderLess,

src/Pages/ChartStore/ChartDetails/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ export const CHART_DETAILS_SEGMENTS: SegmentedControlProps['segments'] = [
1818
]
1919

2020
export const CHART_DETAILS_PORTAL_CONTAINER_ID = 'chart-details-portal-container'
21+
22+
export const CHART_DETAILS_NEW_PRESET_VALUE_ID = '0'

src/components/charts/chartValues/ChartValues.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import {
2727
import { getChartValuesCategorizedListParsed, getChartVersionDetails, getChartVersionsMin } from '../charts.service'
2828
import ChartValuesView from '../../v2/values/chartValuesDiff/ChartValuesView'
2929
import { ChartInstalledConfig, ChartKind } from '../../v2/values/chartValuesDiff/ChartValuesView.type'
30+
import { URLS } from '@Config/routes'
31+
import { ChartDetailsSegment } from '@Pages/ChartStore/ChartDetails/types'
3032

3133
export default function ChartValues() {
3234
const { chartId, chartValueId } = useParams<{ chartId: string; chartValueId: string }>()
@@ -147,7 +149,7 @@ const Header = ({ appStoreApplicationName, name }) => {
147149
() =>
148150
breadcrumbs.map((item) =>
149151
item.name === 'Preset values'
150-
? { ...item, to: `${item.to.replace('/preset-values', '')}?tab=preset-values` }
152+
? { ...item, to: `${item.to.replace(URLS.PRESET_VALUES, '')}?tab=${ChartDetailsSegment.PRESET_VALUES}` }
151153
: item,
152154
),
153155
[breadcrumbs],

src/components/charts/charts.helper.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
import { ToastManager, ToastVariantType, versionComparatorBySortOrder } from '@devtron-labs/devtron-fe-common-lib'
1818

19+
import { ChartDetailsSegment } from '@Pages/ChartStore/ChartDetails/types'
20+
1921
import { URLS } from '../../config'
2022
import { ChartGroupDeployResponse, ChartValuesType } from './charts.types'
2123

@@ -30,7 +32,7 @@ export function getDiscoverChartDetailsURL(chartId: string | number) {
3032
}
3133

3234
export function getSavedValuesListURL(chartId): string {
33-
return `${URLS.CHARTS}/discover/chart/${chartId}?tab=preset-values`
35+
return `${URLS.CHARTS}/discover/chart/${chartId}?tab=${ChartDetailsSegment.PRESET_VALUES}`
3436
}
3537

3638
export function getChartValuesURL(chartId: number | string, chartValueId?: number | string): string {

src/components/charts/list/DiscoverCharts.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,8 @@ const DiscoverChartList = ({ isSuperAdmin }: { isSuperAdmin: boolean }) => {
129129

130130
const noChartAvailable: boolean =
131131
chartList.length > 0 || searchApplied || selectedChartRepo.length > 0 || !!chartCategoryIds
132-
isLeavingPageNotAllowed.current = !state.charts.reduce(
133-
(acc: boolean, chart: ChartGroupEntry) => (acc = acc && chart.originalValuesYaml === chart.valuesYaml),
134-
true,
132+
isLeavingPageNotAllowed.current = !state.charts.every(
133+
(chart: ChartGroupEntry) => chart.originalValuesYaml === chart.valuesYaml,
135134
)
136135

137136
useEffect(() => {
@@ -719,15 +718,12 @@ export default function DiscoverCharts({ isSuperAdmin }: { isSuperAdmin: boolean
719718
<Route path={`${path}/group`}>
720719
<ChartGroupRouter />
721720
</Route>
722-
<Route
723-
path={`${path}${URLS.CHART}/:chartId${URLS.PRESET_VALUES}/:chartValueId`}
724-
render={() => <ChartValues />}
725-
exact
726-
/>
727-
<Route
728-
path={`${path}${URLS.CHART}/:chartId`}
729-
render={({ match: { params } }) => <ChartDetails key={params.chartId} />}
730-
/>
721+
<Route path={`${path}${URLS.CHART}/:chartId${URLS.PRESET_VALUES}/:chartValueId`} exact>
722+
<ChartValues />
723+
</Route>
724+
<Route path={`${path}${URLS.CHART}/:chartId`}>
725+
{({ match: { params } }) => <ChartDetails key={params.chartId} />}
726+
</Route>
731727
<Route>
732728
<DiscoverChartList isSuperAdmin={isSuperAdmin} />
733729
</Route>

0 commit comments

Comments
 (0)