parent
678228d223
commit
31196ffdf5
6 changed files with 190 additions and 118 deletions
@ -1,35 +0,0 @@ |
||||
import React from 'react'; |
||||
import MaterialTable from 'material-table'; |
||||
|
||||
export interface Entry { |
||||
name: String, |
||||
id: Number, |
||||
} |
||||
|
||||
export interface IProps { |
||||
artists: Entry[] |
||||
} |
||||
|
||||
export default function ArtistTable(props: IProps) { |
||||
const tableTitle = "Artists"; |
||||
const tableColumns = [ |
||||
{ title: "Name", field: 'name' }, |
||||
]; |
||||
const tableData = props.artists; |
||||
|
||||
const options = { |
||||
filtering: true, |
||||
paging: true, |
||||
pageSize: 100, |
||||
pageSizeOptions: [ 5, 10, 20, 50, 100 ] |
||||
}; |
||||
|
||||
return ( |
||||
<MaterialTable |
||||
title={tableTitle} |
||||
columns={tableColumns} |
||||
data={tableData} |
||||
options={options} |
||||
/> |
||||
); |
||||
} |
@ -1,36 +0,0 @@ |
||||
import React from 'react'; |
||||
import MaterialTable from 'material-table'; |
||||
|
||||
export interface Entry { |
||||
title: String, |
||||
artistName: String |
||||
} |
||||
|
||||
export interface IProps { |
||||
songs: Entry[] |
||||
} |
||||
|
||||
export default function SongTable(props: IProps) { |
||||
const tableTitle = "Songs"; |
||||
const tableColumns = [ |
||||
{ title: "Title", field: 'title' }, |
||||
{ title: "Artist", field: 'artistName' }, |
||||
]; |
||||
const tableData = props.songs; |
||||
|
||||
const options = { |
||||
filtering: true, |
||||
paging: true, |
||||
pageSize: 100, |
||||
pageSizeOptions: [ 5, 10, 20, 50, 100 ] |
||||
}; |
||||
|
||||
return ( |
||||
<MaterialTable |
||||
title={tableTitle} |
||||
columns={tableColumns} |
||||
data={tableData} |
||||
options={options} |
||||
/> |
||||
); |
||||
} |
@ -1,40 +1,89 @@ |
||||
import { SongQueryElemProperty, SongQueryFilterOp } from '../api'; |
||||
import { SongQueryElemProperty, SongQueryFilterOp, SongQueryElemOp } from '../api'; |
||||
|
||||
export enum QueryKeys { |
||||
TitleLike = 'tl', |
||||
ArtistLike = 'al', |
||||
AndQuerySignature = 'and', |
||||
OrQuerySignature = 'or', |
||||
OperandA = 'a', |
||||
OperandB = 'b', |
||||
} |
||||
|
||||
export interface TitleQuery { |
||||
titleLike: String |
||||
[QueryKeys.TitleLike]: String |
||||
}; |
||||
export function isTitleQuery(q: SongQuery): q is TitleQuery { |
||||
return "titleLike" in q; |
||||
return QueryKeys.TitleLike in q; |
||||
} |
||||
export function TitleToApiQuery(q: TitleQuery) { |
||||
return { |
||||
'prop': SongQueryElemProperty.title, |
||||
'propOperand': '%' + q.titleLike + '%', |
||||
'propOperand': '%' + q[QueryKeys.TitleLike] + '%', |
||||
'propOperator': SongQueryFilterOp.Like, |
||||
} |
||||
} |
||||
|
||||
export interface ArtistQuery { |
||||
artistLike: String |
||||
[QueryKeys.ArtistLike]: String |
||||
}; |
||||
export function isArtistQuery(q: SongQuery): q is ArtistQuery { |
||||
return "artistLike" in q; |
||||
return QueryKeys.ArtistLike in q; |
||||
} |
||||
export function ArtistToApiQuery(q: ArtistQuery) { |
||||
return { |
||||
'prop': SongQueryElemProperty.artistNames, |
||||
'propOperand': '%' + q.artistLike + '%', |
||||
'propOperand': '%' + q[QueryKeys.ArtistLike] + '%', |
||||
'propOperator': SongQueryFilterOp.Like, |
||||
} |
||||
} |
||||
|
||||
export type SongQuery = TitleQuery | ArtistQuery; |
||||
export interface AndQuery<T> { |
||||
[QueryKeys.AndQuerySignature]: any, |
||||
[QueryKeys.OperandA]: T, |
||||
[QueryKeys.OperandB]: T, |
||||
} |
||||
export function isAndQuery(q: SongQuery): q is AndQuery<SongQuery> { |
||||
return QueryKeys.AndQuerySignature in q; |
||||
} |
||||
export function AndToApiQuery(q: AndQuery<SongQuery>) { |
||||
return { |
||||
'childrenOperator': SongQueryElemOp.And, |
||||
'children': [ |
||||
toApiQuery(q.a), |
||||
toApiQuery(q.b), |
||||
] |
||||
} |
||||
} |
||||
|
||||
export interface OrQuery<T> { |
||||
[QueryKeys.OrQuerySignature]: any, |
||||
[QueryKeys.OperandA]: T, |
||||
[QueryKeys.OperandB]: T, |
||||
} |
||||
export function isOrQuery(q: SongQuery): q is OrQuery<SongQuery> { |
||||
return QueryKeys.OrQuerySignature in q; |
||||
} |
||||
export function OrToApiQuery(q: OrQuery<SongQuery>) { |
||||
return { |
||||
'childrenOperator': SongQueryElemOp.Or, |
||||
'children': [ |
||||
toApiQuery(q.a), |
||||
toApiQuery(q.b), |
||||
] |
||||
} |
||||
} |
||||
|
||||
export type SongQuery = TitleQuery | ArtistQuery | AndQuery<SongQuery> | OrQuery<SongQuery>; |
||||
|
||||
export function isSongQuery(q: any): q is SongQuery { |
||||
return q != null && |
||||
(isTitleQuery(q) || isArtistQuery(q)); |
||||
(isTitleQuery(q) || isArtistQuery(q) || isAndQuery(q) || isOrQuery(q)); |
||||
} |
||||
|
||||
export function toApiQuery(q: SongQuery) { |
||||
export function toApiQuery(q: SongQuery): any { |
||||
return (isTitleQuery(q) && TitleToApiQuery(q)) || |
||||
(isArtistQuery(q) && ArtistToApiQuery(q)) || {}; |
||||
(isArtistQuery(q) && ArtistToApiQuery(q)) || |
||||
(isAndQuery(q) && AndToApiQuery(q)) || |
||||
(isOrQuery(q) && OrToApiQuery(q)) || |
||||
{}; |
||||
} |
Loading…
Reference in new issue