Skip to content

Commit 7ddf58c

Browse files
committed
refactor: code refactor/review fixes
1 parent 7c9fc89 commit 7ddf58c

File tree

4 files changed

+45
-48
lines changed

4 files changed

+45
-48
lines changed

src/Shared/Components/DeploymentConfigDiff/DeploymentConfigDiff.utils.tsx

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -300,22 +300,20 @@ const getDiffHeading = <DeploymentTemplate extends boolean>(
300300
let isDraft = false
301301
let isApprovalPending = false
302302

303-
if (deploymentTemplate) {
303+
if (!data) {
304+
doesNotExist = true
305+
} else if (deploymentTemplate) {
304306
const _data = data as DeploymentTemplateDTO
305-
if (!_data) {
306-
doesNotExist = true
307-
} else if (_data?.deploymentDraftData?.configData[0].draftMetadata.draftState === DraftState.Init) {
307+
if (_data.deploymentDraftData?.configData[0].draftMetadata.draftState === DraftState.Init) {
308308
isDraft = true
309-
} else if (_data?.deploymentDraftData?.configData[0].draftMetadata.draftState === DraftState.AwaitApproval) {
309+
} else if (_data.deploymentDraftData?.configData[0].draftMetadata.draftState === DraftState.AwaitApproval) {
310310
isApprovalPending = true
311311
}
312312
} else {
313313
const _data = data as ConfigMapSecretDataConfigDatumDTO
314-
if (!_data) {
315-
doesNotExist = true
316-
} else if (_data?.draftMetadata?.draftState === DraftState.Init) {
314+
if (_data.draftMetadata?.draftState === DraftState.Init) {
317315
isDraft = true
318-
} else if (_data?.draftMetadata?.draftState === DraftState.AwaitApproval) {
316+
} else if (_data.draftMetadata?.draftState === DraftState.AwaitApproval) {
319317
isApprovalPending = true
320318
}
321319
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export { default as SelectPicker } from './SelectPicker.component'
22
export * from './type'
3+
export { getSelectPickerOptionByValue } from './utils'

src/Shared/Components/SelectPicker/utils.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ComponentSizeType } from '@Shared/constants'
2-
import { StylesConfig } from 'react-select'
2+
import { GroupBase, OptionsOrGroups, StylesConfig } from 'react-select'
33
import { SelectPickerOptionType, SelectPickerProps, SelectPickerVariantType } from './type'
44

55
const getMenuWidthFromSize = (menuSize: SelectPickerProps['menuSize']): string => {
@@ -179,3 +179,39 @@ export const getCommonSelectStyle = ({
179179
...(getVariantOverrides(variant)?.singleValue(base, state) || {}),
180180
}),
181181
})
182+
183+
/**
184+
* Retrieves an option from the options list based on the provided value.
185+
*
186+
* @param optionsList - The list of options or groups of options.
187+
* @param value - The value to compare against the options' values.
188+
* @param defaultOption - The default option to return if no match is found.
189+
* @returns The matched option or the default option if no match is found.
190+
*/
191+
export const getSelectPickerOptionByValue = (
192+
optionsList: OptionsOrGroups<SelectPickerOptionType, GroupBase<SelectPickerOptionType>>,
193+
value: string | number,
194+
defaultOption: SelectPickerOptionType = { label: '', value: '' },
195+
): SelectPickerOptionType => {
196+
const foundOption = optionsList.reduce(
197+
(acc, curr) => {
198+
if (!acc.notFound) return acc
199+
200+
if ('value' in curr && curr.value === value) {
201+
return { data: curr, notFound: false }
202+
}
203+
204+
if ('options' in curr) {
205+
const nestedOption = curr.options.find(({ value: _value }) => _value === value)
206+
if (nestedOption) {
207+
return { data: nestedOption, notFound: false }
208+
}
209+
}
210+
211+
return acc
212+
},
213+
{ notFound: true, data: defaultOption },
214+
).data
215+
216+
return foundOption
217+
}

src/Shared/Helpers.tsx

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import { useEffect, useRef, useState, ReactElement } from 'react'
1919
import Tippy from '@tippyjs/react'
2020
import { Pair } from 'yaml'
21-
import { GroupBase, OptionsOrGroups } from 'react-select'
2221
import { handleUTCTime, mapByKey, MaterialInfo, shallowEqual, SortingOrder } from '../Common'
2322
import {
2423
AggregationKeys,
@@ -37,7 +36,6 @@ import {
3736
DeploymentStatusDetailsBreakdownDataType,
3837
DeploymentStatusDetailsType,
3938
PodMetadatum,
40-
SelectPickerOptionType,
4139
} from './Components'
4240
import { getAggregator } from '../Pages'
4341

@@ -734,39 +732,3 @@ export const getFileNameFromHeaders = (headers: Headers) =>
734732
?.find((n) => n.includes('filename='))
735733
?.replace('filename=', '')
736734
.trim()
737-
738-
/**
739-
* Retrieves an option from the options list based on the provided value.
740-
*
741-
* @param optionsList - The list of options or groups of options.
742-
* @param value - The value to compare against the options' values.
743-
* @param defaultOption - The default option to return if no match is found.
744-
* @returns The matched option or the default option if no match is found.
745-
*/
746-
export const getSelectPickerOptionByValue = (
747-
optionsList: OptionsOrGroups<SelectPickerOptionType, GroupBase<SelectPickerOptionType>>,
748-
value: string | number,
749-
defaultOption: SelectPickerOptionType = { label: '', value: '' },
750-
): SelectPickerOptionType => {
751-
const foundOption = optionsList.reduce(
752-
(acc, curr) => {
753-
if (!acc.notFound) return acc
754-
755-
if ('value' in curr && curr.value === value) {
756-
return { data: curr, notFound: false }
757-
}
758-
759-
if (!('value' in curr)) {
760-
const nestedOption = curr.options.find(({ value: _value }) => _value === value)
761-
if (nestedOption) {
762-
return { data: nestedOption, notFound: false }
763-
}
764-
}
765-
766-
return acc
767-
},
768-
{ notFound: true, data: defaultOption },
769-
).data
770-
771-
return foundOption
772-
}

0 commit comments

Comments
 (0)