mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Correctly migrate duplicate clusters in workspaces (#3211)
- Keep track of the set of all workspaces that each duplicated entry was a part of Signed-off-by: Sebastian Malton <sebastian@malton.name>
This commit is contained in:
1 parent
b00afee15c
commit
05311c4b1b
4 files changed
+38
-11
No files matched your search
@@ -63,8 +63,16 @@ function mergeLabels(left: Record<string, string>, right: Record<string, string>
|
||||
};
|
||||
}
|
||||
|
||||
function mergeSet(left: Iterable<string>, right: Iterable<string>): string[] {
|
||||
return [...new Set([...left, ...right])];
|
||||
function mergeSet(...iterables: Iterable<string>[]): string[] {
|
||||
const res = new Set<string>();
|
||||
|
||||
for (const iterable of iterables) {
|
||||
for (const val of iterable) {
|
||||
res.add(val);
|
||||
}
|
||||
}
|
||||
|
||||
return [...res];
|
||||
}
|
||||
|
||||
function mergeClusterModel(prev: ClusterModel, right: Omit<ClusterModel, "id">): ClusterModel {
|
||||
@@ -77,6 +85,7 @@ function mergeClusterModel(prev: ClusterModel, right: Omit<ClusterModel, "id">):
|
||||
labels: mergeLabels(prev.labels ?? {}, right.labels ?? {}),
|
||||
accessibleNamespaces: mergeSet(prev.accessibleNamespaces ?? [], right.accessibleNamespaces ?? []),
|
||||
workspace: prev.workspace || right.workspace,
|
||||
workspaces: mergeSet([prev.workspace, right.workspace], prev.workspaces ?? [], right.workspaces ?? []),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -113,6 +122,7 @@ export default {
|
||||
clusters.set(newId, {
|
||||
...cluster,
|
||||
id: newId,
|
||||
workspaces: [cluster.workspace].filter(Boolean),
|
||||
});
|
||||
moveStorageFolder({ folder, newId, oldId });
|
||||
}
|
||||
|
||||
@@ -71,17 +71,20 @@ export default {
|
||||
|
||||
for (const cluster of clusters) {
|
||||
const uid = generateNewIdFor(cluster);
|
||||
const workspaceHotbar = workspaceHotbars.get(cluster.workspace);
|
||||
|
||||
migrationLog(`Adding cluster ${uid} to ${workspaceHotbar.name}`);
|
||||
for (const workspaceId of cluster.workspaces ?? [cluster.workspace].filter(Boolean)) {
|
||||
const workspaceHotbar = workspaceHotbars.get(workspaceId);
|
||||
|
||||
if (workspaceHotbar?.items.length < defaultHotbarCells) {
|
||||
workspaceHotbar.items.push({
|
||||
entity: {
|
||||
uid: generateNewIdFor(cluster),
|
||||
name: cluster.preferences.clusterName || cluster.contextName,
|
||||
}
|
||||
});
|
||||
migrationLog(`Adding cluster ${uid} to ${workspaceHotbar.name}`);
|
||||
|
||||
if (workspaceHotbar?.items.length < defaultHotbarCells) {
|
||||
workspaceHotbar.items.push({
|
||||
entity: {
|
||||
uid: generateNewIdFor(cluster),
|
||||
name: cluster.preferences.clusterName || cluster.contextName,
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user