mirror of
https://github.com/portainer/portainer.git
synced 2025-08-02 20:35:25 +02:00
fix(app templates): load app template for deployment [BE-11382] (#141)
This commit is contained in:
parent
20e3d3a15b
commit
c0c7144539
23 changed files with 453 additions and 60 deletions
|
@ -42,7 +42,7 @@ import { FormError } from '@@/form-components/FormError';
|
|||
import { EnvironmentVariablesPanel } from '@@/form-components/EnvironmentVariablesFieldset';
|
||||
import { EnvVar } from '@@/form-components/EnvironmentVariablesFieldset/types';
|
||||
|
||||
import { useValidateEnvironmentTypes } from '../useEdgeGroupHasType';
|
||||
import { useEdgeGroupHasType } from '../useEdgeGroupHasType';
|
||||
import { PrivateRegistryFieldset } from '../../../components/PrivateRegistryFieldset';
|
||||
|
||||
import {
|
||||
|
@ -172,7 +172,7 @@ function InnerForm({
|
|||
const { values, setFieldValue, isValid, handleSubmit, errors, dirty } =
|
||||
useFormikContext<FormValues>();
|
||||
|
||||
const { hasType } = useValidateEnvironmentTypes(values.groupIds);
|
||||
const { hasType } = useEdgeGroupHasType(values.groupIds);
|
||||
|
||||
const hasKubeEndpoint = hasType(EnvironmentType.EdgeAgentOnKubernetes);
|
||||
const hasDockerEndpoint = hasType(EnvironmentType.EdgeAgentOnDocker);
|
||||
|
|
|
@ -46,7 +46,7 @@ import { getDefaultStaggerConfig } from '../../components/StaggerFieldset.types'
|
|||
|
||||
import { PrivateRegistryFieldsetWrapper } from './PrivateRegistryFieldsetWrapper';
|
||||
import { FormValues } from './types';
|
||||
import { useValidateEnvironmentTypes } from './useEdgeGroupHasType';
|
||||
import { useEdgeGroupHasType } from './useEdgeGroupHasType';
|
||||
import { useStaggerUpdateStatus } from './useStaggerUpdateStatus';
|
||||
import { useUpdateEdgeStackMutation } from './useUpdateEdgeStackMutation';
|
||||
import { ComposeForm } from './ComposeForm';
|
||||
|
@ -194,7 +194,7 @@ function InnerForm({
|
|||
usePreventExit(initialValues.content, values.content, !isSaved);
|
||||
|
||||
const { getCachedContent, setContentCache } = useCachedContent();
|
||||
const { hasType } = useValidateEnvironmentTypes(values.edgeGroups);
|
||||
const { hasType } = useEdgeGroupHasType(values.edgeGroups);
|
||||
const staggerUpdateStatus = useStaggerUpdateStatus(edgeStack.Id);
|
||||
const [selectedVersion, setSelectedVersion] = useState(versionOptions?.[0]);
|
||||
const selectedParallelOption =
|
||||
|
|
|
@ -5,22 +5,40 @@ import { useEdgeGroups } from '@/react/edge/edge-groups/queries/useEdgeGroups';
|
|||
import { EdgeGroup } from '@/react/edge/edge-groups/types';
|
||||
import { EnvironmentType } from '@/react/portainer/environments/types';
|
||||
|
||||
export function useValidateEnvironmentTypes(groupIds: Array<EdgeGroup['Id']>) {
|
||||
export function useEdgeGroupHasType(groupIds: Array<EdgeGroup['Id']>) {
|
||||
const edgeGroupsQuery = useEdgeGroups();
|
||||
|
||||
const edgeGroups = edgeGroupsQuery.data || [];
|
||||
const edgeGroups = edgeGroupsQuery.data;
|
||||
|
||||
const modelEdgeGroups = _.compact(
|
||||
groupIds.map((id) => edgeGroups.find((e) => e.Id === id))
|
||||
const hasTypeFunction = createHasEnvironmentTypeFunction(
|
||||
groupIds,
|
||||
edgeGroups
|
||||
);
|
||||
const endpointTypes = modelEdgeGroups.flatMap((group) => group.EndpointTypes);
|
||||
|
||||
const hasType = useCallback(
|
||||
(type: EnvironmentType) => endpointTypes.includes(type),
|
||||
[endpointTypes]
|
||||
(type: EnvironmentType) => hasTypeFunction(type),
|
||||
[hasTypeFunction]
|
||||
);
|
||||
|
||||
return {
|
||||
hasType,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if any of the edge groups have the given type
|
||||
*/
|
||||
export function createHasEnvironmentTypeFunction(
|
||||
groupIds: EdgeGroup['Id'][],
|
||||
edgeGroups?: EdgeGroup[]
|
||||
) {
|
||||
const modelEdgeGroups = _.compact(
|
||||
groupIds.map((id) => edgeGroups?.find((e) => e.Id === id))
|
||||
);
|
||||
const endpointTypes = modelEdgeGroups.flatMap((group) => group.EndpointTypes);
|
||||
|
||||
function hasType(type: EnvironmentType) {
|
||||
return endpointTypes.includes(type);
|
||||
}
|
||||
|
||||
return hasType;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue