mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 15:29:42 +02:00
refactor(containers): migrate volumes tab to react [EE-5209] (#10284)
This commit is contained in:
parent
16ccf5871e
commit
e92f067e42
18 changed files with 398 additions and 143 deletions
|
@ -0,0 +1,46 @@
|
|||
import { useState } from 'react';
|
||||
import { FormikErrors } from 'formik';
|
||||
|
||||
import { InputList } from '@@/form-components/InputList';
|
||||
|
||||
import { Values, Volume } from './types';
|
||||
import { InputContext } from './context';
|
||||
import { Item } from './Item';
|
||||
|
||||
export function VolumesTab({
|
||||
onChange,
|
||||
values,
|
||||
allowBindMounts,
|
||||
errors,
|
||||
}: {
|
||||
onChange: (values: Values) => void;
|
||||
values: Values;
|
||||
allowBindMounts: boolean;
|
||||
errors?: FormikErrors<Values>;
|
||||
}) {
|
||||
const [controlledValues, setControlledValues] = useState(values);
|
||||
|
||||
return (
|
||||
<InputContext.Provider value={allowBindMounts}>
|
||||
<InputList<Volume>
|
||||
errors={Array.isArray(errors) ? errors : []}
|
||||
label="Volume mapping"
|
||||
onChange={(volumes) => handleChange(volumes)}
|
||||
value={controlledValues}
|
||||
addLabel="map additional volume"
|
||||
item={Item}
|
||||
itemBuilder={() => ({
|
||||
containerPath: '',
|
||||
type: 'volume',
|
||||
name: '',
|
||||
readOnly: false,
|
||||
})}
|
||||
/>
|
||||
</InputContext.Provider>
|
||||
);
|
||||
|
||||
function handleChange(newValues: Values) {
|
||||
onChange(newValues);
|
||||
setControlledValues(() => newValues);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue