Skip to content

Commit

Permalink
More typescripting
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Dec 22, 2023
1 parent e7f69fb commit 1701a5e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const FacetedSelector = observer(function FacetedSelector({
model: HierarchicalTrackSelectorModel
}) {
const { classes } = useStyles()
const { view, selection, faceted } = model
const { view, selection, shownTrackIds, faceted } = model
const {
rows,
panelWidth,
Expand All @@ -61,7 +61,6 @@ const FacetedSelector = observer(function FacetedSelector({
} = faceted
const { pluginManager } = getEnv(model)
const { ref, scrollLeft } = useResizeBar()
const tracks = view.tracks as AnyConfigurationModel[]
const widthsDebounced = useDebounce(widths, 200)

const columns = [
Expand Down Expand Up @@ -102,10 +101,6 @@ const FacetedSelector = observer(function FacetedSelector({
})),
]

const shownTrackIds = new Set(
tracks.map(t => t.configuration.trackId as string),
)

return (
<>
<FacetedHeader model={model} />
Expand Down Expand Up @@ -197,19 +192,8 @@ const FacetedSelector = observer(function FacetedSelector({
onDrag={dist => faceted.setPanelWidth(panelWidth - dist)}
className={classes.resizeHandle}
/>
<div
style={{
width: panelWidth,
overflowY: 'auto',
overflowX: 'hidden',
}}
>
<FacetFilters
model={model}
width={panelWidth - 10}
rows={rows}
columns={columns}
/>
<div style={{ width: panelWidth }}>
<FacetFilters model={model} rows={rows} columns={columns} />
</div>
</>
) : null}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
export type Row = Record<
string,
{ metadata?: Record<string, unknown>; [key: string]: unknown }
>
export interface Row {
id: string
metadata?: Record<string, unknown>
[key: string]: unknown
}

export function getRowStr(facet: string, row: Row) {
return `${
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,20 @@ export function facetedStateTreeF() {
get rows() {
const session = getSession(self)
const { allTrackConfigurations, filterText } = self
// metadata is spread onto the object for easier access and sorting
// by the mui data grid (it's unable to sort by nested objects)
return allTrackConfigurations
.filter(conf => matches(filterText, conf, session))
.map(track => {
const metadata = readConfObject(track, 'metadata')
return {
id: track.trackId as string,
conf: track,
name: getTrackName(track, session),
category: readConfObject(track, 'category')?.join(', ') as string,
adapter: readConfObject(track, 'adapter')?.type as string,
description: readConfObject(track, 'description') as string,
metadata,
metadata: readConfObject(track, 'metadata') as Record<
string,
unknown
>,
} as const
})
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,17 @@ export default function stateTreeFactory(pluginManager: PluginManager) {
favoritesCounter: 0,
}))
.views(self => ({
/**
* #getter
*/
get shownTrackIds() {
return new Set<string>(
self.view?.tracks?.map(
(t: { configuration: { trackId: string } }) =>
t.configuration.trackId,
),
)
},
/**
* #getter
*/
Expand Down

0 comments on commit 1701a5e

Please sign in to comment.