Skip to content

Commit

Permalink
#171 - a PoC of the idea of metadata value extractors. Completed the …
Browse files Browse the repository at this point in the history
…sorting spec parser part.
  • Loading branch information
SebastianMC committed Nov 3, 2024
1 parent 42a5f1f commit d82a80c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/custom-sort/custom-sort-types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import {MDataExtractor} from "./mdata-extractors";

export enum CustomSortGroupType {
Outsiders, // Not belonging to any of other groups
MatchAll, // like a wildard *, used in connection with foldersOnly or filesOnly. The difference between the MatchAll and Outsiders is
Expand Down Expand Up @@ -51,8 +53,10 @@ export enum CustomSortOrder {
export interface RecognizedOrderValue {
order: CustomSortOrder
applyToMetadataField?: string
metadataValueExtractor?: MDataExtractor
secondaryOrder?: CustomSortOrder
secondaryApplyToMetadataField?: string
secondaryMetadataValueExtractor?: MDataExtractor
}

export type NormalizerFn = (s: string) => string | null
Expand Down
11 changes: 4 additions & 7 deletions src/custom-sort/sorting-spec-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ interface CustomSortOrderAscDescPair {
interface CustomSortOrderSpec {
order: CustomSortOrder
byMetadataField?: string
metadataFieldExtractor?: MDataExtractor
}

const MAX_SORT_LEVEL: number = 1
Expand Down Expand Up @@ -1578,13 +1579,7 @@ export class SortingSpecProcessor {
sortOrderSpec[level] = {
order: order!,
byMetadataField: metadataName,

metadataFieldExtractor: metadataExtractor

... and the carry the metadataFieldExtractor attribute down the parser, handle correctly in the 4-levels mdata sorting options
and execute at runtime

Seems to be far too complex to be worth it.
}
}
return sortOrderSpec
Expand All @@ -1595,8 +1590,10 @@ export class SortingSpecProcessor {
return recognized ? (recognized instanceof AttrError ? recognized : {
order: recognized[0].order,
applyToMetadataField: recognized[0].byMetadataField,
metadataValueExtractor: recognized[0].metadataFieldExtractor,
secondaryOrder: recognized[1]?.order,
secondaryApplyToMetadataField: recognized[1]?.byMetadataField
secondaryApplyToMetadataField: recognized[1]?.byMetadataField,
secondaryMetadataValueExtractor: recognized[1]?.metadataFieldExtractor
}) : null;
}

Expand Down

0 comments on commit d82a80c

Please sign in to comment.