forked from GoogleContainerTools/kpt-backstage-plugins
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from kamilmadejek/nephio-resources-editors
Editors for Nephio-specific resources (1st batch).
- Loading branch information
Showing
25 changed files
with
748 additions
and
31 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
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
143 changes: 143 additions & 0 deletions
143
...nents/ResourceEditorDialog/components/FirstClassEditors/CapacityEditor/CapacityEditor.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,143 @@ | ||
/** | ||
* Copyright 2024 The Nephio Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { TextField } from '@material-ui/core'; | ||
import React, { useState } from 'react'; | ||
import { useSetStateAndCall } from '../../../../../hooks/useSetStateAndCall'; | ||
import { getNumber } from '../../../../../utils/string'; | ||
import { | ||
Capacity, | ||
CapacityMetadata, | ||
CapacitySpec, | ||
} from '../../../../../types/Capacity'; | ||
import { dumpYaml, loadYaml } from '../../../../../utils/yaml'; | ||
import { EditorAccordion, ResourceMetadataAccordion } from '../Controls'; | ||
import { useEditorStyles } from '../styles'; | ||
|
||
type OnUpdatedYamlFn = (yaml: string) => void; | ||
|
||
type ResourceEditorProps = { | ||
yaml: string; | ||
onUpdatedYaml: OnUpdatedYamlFn; | ||
}; | ||
|
||
type State = { | ||
metadata: CapacityMetadata; | ||
spec: CapacitySpec; | ||
}; | ||
|
||
export const CapacityEditor = ({ | ||
yaml, | ||
onUpdatedYaml, | ||
}: ResourceEditorProps) => { | ||
const classes = useEditorStyles(); | ||
const resourceYaml = loadYaml(yaml) as Capacity; | ||
|
||
const createResourceState = (): State => ({ | ||
metadata: resourceYaml.metadata, | ||
spec: resourceYaml.spec, | ||
}); | ||
|
||
const [state, setState] = useState<State>(createResourceState()); | ||
const [expanded, setExpanded] = useState<string>(); | ||
|
||
const setStateAndCall = useSetStateAndCall([state, setState], newState => { | ||
onUpdatedYaml(dumpYaml({ ...resourceYaml, ...newState })); | ||
}); | ||
|
||
return ( | ||
<div className={classes.root}> | ||
<ResourceMetadataAccordion | ||
id="metadata" | ||
state={[expanded, setExpanded]} | ||
value={state.metadata} | ||
onUpdate={metadata => setStateAndCall(s => ({ ...s, metadata }))} | ||
/> | ||
|
||
<EditorAccordion | ||
id="spec" | ||
title="Capacity" | ||
state={[expanded, setExpanded]} | ||
> | ||
{/* TODO Consider adding regex-based validation of both throughput values. */} | ||
<TextField | ||
label="Max Uplink Throughput" | ||
variant="outlined" | ||
value={state.spec.maxUplinkThroughput ?? ''} | ||
onChange={e => { | ||
setStateAndCall(s => ({ | ||
...s, | ||
spec: { ...s.spec, maxUplinkThroughput: e.target.value }, | ||
})); | ||
}} | ||
fullWidth | ||
/> | ||
|
||
<TextField | ||
label="Max Downlink Throughput" | ||
variant="outlined" | ||
value={state.spec.maxDownlinkThroughput ?? ''} | ||
onChange={e => { | ||
setStateAndCall(s => ({ | ||
...s, | ||
spec: { ...s.spec, maxDownlinkThroughput: e.target.value }, | ||
})); | ||
}} | ||
fullWidth | ||
/> | ||
|
||
<TextField | ||
label="Max NF Connections" | ||
variant="outlined" | ||
value={state.spec.maxNFConnections ?? ''} | ||
onChange={e => { | ||
setStateAndCall(s => ({ | ||
...s, | ||
spec: { ...s.spec, maxNFConnections: getNumber(e.target.value) }, | ||
})); | ||
}} | ||
fullWidth | ||
/> | ||
|
||
<TextField | ||
label="Max Sessions" | ||
variant="outlined" | ||
value={state.spec.maxSessions ?? ''} | ||
onChange={e => { | ||
setStateAndCall(s => ({ | ||
...s, | ||
spec: { ...s.spec, maxSessions: getNumber(e.target.value) }, | ||
})); | ||
}} | ||
fullWidth | ||
/> | ||
|
||
<TextField | ||
label="Max Subscribers" | ||
variant="outlined" | ||
value={state.spec.maxSubscribers ?? ''} | ||
onChange={e => { | ||
setStateAndCall(s => ({ | ||
...s, | ||
spec: { ...s.spec, maxSubscribers: getNumber(e.target.value) }, | ||
})); | ||
}} | ||
fullWidth | ||
/> | ||
</EditorAccordion> | ||
</div> | ||
); | ||
}; |
17 changes: 17 additions & 0 deletions
17
.../src/components/ResourceEditorDialog/components/FirstClassEditors/CapacityEditor/index.ts
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,17 @@ | ||
/** | ||
* Copyright 2024 The Nephio Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export { CapacityEditor } from './CapacityEditor'; |
102 changes: 102 additions & 0 deletions
102
...s/ResourceEditorDialog/components/FirstClassEditors/Controls/ValueListEditorAccordion.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,102 @@ | ||
/** | ||
* Copyright 2024 The Nephio Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import { Button, TextField } from '@material-ui/core'; | ||
import AddIcon from '@material-ui/icons/Add'; | ||
import DeleteIcon from '@material-ui/icons/Delete'; | ||
import React, { Fragment, useRef } from 'react'; | ||
import { KubernetesValueList } from '../../../../../types/KubernetesResource'; | ||
import { toLowerCase } from '../../../../../utils/string'; | ||
import { IconButton } from '../../../../Controls'; | ||
import { useEditorStyles } from '../styles'; | ||
import { AccordionState, EditorAccordion } from './EditorAccordion'; | ||
|
||
type ValueListEditorProps = { | ||
id: string; | ||
title: string; | ||
state: AccordionState; | ||
valueList: KubernetesValueList; | ||
onUpdatedValueList: (valueList: KubernetesValueList) => void; | ||
}; | ||
|
||
export const ValueListEditorAccordion = ({ | ||
id, | ||
title, | ||
state, | ||
valueList, | ||
onUpdatedValueList, | ||
}: ValueListEditorProps) => { | ||
const refViewModel = useRef<{ value: string }[]>( | ||
valueList.map(value => ({ value })), | ||
); | ||
|
||
const classes = useEditorStyles(); | ||
|
||
const valueUpdated = (): void => { | ||
onUpdatedValueList( | ||
refViewModel.current.map(valueHolder => valueHolder.value), | ||
); | ||
}; | ||
|
||
const addRow = () => { | ||
refViewModel.current.push({ value: '' }); | ||
valueUpdated(); | ||
}; | ||
|
||
const description = `${refViewModel.current.length} ${toLowerCase(title)}`; | ||
|
||
return ( | ||
<EditorAccordion | ||
id={id} | ||
state={state} | ||
title={title} | ||
description={description} | ||
> | ||
<Fragment> | ||
{refViewModel.current.map((valueHolder, index) => ( | ||
<div className={classes.multiControlRow} key={index}> | ||
<TextField | ||
label="Value" | ||
variant="outlined" | ||
value={valueHolder.value} | ||
onChange={e => { | ||
valueHolder.value = e.target.value; | ||
valueUpdated(); | ||
}} | ||
fullWidth | ||
/> | ||
<IconButton | ||
title="Delete" | ||
className={classes.iconButton} | ||
onClick={() => { | ||
refViewModel.current = refViewModel.current.filter( | ||
thisValueHolder => thisValueHolder !== valueHolder, | ||
); | ||
valueUpdated(); | ||
}} | ||
> | ||
<DeleteIcon /> | ||
</IconButton> | ||
</div> | ||
))} | ||
|
||
<Button variant="outlined" startIcon={<AddIcon />} onClick={addRow}> | ||
Add {title} | ||
</Button> | ||
</Fragment> | ||
</EditorAccordion> | ||
); | ||
}; |
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
Oops, something went wrong.