Move makeSearchableList to it’s own file

This commit is contained in:
Sam Carlton 2021-01-23 14:39:04 -06:00
parent 50272298bf
commit c73d62f6bc
3 changed files with 88 additions and 82 deletions

View file

@ -10,6 +10,7 @@ import { buildVideoPayload, buildAppBenchmarkPayload } from './helpers/build-pay
import { categories, getAppCategory } from './helpers/categories.js'
import { getAppEndpoint, getVideoEndpoint } from './helpers/app-derived.js'
import { makeSearchableList } from './helpers/searchable-list.js'
// Setup dotenv
dotenv.config()
@ -149,87 +150,6 @@ class BuildLists {
return
}
// Converts a list into a smaller searchable list
// similar to a table/spreadsheet
makeSearchableList ( list ) {
let firstLoop = true
const searchableList = new Set()
const tableHeader = new Set()
// const searchableKeys = new Set([
// 'name',
// 'text',
// 'lastUpdated',
// 'endpoint'
// ])
const makeSearchable = new Map([
[
'name',
item => {
// console.log('Running name method', item)
return item.name
}
],
[
'text',
item => item.text
],
[
'endpoint',
item => item.endpoint
],
[
'category',
app => {
return getAppCategory( app ).id
}
]
])
list.forEach( ( searchableItem ) => {
// If this is the first items
// then store the keys
if ( firstLoop ) {
Object.keys(searchableItem).forEach( key => {
// console.log(key, makeSearchable.has(key))
if ( !makeSearchable.has(key) ) return
// Add to table header so we can loop it later on
tableHeader.add( key )
})
// Add keys to table head
searchableList.add( Array.from( tableHeader ) )
firstLoop = false
}
// This could cause an issue if the keys
// are out of order
// console.log('tableHeader', tableHeader)
const tableRow = []
// Loop through keys from table header
// and push them to this row
tableHeader.forEach( key => {
// console.log('searchableValue', key, searchableItem[key], makeSearchable.get(key)(searchableItem) )
tableRow.push( makeSearchable.get(key)(searchableItem) )
})
searchableList.add( tableRow )
return
})
return searchableList
}
// Save app lists to JSON
saveAppLists = async function () {
@ -246,7 +166,7 @@ class BuildLists {
await this.saveList( listOptions )
const searchableList = this.makeSearchableList( this.lists[listOptions.name] )
const searchableList = makeSearchableList( this.lists[listOptions.name] )
// console.log('searchableList', searchableList)

View file

@ -1,3 +1,5 @@
// Universal JS imports only
// Contains all types of properies to keep data consistent
export const categoryTemplate = {

View file

@ -0,0 +1,84 @@
// Universal JS imports only
import { getAppCategory } from './categories.js'
// Converts a list into a smaller searchable list
// similar to a table/spreadsheet
export function makeSearchableList ( listSet ) {
let firstLoop = true
const searchableList = new Set()
const tableHeader = new Set()
// const searchableKeys = new Set([
// 'name',
// 'text',
// 'lastUpdated',
// 'endpoint'
// ])
const makeSearchable = new Map([
[
'name',
item => {
// console.log('Running name method', item)
return item.name
}
],
[
'text',
item => item.text
],
[
'endpoint',
item => item.endpoint
],
[
'category',
app => {
return getAppCategory( app ).id
}
]
])
listSet.forEach( ( searchableItem ) => {
// If this is the first items
// then store the keys
if ( firstLoop ) {
Object.keys(searchableItem).forEach( key => {
// console.log(key, makeSearchable.has(key))
if ( !makeSearchable.has(key) ) return
// Add to table header so we can loop it later on
tableHeader.add( key )
})
// Add keys to table head
searchableList.add( Array.from( tableHeader ) )
firstLoop = false
}
// This could cause an issue if the keys
// are out of order
// console.log('tableHeader', tableHeader)
const tableRow = []
// Loop through keys from table header
// and push them to this row
tableHeader.forEach( key => {
// console.log('searchableValue', key, searchableItem[key], makeSearchable.get(key)(searchableItem) )
tableRow.push( makeSearchable.get(key)(searchableItem) )
})
searchableList.add( tableRow )
return
})
return searchableList
}