Skip to content

Commit 3541f14

Browse files
committed
add a flag to opt out of version check in super.shouldApply in file mods
1 parent 18c6a04 commit 3541f14

File tree

5 files changed

+56
-33
lines changed

5 files changed

+56
-33
lines changed

api/src/unraid-api/graph/resolvers/docker/docker-template-scanner.service.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { join } from 'path';
55

66
import { XMLParser } from 'fast-xml-parser';
77

8-
import { PATHS_DOCKER_TEMPLATES } from '@app/environment.js';
8+
import { ENABLE_NEXT_DOCKER_RELEASE, PATHS_DOCKER_TEMPLATES } from '@app/environment.js';
99
import { DockerConfigService } from '@app/unraid-api/graph/resolvers/docker/docker-config.service.js';
1010
import { DockerTemplateSyncResult } from '@app/unraid-api/graph/resolvers/docker/docker-template-scanner.model.js';
1111
import { DockerContainer } from '@app/unraid-api/graph/resolvers/docker/docker.model.js';
@@ -33,6 +33,9 @@ export class DockerTemplateScannerService {
3333

3434
@Timeout(5_000)
3535
async bootstrapScan(attempt = 1, maxAttempts = 5): Promise<void> {
36+
if (!ENABLE_NEXT_DOCKER_RELEASE) {
37+
return;
38+
}
3639
try {
3740
this.logger.log(`Starting template scan (attempt ${attempt}/${maxAttempts})`);
3841
const result = await this.scanTemplates();

api/src/unraid-api/unraid-file-modifier/file-modification.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,11 @@ export abstract class FileModification {
212212
}
213213

214214
// Default implementation that can be overridden if needed
215-
async shouldApply(): Promise<ShouldApplyWithReason> {
215+
async shouldApply({
216+
checkOsVersion = true,
217+
}: { checkOsVersion?: boolean } = {}): Promise<ShouldApplyWithReason> {
216218
try {
217-
if (await this.isUnraidVersionGreaterThanOrEqualTo('7.2.0')) {
219+
if (checkOsVersion && (await this.isUnraidVersionGreaterThanOrEqualTo('7.2.0'))) {
218220
return {
219221
shouldApply: false,
220222
reason: 'Patch unnecessary for Unraid 7.2 or later because the Unraid API is integrated.',

api/src/unraid-api/unraid-file-modifier/modifications/docker-containers-page.modification.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default class DockerContainersPageModification extends FileModification {
1212
'/usr/local/emhttp/plugins/dynamix.docker.manager/DockerContainers.page';
1313

1414
async shouldApply(): Promise<ShouldApplyWithReason> {
15-
const baseCheck = await super.shouldApply();
15+
const baseCheck = await super.shouldApply({ checkOsVersion: false });
1616
if (!baseCheck.shouldApply) {
1717
return baseCheck;
1818
}

web/src/components/Docker/DockerContainersTable.vue

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { computed, h, nextTick, ref, resolveComponent, watch } from 'vue';
2+
import { computed, h, nextTick, ref, resolveComponent, watch, watchEffect } from 'vue';
33
import { useMutation } from '@vue/apollo-composable';
44
55
import BaseTreeTable from '@/components/Common/BaseTreeTable.vue';
@@ -260,8 +260,7 @@ const { visibleFolders, expandedFolders, toggleExpandFolder, setExpandedFolders
260260
});
261261
const busyRowIds = ref<Set<string>>(new Set());
262262
263-
const { loadColumnVisibility, mergeServerPreferences, saveColumnVisibility } =
264-
useDockerViewPreferences();
263+
const { mergeServerPreferences, saveColumnVisibility, columnVisibilityRef } = useDockerViewPreferences();
265264
266265
function setRowsBusy(ids: string[], busy: boolean) {
267266
const next = new Set(busyRowIds.value);
@@ -467,7 +466,7 @@ const columns = computed<TableColumn<TreeRow<DockerContainer>>[]>(() => {
467466
return cols;
468467
});
469468
470-
const hasAppliedPreferences = ref(false);
469+
const isApplyingColumnVisibility = ref(false);
471470
472471
function getDefaultColumnVisibility(isCompact: boolean): Record<string, boolean> {
473472
if (isCompact) {
@@ -498,38 +497,53 @@ function getDefaultColumnVisibility(isCompact: boolean): Record<string, boolean>
498497
}
499498
}
500499
501-
function applyColumnVisibilityPreferences() {
502-
if (!baseTableRef.value?.columnVisibility) return;
503-
if (hasAppliedPreferences.value) return;
500+
const defaultColumnVisibility = computed(() => getDefaultColumnVisibility(props.compact));
504501
505-
const savedPrefs = loadColumnVisibility();
506-
const defaultPrefs = getDefaultColumnVisibility(props.compact);
502+
const resolvedColumnVisibility = computed<Record<string, boolean>>(() => {
503+
const saved = columnVisibilityRef.value;
504+
return {
505+
...defaultColumnVisibility.value,
506+
...(saved ?? {}),
507+
};
508+
});
507509
508-
baseTableRef.value.columnVisibility.value = savedPrefs || defaultPrefs;
509-
hasAppliedPreferences.value = true;
510+
function visibilityStatesEqual(a?: Record<string, boolean>, b?: Record<string, boolean>): boolean {
511+
if (a === b) return true;
512+
if (!a || !b) return false;
513+
const aKeys = Object.keys(a);
514+
const bKeys = Object.keys(b);
515+
if (aKeys.length !== bKeys.length) return false;
516+
for (const key of aKeys) {
517+
if (a[key] !== b[key]) {
518+
return false;
519+
}
520+
}
521+
return true;
510522
}
511523
512-
watch(
513-
baseTableRef,
514-
(ref) => {
515-
if (ref?.columnVisibility && !hasAppliedPreferences.value) {
516-
applyColumnVisibilityPreferences();
517-
}
518-
},
519-
{ immediate: true, flush: 'post' }
520-
);
524+
watchEffect(() => {
525+
const tableVisibility = baseTableRef.value?.columnVisibility;
526+
if (!tableVisibility) return;
527+
528+
const target = resolvedColumnVisibility.value;
529+
const current = tableVisibility.value || {};
530+
531+
if (visibilityStatesEqual(current, target)) {
532+
return;
533+
}
534+
535+
isApplyingColumnVisibility.value = true;
536+
tableVisibility.value = { ...target };
537+
nextTick(() => {
538+
isApplyingColumnVisibility.value = false;
539+
});
540+
});
521541
522542
watch(
523543
() => props.viewPrefs,
524544
(prefs) => {
525-
if (prefs && hasAppliedPreferences.value) {
545+
if (prefs) {
526546
mergeServerPreferences(prefs);
527-
if (baseTableRef.value?.columnVisibility) {
528-
const savedPrefs = loadColumnVisibility();
529-
if (savedPrefs) {
530-
baseTableRef.value.columnVisibility.value = savedPrefs;
531-
}
532-
}
533547
}
534548
},
535549
{ immediate: true }
@@ -538,9 +552,10 @@ watch(
538552
watch(
539553
() => baseTableRef.value?.columnVisibility?.value,
540554
(columnVisibility) => {
541-
if (columnVisibility && hasAppliedPreferences.value && !props.compact) {
542-
saveColumnVisibility(columnVisibility);
555+
if (!columnVisibility || props.compact || isApplyingColumnVisibility.value) {
556+
return;
543557
}
558+
saveColumnVisibility({ ...columnVisibility });
544559
},
545560
{ deep: true }
546561
);

web/src/composables/useDockerColumnVisibility.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { computed } from 'vue';
12
import { useMutation } from '@vue/apollo-composable';
23
import { useDebounceFn, useStorage } from '@vueuse/core';
34

@@ -11,6 +12,7 @@ export function useDockerViewPreferences(viewId = 'default') {
1112
const storageKey = `docker-view-prefs-${viewId}`;
1213

1314
const localPrefs = useStorage<ViewPreferences>(storageKey, {});
15+
const columnVisibilityRef = computed(() => localPrefs.value.columnVisibility);
1416

1517
const { mutate: updatePrefs } = useMutation(UPDATE_DOCKER_VIEW_PREFERENCES);
1618

@@ -52,5 +54,6 @@ export function useDockerViewPreferences(viewId = 'default') {
5254
loadColumnVisibility,
5355
mergeServerPreferences,
5456
saveColumnVisibility,
57+
columnVisibilityRef,
5558
};
5659
}

0 commit comments

Comments
 (0)