fix: Preserve parsers/matches on folder navigation (#2249)
- Closes #2231
This commit is contained in:
@@ -2,7 +2,7 @@ import { ConditionState } from '../../conditions/types';
|
||||
import { FolderConfig, FolderType, folderTypeSchema } from '../../config/schema/folders';
|
||||
import { HomeAssistant } from '../../ha/types';
|
||||
import { Endpoint } from '../../types';
|
||||
import { ViewItem } from '../../view/item';
|
||||
import { ViewFolder, ViewItem } from '../../view/item';
|
||||
import { ViewItemCapabilities } from '../../view/types';
|
||||
import { sortItems } from '../view/sort';
|
||||
import { HAFoldersEngine } from './ha/engine';
|
||||
@@ -21,6 +21,18 @@ export class FoldersExecutor {
|
||||
);
|
||||
}
|
||||
|
||||
public generateChildFolderQuery(
|
||||
query: FolderQuery,
|
||||
folder: ViewFolder,
|
||||
): FolderQuery | null {
|
||||
return (
|
||||
this._getFolderEngine(query.folder.type)?.generateChildFolderQuery(
|
||||
query,
|
||||
folder,
|
||||
) ?? null
|
||||
);
|
||||
}
|
||||
|
||||
public async expandFolder(
|
||||
hass: HomeAssistant,
|
||||
query: FolderQuery,
|
||||
|
||||
@@ -4,8 +4,8 @@ import {
|
||||
FolderConfig,
|
||||
folderTypeSchema,
|
||||
HA_MEDIA_SOURCE_ROOT,
|
||||
HAFolderConfig,
|
||||
HAFolderPathComponent,
|
||||
HAFolderConfig,
|
||||
} from '../../../config/schema/folders';
|
||||
import { getViewItemsFromBrowseMediaArray } from '../../../ha/browse-media/browse-media-to-view-media';
|
||||
import { BrowseMediaViewFolder } from '../../../ha/browse-media/item';
|
||||
@@ -23,15 +23,15 @@ import {
|
||||
import { getMediaDownloadPath } from '../../../ha/download';
|
||||
import { HomeAssistant } from '../../../ha/types';
|
||||
import { Endpoint } from '../../../types';
|
||||
import { ViewItem } from '../../../view/item';
|
||||
import { ViewFolder, ViewItem } from '../../../view/item';
|
||||
import { ViewItemClassifier } from '../../../view/item-classifier';
|
||||
import { ViewItemCapabilities } from '../../../view/types';
|
||||
import {
|
||||
DownloadHelpers,
|
||||
EngineOptions,
|
||||
FolderPathComponent,
|
||||
FolderQuery,
|
||||
FoldersEngine,
|
||||
FolderPathComponent,
|
||||
} from '../types';
|
||||
import { MediaMatcher } from './media-matcher';
|
||||
import { MetadataGenerator } from './metadata-generator.js';
|
||||
@@ -96,7 +96,8 @@ export class HAFoldersEngine implements FoldersEngine {
|
||||
private getDefaultFolderPathComponents(
|
||||
haFolderConfig?: HAFolderConfig,
|
||||
): NonEmptyTuple<FolderPathComponent> {
|
||||
const shouldAddDefaultRoot = !haFolderConfig?.url && !haFolderConfig?.path?.[0]?.id;
|
||||
const shouldAddDefaultRoot =
|
||||
!haFolderConfig?.url && haFolderConfig?.path?.[0]?.id !== HA_MEDIA_SOURCE_ROOT;
|
||||
|
||||
const path: HAFolderPathComponent[] = [
|
||||
...(shouldAddDefaultRoot ? [{ id: HA_MEDIA_SOURCE_ROOT }] : []),
|
||||
@@ -190,4 +191,27 @@ export class HAFoldersEngine implements FoldersEngine {
|
||||
folder: query.folder,
|
||||
});
|
||||
}
|
||||
|
||||
public generateChildFolderQuery(
|
||||
query: FolderQuery,
|
||||
folder: ViewFolder,
|
||||
): FolderQuery | null {
|
||||
const id = folder.getID();
|
||||
if (query.folder.type !== folderTypeSchema.enum.ha || !id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Get the full configured path to find parsers/matchers for this depth.
|
||||
const fullPath = this.getDefaultFolderPathComponents(query.folder.ha);
|
||||
const nextConfiguredComponent = fullPath[query.path.length];
|
||||
|
||||
// Use the configured component's parsers/matchers if available, otherwise
|
||||
// just use the ID from the folder.
|
||||
const ha = nextConfiguredComponent?.ha ?? { id };
|
||||
|
||||
return {
|
||||
...query,
|
||||
path: [...query.path, { folder, ha }],
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ConditionState } from '../../conditions/types';
|
||||
import { FolderConfig, FolderConfigWithoutID } from '../../config/schema/folders';
|
||||
import { localize } from '../../localize/localize';
|
||||
import { Endpoint } from '../../types';
|
||||
import { ViewItem } from '../../view/item';
|
||||
import { ViewFolder, ViewItem } from '../../view/item';
|
||||
import { ViewItemCapabilities } from '../../view/types';
|
||||
import { CardFoldersAPI } from '../types';
|
||||
import { FoldersExecutor } from './executor';
|
||||
@@ -62,6 +62,13 @@ export class FoldersManager {
|
||||
return _folder ? this._executor.generateDefaultFolderQuery(_folder) : null;
|
||||
}
|
||||
|
||||
public generateChildFolderQuery(
|
||||
query: FolderQuery,
|
||||
folder: ViewFolder,
|
||||
): FolderQuery | null {
|
||||
return this._executor.generateChildFolderQuery(query, folder);
|
||||
}
|
||||
|
||||
public async expandFolder(
|
||||
query: FolderQuery,
|
||||
conditionState?: ConditionState,
|
||||
|
||||
@@ -48,6 +48,8 @@ export interface DownloadHelpers {
|
||||
|
||||
export interface FoldersEngine {
|
||||
generateDefaultFolderQuery(folder: FolderConfig): FolderQuery | null;
|
||||
generateChildFolderQuery(query: FolderQuery, folder: ViewFolder): FolderQuery | null;
|
||||
|
||||
expandFolder(
|
||||
hass: HomeAssistant,
|
||||
query: FolderQuery,
|
||||
|
||||
Reference in New Issue
Block a user