-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GEN-1517]: actions add via gql (#1635)
Co-authored-by: Alon Braymok <138359965+alonkeyval@users.noreply.github.com>
- Loading branch information
1 parent
40f2215
commit 2d4b1bb
Showing
17 changed files
with
400 additions
and
259 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
frontend/webapp/containers/main/actions/choose-action-body/custom-fields/error-sampler.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React, { useMemo } from 'react'; | ||
import { safeJsonParse } from '@/utils'; | ||
import { Input } from '@/reuseable-components'; | ||
import { FieldTitle, FieldWrapper } from './styled'; | ||
|
||
type Props = { | ||
value: string; | ||
setValue: (value: string) => void; | ||
}; | ||
|
||
type Parsed = { | ||
fallback_sampling_ratio: number; | ||
}; | ||
|
||
const MIN = 0, | ||
MAX = 100; | ||
|
||
const ErrorSampler: React.FC<Props> = ({ value, setValue }) => { | ||
const mappedValue = useMemo(() => safeJsonParse<Parsed>(value, { fallback_sampling_ratio: 0 }).fallback_sampling_ratio, [value]); | ||
|
||
const handleChange = (val: string) => { | ||
let num = Number(val); | ||
|
||
if (Number.isNaN(num) || num < MIN || num > MAX) { | ||
num = MIN; | ||
} | ||
|
||
const payload: Parsed = { | ||
fallback_sampling_ratio: num, | ||
}; | ||
|
||
setValue(JSON.stringify(payload)); | ||
}; | ||
|
||
return ( | ||
<FieldWrapper> | ||
<FieldTitle>Fallback sampling ratio</FieldTitle> | ||
<Input type='number' min={MIN} max={MAX} value={mappedValue} onChange={({ target: { value: v } }) => handleChange(v)} /> | ||
</FieldWrapper> | ||
); | ||
}; | ||
|
||
export default ErrorSampler; |
46 changes: 21 additions & 25 deletions
46
frontend/webapp/containers/main/actions/choose-action-body/custom-fields/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,41 @@ | ||
import React from 'react'; | ||
import { ActionsType } from '@/types'; | ||
import AddClusterInfo from './add-cluster-info'; | ||
import DeleteAttributes from './delete-attributes'; | ||
import RenameAttributes from './rename-attributes'; | ||
import PiiMasking from './pii-masking'; | ||
import ErrorSampler from './error-sampler'; | ||
import ProbabilisticSampler from './probabilistic-sampler'; | ||
|
||
interface ActionCustomFieldsProps { | ||
actionType?: ActionsType; | ||
value: string; | ||
setValue: (value: string) => void; | ||
} | ||
|
||
const ActionCustomFields: React.FC<ActionCustomFieldsProps> = ({ actionType, value, setValue }) => { | ||
switch (actionType) { | ||
case ActionsType.ADD_CLUSTER_INFO: { | ||
return <AddClusterInfo value={value} setValue={setValue} />; | ||
} | ||
|
||
case ActionsType.DELETE_ATTRIBUTES: { | ||
return <DeleteAttributes value={value} setValue={setValue} />; | ||
} | ||
|
||
case ActionsType.RENAME_ATTRIBUTES: { | ||
return <RenameAttributes value={value} setValue={setValue} />; | ||
} | ||
type ComponentProps = { | ||
value: string; | ||
setValue: (value: string) => void; | ||
}; | ||
|
||
case ActionsType.PII_MASKING: { | ||
return <PiiMasking value={value} setValue={setValue} />; | ||
} | ||
type ComponentType = React.FC<ComponentProps> | null; | ||
|
||
case ActionsType.ERROR_SAMPLER: | ||
return null; | ||
const componentsMap: Record<ActionsType, ComponentType> = { | ||
[ActionsType.ADD_CLUSTER_INFO]: AddClusterInfo, | ||
[ActionsType.DELETE_ATTRIBUTES]: DeleteAttributes, | ||
[ActionsType.RENAME_ATTRIBUTES]: RenameAttributes, | ||
[ActionsType.PII_MASKING]: PiiMasking, | ||
[ActionsType.ERROR_SAMPLER]: ErrorSampler, | ||
[ActionsType.PROBABILISTIC_SAMPLER]: ProbabilisticSampler, | ||
[ActionsType.LATENCY_SAMPLER]: null, | ||
}; | ||
|
||
case ActionsType.PROBABILISTIC_SAMPLER: | ||
return null; | ||
const ActionCustomFields: React.FC<ActionCustomFieldsProps> = ({ actionType, value, setValue }) => { | ||
if (!actionType) return null; | ||
|
||
case ActionsType.LATENCY_SAMPLER: | ||
return null; | ||
const Component = componentsMap[actionType]; | ||
|
||
default: | ||
return null; | ||
} | ||
return Component ? <Component value={value} setValue={setValue} /> : null; | ||
}; | ||
|
||
export default ActionCustomFields; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...webapp/containers/main/actions/choose-action-body/custom-fields/probabilistic-sampler.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React, { useMemo } from 'react'; | ||
import { safeJsonParse } from '@/utils'; | ||
import { Input } from '@/reuseable-components'; | ||
import { FieldTitle, FieldWrapper } from './styled'; | ||
|
||
type Props = { | ||
value: string; | ||
setValue: (value: string) => void; | ||
}; | ||
|
||
type Parsed = { | ||
sampling_percentage: string; | ||
}; | ||
|
||
const MIN = 0, | ||
MAX = 100; | ||
|
||
const ProbabilisticSampler: React.FC<Props> = ({ value, setValue }) => { | ||
const mappedValue = useMemo(() => safeJsonParse<Parsed>(value, { sampling_percentage: '0' }).sampling_percentage, [value]); | ||
|
||
const handleChange = (val: string) => { | ||
const num = Math.max(MIN, Math.min(Number(val), MAX)) || MIN; | ||
|
||
const payload: Parsed = { | ||
sampling_percentage: String(num), | ||
}; | ||
|
||
setValue(JSON.stringify(payload)); | ||
}; | ||
|
||
return ( | ||
<FieldWrapper> | ||
<FieldTitle>Sampling percentage</FieldTitle> | ||
<Input type='number' min={MIN} max={MAX} value={mappedValue} onChange={({ target: { value: v } }) => handleChange(v)} /> | ||
</FieldWrapper> | ||
); | ||
}; | ||
|
||
export default ProbabilisticSampler; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.