You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/react/docker/containers/CreateView/VolumesTab/VolumesTab.tsx

61 lines
1.6 KiB

import { useMemo } from 'react';
import { useIsEnvironmentAdmin } from '@/react/hooks/useUser';
import { useCurrentEnvironment } from '@/react/hooks/useCurrentEnvironment';
import { InputList } from '@@/form-components/InputList';
import { ArrayError } from '@@/form-components/InputList/InputList';
import { Values, Volume } from './types';
import { InputContext } from './context';
import { Item } from './Item';
export function VolumesTab({
onChange,
values,
errors,
allowAuto = false,
}: {
onChange: (values: Values) => void;
values: Values;
errors?: ArrayError<Values>;
allowAuto?: boolean;
}) {
const isEnvironmentAdminQuery = useIsEnvironmentAdmin({ adminOnlyCE: true });
const envQuery = useCurrentEnvironment();
const allowBindMounts = !!(
isEnvironmentAdminQuery.authorized ||
envQuery.data?.SecuritySettings.allowBindMountsForRegularUsers
);
const inputContext = useMemo(
() => ({ allowBindMounts, allowAuto }),
[allowAuto, allowBindMounts]
);
return (
<InputContext.Provider value={inputContext}>
<InputList<Volume>
errors={Array.isArray(errors) ? errors : []}
label="Volume mapping"
onChange={(volumes) => handleChange(volumes)}
value={values}
addLabel="map additional volume"
item={Item}
itemBuilder={() => ({
containerPath: '',
type: 'volume',
name: '',
readOnly: false,
})}
data-cy="docker-container-volumes"
/>
</InputContext.Provider>
);
function handleChange(newValues: Values) {
onChange(newValues);
}
}