Skip to content

Commit

Permalink
fix: enable mode when creating PhysicalMachineChaos with addresses (c…
Browse files Browse the repository at this point in the history
…haos-mesh#3797)

* fix: enable mode when creating PhysicalMachineChaos with addresses

Signed-off-by: Yue Yang <[email protected]>

* chore: update changelog

Signed-off-by: Yue Yang <[email protected]>

* fix: hasSelector

Signed-off-by: Yue Yang <[email protected]>

* fix: render Scope by hasSelector

Signed-off-by: Yue Yang <[email protected]>

Signed-off-by: Yue Yang <[email protected]>
  • Loading branch information
g1eny0ung authored Nov 17, 2022
1 parent 042fb87 commit d62eeb4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ For more information and how-to, see [RFC: Keep A Changelog](https://github.com/
- Fix timechaos not injected into the child process [#3725](https://github.com/chaos-mesh/chaos-mesh/pull/3725)
- Ignore `ScheduleSkipRemoveHistory` events to fix the memory of controller-manager keep increasing [#3761](https://github.com/chaos-mesh/chaos-mesh/issues/3761)
- Update `is mandatory` to true in a swagger comment [#3743](https://github.com/chaos-mesh/chaos-mesh/pull/3743)
- Enable mode when creating PhysicalMachineChaos with addresses in UI [#3797](https://github.com/chaos-mesh/chaos-mesh/pull/3797)

### Security

Expand Down
22 changes: 12 additions & 10 deletions ui/app/src/components/AutoForm/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ import _ from 'lodash'

export const podPhases = ['Pending', 'Running', 'Succeeded', 'Failed', 'Unknown']

export const scopeInitialValues = {
selector: {
namespaces: [],
labelSelectors: [],
annotationSelectors: [],
podPhaseSelectors: [],
pods: [],
physicalMachines: [],
},
export const scopeInitialValues = ({ hasSelector }: { hasSelector: boolean }) => ({
...(hasSelector && {
selector: {
namespaces: [],
labelSelectors: [],
annotationSelectors: [],
podPhaseSelectors: [],
pods: [],
physicalMachines: [],
},
}),
mode: 'all',
value: undefined,
}
})

export interface Schedule {
schedule: string
Expand Down
16 changes: 9 additions & 7 deletions ui/app/src/components/AutoForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { useStoreSelector } from 'store'
import { AutocompleteField, SelectField, Submit, TextField, TextTextField } from 'components/FormField'
import { SpecialTemplateType } from 'components/NewWorkflowNext/utils/convert'
import Scope from 'components/Scope'
import Mode from 'components/Scope/Mode'
import { T } from 'components/T'

import { concatKindAction } from 'lib/utils'
Expand Down Expand Up @@ -69,19 +70,18 @@ const AutoForm: React.FC<AutoFormProps> = ({ belong = Belong.Experiment, id, kin

const { useNewPhysicalMachine } = useStoreSelector((state) => state.settings)
const noScope =
kind === SpecialTemplateType.Suspend ||
kind === SpecialTemplateType.Serial ||
kind === SpecialTemplateType.Parallel ||
(kind === 'PhysicalMachineChaos' && !useNewPhysicalMachine)
kind === SpecialTemplateType.Suspend || kind === SpecialTemplateType.Serial || kind === SpecialTemplateType.Parallel

const [initialValues, setInitialValues] = useState<FormikValues>({
id,
kind,
action,
...(kind === 'NetworkChaos' && { target: scopeInitialValues }),
...(!noScope && scopeInitialValues),
...(kind === 'NetworkChaos' && { target: scopeInitialValues({ hasSelector: true }) }),
...(!noScope &&
scopeInitialValues({ hasSelector: kind === 'PhysicalMachineChaos' && !useNewPhysicalMachine ? false : true })),
...(belong === Belong.Workflow && { ...workflowNodeInfoInitialValues, templateType: kind }),
})
const hasSelector = !!initialValues.selector
const [form, setForm] = useState<AtomFormData[]>([])
const [scheduled, setScheduled] = useState(false)

Expand Down Expand Up @@ -343,12 +343,14 @@ const AutoForm: React.FC<AutoFormProps> = ({ belong = Belong.Experiment, id, kin
<Typography variant="h6">
<T id="newE.steps.scope" />
</Typography>
{useNewPhysicalMachine && (
{hasSelector ? (
<Scope
env={kind === 'PhysicalMachineChaos' ? 'physic' : 'k8s'}
kind={kind}
namespaces={namespaces}
/>
) : (
<Mode scope="selector" modeScope="" />
)}
<Divider />
<Box>
Expand Down
10 changes: 5 additions & 5 deletions ui/app/src/lib/localStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ export default class LocalStorage {
static ls = window.localStorage

static get(key: string) {
return LocalStorage.ls.getItem(PREFIX + key)
return this.ls.getItem(PREFIX + key)
}

static getObj(key: string) {
return JSON.parse(LocalStorage.get(key) ?? '{}')
return JSON.parse(this.get(key) ?? '{}')
}

static set(key: string, val: string) {
LocalStorage.ls.setItem(PREFIX + key, val)
this.ls.setItem(PREFIX + key, val)
}

static setObj(key: string, obj: any) {
LocalStorage.set(key, JSON.stringify(obj))
this.set(key, JSON.stringify(obj))
}

static remove(key: string) {
LocalStorage.ls.removeItem(PREFIX + key)
this.ls.removeItem(PREFIX + key)
}
}

0 comments on commit d62eeb4

Please sign in to comment.