Skip to content

Commit 7c19ab7

Browse files
Merge pull request #717 from devtron-labs/feat/release-tenant-mapping
feat: release tenant mapping
2 parents 89bc6bb + c1e1bd1 commit 7c19ab7

File tree

6 files changed

+57
-5
lines changed

6 files changed

+57
-5
lines changed

src/Assets/IconV2/ic-expand-sm.svg

Lines changed: 3 additions & 0 deletions
Loading

src/Common/Constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const DOCUMENTATION = {
3030
GLOBAL_CONFIG_BUILD_INFRA: `${DOCUMENTATION_HOME_PAGE}${DOCUMENTATION_VERSION}/global-configurations/build-infra`,
3131
ENTERPRISE_LICENSE: `${DOCUMENTATION_HOME_PAGE}/enterprise-license`,
3232
KUBE_CONFIG: `${DOCUMENTATION_HOME_PAGE}${DOCUMENTATION_VERSION}/usage/resource-browser#running-kubectl-commands-locally`,
33+
TENANT_INSTALLATION: `${DOCUMENTATION_HOME_PAGE}${DOCUMENTATION_VERSION}/usage/software-distribution-hub/tenants`,
3334
}
3435

3536
export const PATTERNS = {

src/Common/Helper.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ export const applyCompareDiffOnUneditedDocument = (uneditedDocument: object, edi
679679

680680
/**
681681
* Returns a debounced variant of the function
682+
* @deprecated - It should use useRef instead, pls use useDebounce
682683
*/
683684
export const debounce = (func, timeout = 500) => {
684685
let timer
@@ -693,6 +694,17 @@ export const debounce = (func, timeout = 500) => {
693694
}
694695
}
695696

697+
export const useDebounce = <Callback extends (...args: any[]) => void>(cb: Callback, delay: number) => {
698+
const timeoutId = useRef<ReturnType<typeof setTimeout>>(null)
699+
700+
return (...args: Parameters<Callback>) => {
701+
if (timeoutId.current) {
702+
clearTimeout(timeoutId.current)
703+
}
704+
timeoutId.current = setTimeout(() => cb(...args), delay)
705+
}
706+
}
707+
696708
/**
697709
* Returns a capitalized string with first letter in uppercase and rest in lowercase
698710
*/

src/Common/Toggle/Toggle.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@
6363
background-color: var(--white);
6464
transition: all 0.4s ease;
6565
}
66+
67+
&.intermediate::before {
68+
width: 0px;
69+
height: 0px;
70+
}
71+
6672
&.with-icon {
6773
background-color: var(--bg-primary) !important;
6874
svg {

src/Common/Toggle/Toggle.tsx

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import React, { SyntheticEvent, useCallback } from 'react'
1818
import { Icon as IconComponent } from '@Shared/Components'
1919
import { throttle, useEffectAfterMount } from '../Helper'
20+
import { CHECKBOX_VALUE } from '@Common/Types'
2021
import './Toggle.scss'
2122

2223
const Toggle = ({
@@ -31,12 +32,14 @@ const Toggle = ({
3132
throttleOnChange = false,
3233
shouldToggleValueOnLabelClick = false,
3334
isLoading = false,
35+
value = CHECKBOX_VALUE.CHECKED,
36+
isControlled = false,
3437
...props
3538
}) => {
3639
const [active, setActive] = React.useState(selected)
3740

3841
useEffectAfterMount(() => {
39-
if (typeof onSelect === 'function') {
42+
if (typeof onSelect === 'function' && !isControlled) {
4043
if (active !== selected) {
4144
onSelect(active)
4245
}
@@ -49,7 +52,11 @@ const Toggle = ({
4952

5053
function handleClick() {
5154
if (!disabled) {
52-
setActive((active) => !active)
55+
if (isControlled) {
56+
onSelect(!active)
57+
} else {
58+
setActive((active) => !active)
59+
}
5360
}
5461
}
5562

@@ -70,8 +77,26 @@ const Toggle = ({
7077
}
7178
}
7279

80+
const isIntermediateView = selected && value === CHECKBOX_VALUE.INTERMEDIATE
81+
82+
const renderIcon = () => {
83+
if (isIntermediateView) {
84+
return (
85+
<div className="w-100 h-100 dc__position-abs flex">
86+
<div className="w-8 h-2 br-4 dc__no-shrink bg__white" />
87+
</div>
88+
)
89+
}
90+
91+
if (Icon) {
92+
return <Icon className={`icon-dim-20 br-4 p-2 ${iconClass}`} />
93+
}
94+
95+
return null
96+
}
97+
7398
return isLoading ? (
74-
<IconComponent name='ic-circle-loader' color='B500' size={20} />
99+
<IconComponent name="ic-circle-loader" color="B500" size={20} />
75100
) : (
76101
<label
77102
{...props}
@@ -80,8 +105,11 @@ const Toggle = ({
80105
{...(shouldToggleValueOnLabelClick ? { onClick: handleLabelClick } : {})}
81106
>
82107
<input type="checkbox" checked={!!active} onChange={handleChange} className="toggle__input" />
83-
<span className={`toggle__slider ${Icon ? 'with-icon br-4 dc__border' : 'round'}`} data-testid={dataTestId}>
84-
{Icon && <Icon className={`icon-dim-20 br-4 p-2 ${iconClass}`} />}
108+
<span
109+
className={`toggle__slider ${isIntermediateView ? 'intermediate' : ''} ${Icon ? 'with-icon br-4 dc__border' : 'round'}`}
110+
data-testid={dataTestId}
111+
>
112+
{renderIcon()}
85113
</span>
86114
</label>
87115
)

src/Shared/Components/Icon/Icon.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { ReactComponent as ICDockerhub } from '@IconsV2/ic-dockerhub.svg'
4545
import { ReactComponent as ICEcr } from '@IconsV2/ic-ecr.svg'
4646
import { ReactComponent as ICEnv } from '@IconsV2/ic-env.svg'
4747
import { ReactComponent as ICError } from '@IconsV2/ic-error.svg'
48+
import { ReactComponent as ICExpandSm } from '@IconsV2/ic-expand-sm.svg'
4849
import { ReactComponent as ICFailure } from '@IconsV2/ic-failure.svg'
4950
import { ReactComponent as ICFileKey } from '@IconsV2/ic-file-key.svg'
5051
import { ReactComponent as ICFolderUser } from '@IconsV2/ic-folder-user.svg'
@@ -161,6 +162,7 @@ export const iconMap = {
161162
'ic-ecr': ICEcr,
162163
'ic-env': ICEnv,
163164
'ic-error': ICError,
165+
'ic-expand-sm': ICExpandSm,
164166
'ic-failure': ICFailure,
165167
'ic-file-key': ICFileKey,
166168
'ic-folder-user': ICFolderUser,

0 commit comments

Comments
 (0)