-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite devices dashboard page in react #6489
Open
thornbill
wants to merge
11
commits into
jellyfin:master
Choose a base branch
from
thornbill:device-page-table
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+490
−354
Open
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
93b8911
Add TablePage component
thornbill 693d644
Rewrite devices page in react
thornbill f54ad01
Update import for TablePage
thornbill 061a363
Add device deletion support
thornbill c1c7e1e
Move UserAvatarButton component
thornbill de3b0da
Refactor devices page components
thornbill 65cc5ec
Remove legacy devices page
thornbill 6f81bbb
Remove actions column label
thornbill ce66d3a
Add error logging for deleting all devices
thornbill e70ef36
Fix date column label and formatting
thornbill f0c1641
Fix missing hook dependency
thornbill File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import Box from '@mui/material/Box/Box'; | ||
import Typography from '@mui/material/Typography/Typography'; | ||
import { type MRT_RowData, type MRT_TableInstance, MaterialReactTable } from 'material-react-table'; | ||
import React from 'react'; | ||
|
||
import Page, { type PageProps } from 'components/Page'; | ||
|
||
interface TablePageProps<T extends MRT_RowData> extends PageProps { | ||
title: string | ||
table: MRT_TableInstance<T> | ||
} | ||
|
||
export const DEFAULT_TABLE_OPTIONS = { | ||
// Enable custom features | ||
enableColumnPinning: true, | ||
enableColumnResizing: true, | ||
|
||
// Sticky header/footer | ||
enableStickyFooter: true, | ||
enableStickyHeader: true, | ||
muiTableContainerProps: { | ||
sx: { | ||
maxHeight: 'calc(100% - 7rem)' // 2 x 3.5rem for header and footer | ||
} | ||
} | ||
}; | ||
|
||
const TablePage = <T extends MRT_RowData>({ | ||
title, | ||
table, | ||
children, | ||
...pageProps | ||
}: TablePageProps<T>) => { | ||
return ( | ||
<Page | ||
title={title} | ||
{...pageProps} | ||
> | ||
<Box | ||
className='content-primary' | ||
sx={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
height: '100%' | ||
}} | ||
> | ||
<Box | ||
sx={{ | ||
marginBottom: 1 | ||
}} | ||
> | ||
<Typography variant='h2'> | ||
{title} | ||
</Typography> | ||
</Box> | ||
<MaterialReactTable table={table} /> | ||
</Box> | ||
{children} | ||
</Page> | ||
); | ||
}; | ||
|
||
export default TablePage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/apps/dashboard/features/devices/api/useDeleteDevice.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { DevicesApiDeleteDeviceRequest } from '@jellyfin/sdk/lib/generated-client/api/devices-api'; | ||
import { getDevicesApi } from '@jellyfin/sdk/lib/utils/api/devices-api'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
|
||
import { useApi } from 'hooks/useApi'; | ||
import { queryClient } from 'utils/query/queryClient'; | ||
import { QUERY_KEY } from './useDevices'; | ||
|
||
export const useDeleteDevice = () => { | ||
const { api } = useApi(); | ||
|
||
return useMutation({ | ||
mutationFn: (params: DevicesApiDeleteDeviceRequest) => ( | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
getDevicesApi(api!) | ||
.deleteDevice(params) | ||
), | ||
onSuccess: () => { | ||
void queryClient.invalidateQueries({ | ||
queryKey: [ QUERY_KEY ] | ||
}); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import type { DevicesApiGetDevicesRequest } from '@jellyfin/sdk/lib/generated-client'; | ||
import type { AxiosRequestConfig } from 'axios'; | ||
import type { Api } from '@jellyfin/sdk'; | ||
import { getDevicesApi } from '@jellyfin/sdk/lib/utils/api/devices-api'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import { useApi } from 'hooks/useApi'; | ||
|
||
export const QUERY_KEY = 'Devices'; | ||
|
||
const fetchDevices = async ( | ||
api?: Api, | ||
requestParams?: DevicesApiGetDevicesRequest, | ||
options?: AxiosRequestConfig | ||
) => { | ||
if (!api) { | ||
console.warn('[fetchDevices] No API instance available'); | ||
return; | ||
} | ||
|
||
const response = await getDevicesApi(api).getDevices(requestParams, { | ||
signal: options?.signal | ||
}); | ||
|
||
return response.data; | ||
}; | ||
|
||
export const useDevices = ( | ||
requestParams: DevicesApiGetDevicesRequest | ||
) => { | ||
const { api } = useApi(); | ||
return useQuery({ | ||
queryKey: [QUERY_KEY, requestParams], | ||
queryFn: ({ signal }) => | ||
fetchDevices(api, requestParams, { signal }), | ||
enabled: !!api | ||
}); | ||
}; |
24 changes: 24 additions & 0 deletions
24
src/apps/dashboard/features/devices/api/useUpdateDevice.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import type { DevicesApiUpdateDeviceOptionsRequest } from '@jellyfin/sdk/lib/generated-client/api/devices-api'; | ||
import { getDevicesApi } from '@jellyfin/sdk/lib/utils/api/devices-api'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
|
||
import { useApi } from 'hooks/useApi'; | ||
import { queryClient } from 'utils/query/queryClient'; | ||
import { QUERY_KEY } from './useDevices'; | ||
|
||
export const useUpdateDevice = () => { | ||
const { api } = useApi(); | ||
|
||
return useMutation({ | ||
mutationFn: (params: DevicesApiUpdateDeviceOptionsRequest) => ( | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
getDevicesApi(api!) | ||
.updateDeviceOptions(params) | ||
), | ||
onSuccess: () => { | ||
void queryClient.invalidateQueries({ | ||
queryKey: [ QUERY_KEY ] | ||
}); | ||
} | ||
}); | ||
}; |
22 changes: 22 additions & 0 deletions
22
src/apps/dashboard/features/devices/components/DeviceNameCell.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React, { FC } from 'react'; | ||
|
||
import { DeviceInfoCell } from 'apps/dashboard/features/devices/types/deviceInfoCell'; | ||
import { getDeviceIcon } from 'utils/image'; | ||
|
||
const DeviceNameCell: FC<DeviceInfoCell> = ({ row, renderedCellValue }) => ( | ||
<> | ||
<img | ||
alt={row.original.AppName || undefined} | ||
src={getDeviceIcon(row.original)} | ||
style={{ | ||
display: 'inline-block', | ||
maxWidth: '1.5em', | ||
maxHeight: '1.5em', | ||
marginRight: '1rem' | ||
}} | ||
/> | ||
{renderedCellValue} | ||
</> | ||
); | ||
|
||
export default DeviceNameCell; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import type { DeviceInfoDto } from '@jellyfin/sdk/lib/generated-client/models/device-info-dto'; | ||
import type { MRT_Row } from 'material-react-table'; | ||
|
||
export interface DeviceInfoCell { | ||
renderedCellValue: React.ReactNode | ||
row: MRT_Row<DeviceInfoDto> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we do this refactor for the api keys page as well? 😅
I'm also alright with doing it in another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. It didn't exist when I started this and I didn't want to make the PR bigger. 😅