Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ import { useMemo, useState } from 'react'
import { generatePath, Route, Switch, useLocation, useRouteMatch } from 'react-router-dom'

import { ReactComponent as ICError } from '@Icons/ic-error.svg'
import { getAppEnvDeploymentConfigList } from '@Shared/Components/DeploymentConfigDiff'
import { getAppEnvDeploymentConfigList, DEPLOYMENT_CONFIG_DIFF_SORT_KEY } from '@Shared/Components/DeploymentConfigDiff'
import { useAsync } from '@Common/Helper'
import { EnvResourceType, getAppEnvDeploymentConfig, getCompareSecretsData } from '@Shared/Services'
import { groupArrayByObjectKey } from '@Shared/Helpers'
import ErrorScreenManager from '@Common/ErrorScreenManager'
import { Progressing } from '@Common/Progressing'
import { useUrlFilters } from '@Common/Hooks'
import { GenericEmptyState, InfoColourBar } from '@Common/index'

import { GenericEmptyState, InfoColourBar, SortingOrder } from '@Common/index'
import { useMainContext } from '@Shared/Providers'

import { DeploymentHistoryConfigDiffCompare } from './DeploymentHistoryConfigDiffCompare'
import { DeploymentHistoryConfigDiffProps, DeploymentHistoryConfigDiffQueryParams } from './types'
import {
Expand Down Expand Up @@ -125,7 +125,7 @@ export const DeploymentHistoryConfigDiff = ({
`${generatePath(path, { ...params })}/${resourceType}${resourceName ? `/${resourceName}` : ''}${search}`

// Generate the deployment history config list
const deploymentConfigList = useMemo(() => {
const { deploymentConfigList, sortedDeploymentConfigList } = useMemo(() => {
if (!compareDeploymentConfigLoader && compareDeploymentConfig) {
const compareList =
isPreviousDeploymentConfigAvailable && compareDeploymentConfig[1].status === 'fulfilled'
Expand All @@ -140,17 +140,30 @@ export const DeploymentHistoryConfigDiff = ({
const currentList =
compareDeploymentConfig[0].status === 'fulfilled' ? compareDeploymentConfig[0].value.result : null

// This data is displayed on the deployment history diff view page.
// It requires dynamic sorting based on the current sortBy and sortOrder, which the user can modify using the Sort Button.
const configData = getAppEnvDeploymentConfigList({
currentList,
compareList,
getNavItemHref,
convertVariables,
sortingConfig: { sortBy, sortOrder },
})
return configData

// Sorting is hardcoded here because this data is displayed on the deployment history configuration tab.
// The diff needs to be shown on sorted data, and no additional sorting will be applied.
const sortedConfigData = getAppEnvDeploymentConfigList({
currentList,
compareList,
getNavItemHref,
convertVariables,
sortingConfig: { sortBy: DEPLOYMENT_CONFIG_DIFF_SORT_KEY, sortOrder: SortingOrder.ASC },
})

return { deploymentConfigList: configData, sortedDeploymentConfigList: sortedConfigData }
}

return null
return { deploymentConfigList: null, sortedDeploymentConfigList: null }
}, [
isPreviousDeploymentConfigAvailable,
compareDeploymentConfigLoader,
Expand All @@ -170,8 +183,11 @@ export const DeploymentHistoryConfigDiff = ({
)

const groupedDeploymentConfigList = useMemo(
() => (deploymentConfigList ? groupArrayByObjectKey(deploymentConfigList.configList, 'groupHeader') : []),
[deploymentConfigList],
() =>
sortedDeploymentConfigList
? groupArrayByObjectKey(sortedDeploymentConfigList.configList, 'groupHeader')
: [],
[sortedDeploymentConfigList],
)

/** Previous deployment config has 404 error. */
Expand Down