mirror of
https://github.com/Dispatcharr/Dispatcharr.git
synced 2026-07-21 01:05:30 +00:00
rewrite with tanstack table
This commit is contained in:
parent
af638326e1
commit
6a0ce574b0
6 changed files with 884 additions and 50 deletions
|
|
@ -139,13 +139,13 @@ class ChannelViewSet(viewsets.ModelViewSet):
|
|||
queryset = Channel.objects.all()
|
||||
serializer_class = ChannelSerializer
|
||||
permission_classes = [IsAuthenticated]
|
||||
# pagination_class = ChannelPagination
|
||||
pagination_class = ChannelPagination
|
||||
|
||||
# filter_backends = [DjangoFilterBackend, SearchFilter, OrderingFilter]
|
||||
# filterset_class = ChannelFilter
|
||||
# search_fields = ['name', 'channel_group__name']
|
||||
# ordering_fields = ['channel_number', 'name', 'channel_group__name']
|
||||
# ordering = ['-channel_number']
|
||||
filter_backends = [DjangoFilterBackend, SearchFilter, OrderingFilter]
|
||||
filterset_class = ChannelFilter
|
||||
search_fields = ['name', 'channel_group__name']
|
||||
ordering_fields = ['channel_number', 'name', 'channel_group__name']
|
||||
ordering = ['-channel_number']
|
||||
|
||||
def get_queryset(self):
|
||||
qs = super().get_queryset()
|
||||
|
|
|
|||
|
|
@ -83,12 +83,9 @@ class ChannelProfileSerializer(serializers.ModelSerializer):
|
|||
fields = ['id', 'name', 'channels']
|
||||
|
||||
def get_channels(self, obj):
|
||||
memberships = ChannelProfileMembership.objects.filter(channel_profile=obj)
|
||||
memberships = ChannelProfileMembership.objects.filter(channel_profile=obj, enabled=True)
|
||||
return [
|
||||
{
|
||||
'id': membership.channel.id,
|
||||
'enabled': membership.enabled
|
||||
}
|
||||
membership.channel.id
|
||||
for membership in memberships
|
||||
]
|
||||
|
||||
|
|
|
|||
19
frontend/package-lock.json
generated
19
frontend/package-lock.json
generated
|
|
@ -16,7 +16,11 @@
|
|||
"@mantine/hooks": "^7.17.2",
|
||||
"@mantine/notifications": "^7.17.2",
|
||||
"@tabler/icons-react": "^3.31.0",
|
||||
<<<<<<< Updated upstream
|
||||
"@tanstack/react-table": "^8.21.2",
|
||||
=======
|
||||
"@tanstack/react-table": "^8.21.3",
|
||||
>>>>>>> Stashed changes
|
||||
"allotment": "^1.20.3",
|
||||
"axios": "^1.8.2",
|
||||
"clsx": "^2.1.1",
|
||||
|
|
@ -1743,12 +1747,21 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@tanstack/react-table": {
|
||||
<<<<<<< Updated upstream
|
||||
"version": "8.21.2",
|
||||
"resolved": "https://registry.npmjs.org/@tanstack/react-table/-/react-table-8.21.2.tgz",
|
||||
"integrity": "sha512-11tNlEDTdIhMJba2RBH+ecJ9l1zgS2kjmexDPAraulc8jeNA4xocSNeyzextT0XJyASil4XsCYlJmf5jEWAtYg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@tanstack/table-core": "8.21.2"
|
||||
=======
|
||||
"version": "8.21.3",
|
||||
"resolved": "https://registry.npmjs.org/@tanstack/react-table/-/react-table-8.21.3.tgz",
|
||||
"integrity": "sha512-5nNMTSETP4ykGegmVkhjcS8tTLW6Vl4axfEGQN3v0zdHYbK4UfoqfPChclTrJ4EoK9QynqAu9oUf8VEmrpZ5Ww==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@tanstack/table-core": "8.21.3"
|
||||
>>>>>>> Stashed changes
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
|
|
@ -1780,9 +1793,15 @@
|
|||
}
|
||||
},
|
||||
"node_modules/@tanstack/table-core": {
|
||||
<<<<<<< Updated upstream
|
||||
"version": "8.21.2",
|
||||
"resolved": "https://registry.npmjs.org/@tanstack/table-core/-/table-core-8.21.2.tgz",
|
||||
"integrity": "sha512-uvXk/U4cBiFMxt+p9/G7yUWI/UbHYbyghLCjlpWZ3mLeIZiUBSKcUnw9UnKkdRz7Z/N4UBuFLWQdJCjUe7HjvA==",
|
||||
=======
|
||||
"version": "8.21.3",
|
||||
"resolved": "https://registry.npmjs.org/@tanstack/table-core/-/table-core-8.21.3.tgz",
|
||||
"integrity": "sha512-ldZXEhOBb8Is7xLs01fR3YEc3DERiz5silj8tnGkFZytt1abEvl/GhUmCE0PMLaMPTa3Jk4HbKmRlHmu+gCftg==",
|
||||
>>>>>>> Stashed changes
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
|
|
|
|||
|
|
@ -18,7 +18,11 @@
|
|||
"@mantine/hooks": "^7.17.2",
|
||||
"@mantine/notifications": "^7.17.2",
|
||||
"@tabler/icons-react": "^3.31.0",
|
||||
<<<<<<< Updated upstream
|
||||
"@tanstack/react-table": "^8.21.2",
|
||||
=======
|
||||
"@tanstack/react-table": "^8.21.3",
|
||||
>>>>>>> Stashed changes
|
||||
"allotment": "^1.20.3",
|
||||
"axios": "^1.8.2",
|
||||
"clsx": "^2.1.1",
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -10,7 +10,7 @@ const useChannelsStore = create((set, get) => ({
|
|||
channelGroups: {},
|
||||
profiles: {},
|
||||
selectedProfileId: '0',
|
||||
selectedProfileChannels: [],
|
||||
selectedProfileChannelIds: new Set(),
|
||||
channelsPageSelection: [],
|
||||
stats: {},
|
||||
activeChannels: {},
|
||||
|
|
@ -97,10 +97,10 @@ const useChannelsStore = create((set, get) => ({
|
|||
},
|
||||
profiles,
|
||||
selectedProfile: profiles[state.selectedProfileId],
|
||||
selectedProfileChannels:
|
||||
selectedProfileChannelIds:
|
||||
state.selectedProfileId == '0'
|
||||
? []
|
||||
: profiles[state.selectedProfileId].channels,
|
||||
: new Set(profiles[state.selectedProfileId].channels),
|
||||
};
|
||||
});
|
||||
},
|
||||
|
|
@ -149,7 +149,9 @@ const useChannelsStore = create((set, get) => ({
|
|||
},
|
||||
profiles,
|
||||
selectedProfile: profiles[state.selectedProfileId],
|
||||
selectedProfileChannels: profiles[state.selectedProfileId].channels,
|
||||
selectedProfileChannelIds: new Set(
|
||||
profiles[state.selectedProfileId].channels
|
||||
),
|
||||
};
|
||||
}),
|
||||
|
||||
|
|
@ -256,7 +258,7 @@ const useChannelsStore = create((set, get) => ({
|
|||
if (profileIds.includes(state.selectedProfileId)) {
|
||||
additionalUpdates = {
|
||||
selectedProfileId: '0',
|
||||
selectedProfileChannels: [],
|
||||
selectedProfileChannelIds: new Set(),
|
||||
selectedProfile: {},
|
||||
};
|
||||
}
|
||||
|
|
@ -276,27 +278,30 @@ const useChannelsStore = create((set, get) => ({
|
|||
const profile = state.profiles[profileId];
|
||||
if (!profile) return state; // Profile doesn't exist, no update needed
|
||||
|
||||
const profileChannels = new Set(state.profiles[profileId].channels);
|
||||
|
||||
if (enabled) {
|
||||
channelIds.forEach((id) => {
|
||||
profileChannels.add(id);
|
||||
});
|
||||
} else {
|
||||
channelIds.forEach((id) => {
|
||||
profileChannels.delete(id);
|
||||
});
|
||||
}
|
||||
|
||||
// Efficiently update only the specific channel
|
||||
return {
|
||||
profiles: {
|
||||
...state.profiles,
|
||||
[profileId]: {
|
||||
...profile,
|
||||
channels: profile.channels.map((channel) =>
|
||||
channelIds.includes(channel.id)
|
||||
? { ...channel, enabled } // Update enabled flag
|
||||
: channel
|
||||
),
|
||||
channels: profileChannels,
|
||||
},
|
||||
},
|
||||
selectedProfileChannels: state.selectedProfileChannels.map(
|
||||
(channel) => ({
|
||||
id: channel.id,
|
||||
enabled: channelIds.includes(channel.id)
|
||||
? enabled
|
||||
: channel.enabled,
|
||||
})
|
||||
),
|
||||
...(state.selectedProfileId == profileId && {
|
||||
selectedProfileChannelIds: profileChannels,
|
||||
}),
|
||||
};
|
||||
}),
|
||||
|
||||
|
|
@ -306,7 +311,8 @@ const useChannelsStore = create((set, get) => ({
|
|||
setSelectedProfileId: (id) =>
|
||||
set((state) => ({
|
||||
selectedProfileId: id,
|
||||
selectedProfileChannels: id == '0' ? [] : state.profiles[id].channels,
|
||||
selectedProfileChannelIds:
|
||||
id == '0' ? new Set() : new Set(state.profiles[id].channels),
|
||||
})),
|
||||
|
||||
setChannelStats: (stats) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue