mirror of
https://github.com/portainer/portainer.git
synced 2025-07-23 15:29:42 +02:00
refactor(namespace): migrate namespace edit to react [r8s-125] (#38)
This commit is contained in:
parent
40c7742e46
commit
ce7e0d8d60
108 changed files with 3183 additions and 2194 deletions
|
@ -0,0 +1,50 @@
|
|||
import { uniqBy } from 'lodash';
|
||||
|
||||
import { Registry } from '@/react/portainer/registries/types/registry';
|
||||
|
||||
import { UpdateRegistryPayload } from '../types';
|
||||
|
||||
export function createUpdateRegistriesPayload({
|
||||
registries,
|
||||
namespaceName,
|
||||
newRegistriesValues,
|
||||
initialRegistriesValues,
|
||||
environmentId,
|
||||
}: {
|
||||
registries: Registry[] | undefined;
|
||||
namespaceName: string;
|
||||
newRegistriesValues: Registry[];
|
||||
initialRegistriesValues: Registry[];
|
||||
environmentId: number;
|
||||
}): UpdateRegistryPayload[] {
|
||||
if (!registries) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Get all unique registries from both initial and new values
|
||||
const uniqueRegistries = uniqBy(
|
||||
[...initialRegistriesValues, ...newRegistriesValues],
|
||||
'Id'
|
||||
);
|
||||
|
||||
const payload = uniqueRegistries.map((registry) => {
|
||||
const currentNamespaces =
|
||||
registry.RegistryAccesses?.[`${environmentId}`]?.Namespaces || [];
|
||||
|
||||
const existsInNewValues = newRegistriesValues.some(
|
||||
(r) => r.Id === registry.Id
|
||||
);
|
||||
|
||||
// If registry is in new values, add namespace; if not, remove it
|
||||
const updatedNamespaces = existsInNewValues
|
||||
? [...new Set([...currentNamespaces, namespaceName])]
|
||||
: currentNamespaces.filter((ns) => ns !== namespaceName);
|
||||
|
||||
return {
|
||||
Id: registry.Id,
|
||||
Namespaces: updatedNamespaces,
|
||||
};
|
||||
});
|
||||
|
||||
return payload;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue