Skip to content

Commit

Permalink
[CP-3322] Handle entitiesTypes ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarski committed Dec 2, 2024
1 parent 18be4b1 commit 61e208e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,26 @@ interface CategoryListItemConfig {
icon: IconType
}

const CONFIG_MAP: Record<string, CategoryListItemConfig> = {
const CONFIG_MAP: Record<string, Omit<CategoryListItemConfig, "id">> = {
audioFiles: {
id: "0",
name: "Music",
icon: IconType.MusicNote,
markerColor: "#E38577",
entitiesType: "audioFiles",
},
imageFiles: {
id: "1",
name: "Photos",
icon: IconType.PhotoCatalog,
markerColor: "#0E7490",
entitiesType: "imageFiles",
},
ebookFiles: {
id: "2",
name: "Ebooks",
icon: IconType.Book,
markerColor: "#A8DADC",
entitiesType: "ebookFiles",
},
applicationFiles: {
id: "3",
name: "Apps",
icon: IconType.Grid,
markerColor: "#AEBEC9",
Expand All @@ -45,9 +41,10 @@ const CONFIG_MAP: Record<string, CategoryListItemConfig> = {
}

function getConfigByEntityType(
entityType: string
entityType: string,
id: string
): CategoryListItemConfig | undefined {
return CONFIG_MAP[entityType] || undefined
return { ...CONFIG_MAP[entityType], id } || undefined
}

const generateFileCategoryListItem = ({
Expand Down Expand Up @@ -212,8 +209,8 @@ export const generateFileCategoryList = (entitiesTypes: string[]): Subview => {
},
}

return entitiesTypes.reduce((previousValue, entitiesType) => {
const config = getConfigByEntityType(entitiesType)
return entitiesTypes.reduce((previousValue, entitiesType, index) => {
const config = getConfigByEntityType(entitiesType, String(index))
if (!config) {
return previousValue
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,30 @@ interface FileListConfig {
entitiesType: string
}

const CONFIG_MAP: Record<string, FileListConfig> = {
const CONFIG_MAP: Record<string, Omit<FileListConfig, "id">> = {
audioFiles: {
id: "0",
name: "Music",
entitiesType: "audioFiles",
},
imageFiles: {
id: "1",
name: "Photos",
entitiesType: "imageFiles",
},
ebookFiles: {
id: "2",
name: "Ebooks",
entitiesType: "ebookFiles",
},
applicationFiles: {
id: "3",
name: "Apps",
entitiesType: "applicationFiles",
},
}

function getConfigByEntityType(entityType: string): FileListConfig | undefined {
return CONFIG_MAP[entityType] || undefined
function getConfigByEntityType(
entityType: string,
id: string
): FileListConfig | undefined {
return { ...CONFIG_MAP[entityType], id } || undefined
}

const generateFileList = ({
Expand Down Expand Up @@ -479,8 +478,8 @@ export const generateFileListWrapper = (entitiesTypes: string[]): Subview => {
},
}

return entitiesTypes.reduce((previousValue, entitiesType) => {
const config = getConfigByEntityType(entitiesType)
return entitiesTypes.reduce((previousValue, entitiesType, index) => {
const config = getConfigByEntityType(entitiesType, String(index))
if (!config) {
return previousValue
}
Expand Down

0 comments on commit 61e208e

Please sign in to comment.