Skip to content
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

refactor: large refactoring of filtering functionality and performance #909

Merged
merged 50 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
d63123e
refactor: almost all filter related frontend code
TurtIeSocks Jan 5, 2024
ac0cb4f
style: cleanup the advanced filter menu
TurtIeSocks Jan 5, 2024
33c6df7
fix: disable prop for size & gender
TurtIeSocks Jan 5, 2024
a216235
style: slider tile width
TurtIeSocks Jan 5, 2024
03cbddb
style: color prop for booltoggle
TurtIeSocks Jan 5, 2024
1cf4955
fix: disable prop for multiselector
TurtIeSocks Jan 5, 2024
20dd65d
feat: useTranslateById AIO hook for ez key translations
TurtIeSocks Jan 5, 2024
e9ca4b4
refactor: move quick selector into its own component
TurtIeSocks Jan 5, 2024
96190b9
refactor: split selector components into their own files
TurtIeSocks Jan 5, 2024
f401bbe
fix: top level state changes
TurtIeSocks Jan 5, 2024
98686b8
fix: better slide/input behaviors
TurtIeSocks Jan 5, 2024
6a2651f
feat: dev settings in sidebar
TurtIeSocks Jan 5, 2024
0625fe4
refactor: better enabled/all behaviors
TurtIeSocks Jan 5, 2024
3cc8ea3
refactor: move advanced menu state into a store
TurtIeSocks Jan 6, 2024
73ec7e4
refactor: cleanup virtual grid component
TurtIeSocks Jan 6, 2024
4431429
refactor: cleanup
TurtIeSocks Jan 6, 2024
412b3af
style: menu layout and fixes
TurtIeSocks Jan 6, 2024
422feb6
refactor: move tiled background to its own component
TurtIeSocks Jan 6, 2024
a72d122
refactor: consts renames
TurtIeSocks Jan 6, 2024
cb57574
fix: support for `all` in pokestop model
TurtIeSocks Jan 6, 2024
a4c4eee
fix: more filter tweaks
TurtIeSocks Jan 6, 2024
0e96864
refactor: styled divider
TurtIeSocks Jan 6, 2024
9cceb3d
refactor: apply to all action
TurtIeSocks Jan 6, 2024
7efe5ff
Merge branch 'quick-pkmn-filters' into filter-code-refactoring
TurtIeSocks Jan 6, 2024
2daf109
fix: some state bugs
TurtIeSocks Jan 6, 2024
8831e81
refactor: rename and move `CustomImg`
TurtIeSocks Jan 6, 2024
18f75e8
refactor: drawer performance
TurtIeSocks Jan 6, 2024
8b7d25d
fix: prop cleanups
TurtIeSocks Jan 6, 2024
7068f6a
chore: fully replace ReactWindow
TurtIeSocks Jan 7, 2024
8cea2fb
fix: gym badge menu from popup
TurtIeSocks Jan 7, 2024
2aa6134
Merge branch 'quick-pkmn-filters' into filter-code-refactoring
TurtIeSocks Jan 7, 2024
fce7eb9
fix: pvp mons with no iv perm
TurtIeSocks Jan 8, 2024
4b06e1e
style: user perms
TurtIeSocks Jan 8, 2024
a9d3506
refactor: user backups
TurtIeSocks Jan 8, 2024
539d9e1
refactor: move user permission into file
TurtIeSocks Jan 8, 2024
de1587e
refactor: move gym badge to separate file
TurtIeSocks Jan 8, 2024
ed9ee2d
refactor: move LinkAccounts to separate file
TurtIeSocks Jan 8, 2024
658c7ba
refactor: extra fields in its own file
TurtIeSocks Jan 8, 2024
c9b08e6
refactor: move user profile file
TurtIeSocks Jan 8, 2024
15ad84d
fix: user fields
TurtIeSocks Jan 8, 2024
f4564ef
fix: poracle manager with new state fixes
TurtIeSocks Jan 9, 2024
9ac88ca
fix: cleanups
TurtIeSocks Jan 9, 2024
37388f8
refactor: slot selection dialog
TurtIeSocks Jan 9, 2024
57ae335
fix: cleanup from slot selection changes
TurtIeSocks Jan 9, 2024
52690be
fix: cleanups
TurtIeSocks Jan 9, 2024
3c9e40c
fix: tut welcome page
TurtIeSocks Jan 9, 2024
efd4a98
refactor: move help dialog
TurtIeSocks Jan 9, 2024
36f2bd8
fix: missing label on search
TurtIeSocks Jan 9, 2024
d4016b5
refactor: remove old search component
TurtIeSocks Jan 9, 2024
b17753f
fix: alignment uicons by id
TurtIeSocks Jan 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"i18n-ally.localesPaths": [
"packages/locales/lib/human",
"packages/locales/lib/generated"
"packages/locales/lib/generated",
"packages/locales/lib/data"
],
"i18n-ally.keystyle": "flat",
"[javascript]": {
Expand All @@ -14,4 +15,4 @@
},
"editor.formatOnSave": true,
"docwriter.style": "JSDoc"
}
}
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@
"react-i18next": "^11.16.7",
"react-leaflet": "4.2.1",
"react-router-dom": "^6.15.0",
"react-virtualized-auto-sizer": "^1.0.20",
"react-virtuoso": "^4.5.0",
"react-window": "^1.8.9",
"react-virtuoso": "^4.6.2",
"rtree": "^1.4.2",
"source-map": "^0.7.4",
"suncalc": "^1.9.0",
Expand Down
4 changes: 3 additions & 1 deletion packages/locales/lib/human/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -713,5 +713,7 @@
"expert": "Expert",
"basic_description": "Easily select Pokémon and apply a global filter",
"intermediate_description": "Set individual filters globally and per Pokémon (traditional)",
"expert_description": "Manual input queries for the most customization"
"expert_description": "Manual input queries for the most customization",
"icon_size": "Icon Size",
"developer": "Developer"
}
38 changes: 37 additions & 1 deletion packages/types/lib/client.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from 'react'
import { Config } from './config'
import UAssets from '@services/Icons'
import { ButtonProps } from '@mui/material'
import { ButtonProps, SxProps, Theme } from '@mui/material'
import { SystemStyleObject } from '@mui/system'

declare global {
declare const CONFIG: Config<true>
Expand All @@ -15,3 +16,38 @@ declare global {
export interface CustomI extends React.HTMLProps<HTMLLIElement> {
size?: ButtonProps['size']
}

export type TimesOfDay = 'day' | 'night' | 'dawn' | 'dusk'

export type MarginProps = {
[Key in
| 'm'
| 'mt'
| 'mb'
| 'ml'
| 'mr'
| 'mx'
| 'my']?: React.CSSProperties['margin']
}

export type PaddingProps = {
[Key in
| 'p'
| 'pt'
| 'pb'
| 'pl'
| 'pr'
| 'px'
| 'py']?: React.CSSProperties['padding']
}

export interface MultiSelectorProps<V> {
value: V
items: readonly V[]
tKey?: string
disabled?: boolean
onClick?: (
oldValue: V,
newValue: V,
) => (e?: React.MouseEvent<HTMLButtonElement, MouseEvent>) => void
}
19 changes: 14 additions & 5 deletions packages/types/lib/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ export interface Config<Client extends boolean = false>
database: {
schemas: Schema[]
settings: {
extraUserFields: string[]
} & BaseConfig['database']['settings']
extraUserFields: (ExtraField | string)[]
} & Omit<BaseConfig['database']['settings'], 'extraUserFields'>
} & BaseConfig['database']
scanner: {
scanNext: {
Expand All @@ -130,6 +130,12 @@ export interface Config<Client extends boolean = false>
manualAreas: ExampleConfig['manualAreas'][number][]
}

export interface ExtraField {
name: string
database: string
disabled: boolean
}

export interface Webhook {
enabled: boolean
provider: 'poracle'
Expand Down Expand Up @@ -163,7 +169,7 @@ export type DeepKeys<T, P extends string = ''> = {
: never
}[keyof T]

export type ConfigPaths = DeepKeys<Config>
export type ConfigPaths<T extends object> = DeepKeys<T>

export type PathValue<T, P> = P extends `${infer K}.${infer Rest}`
? K extends keyof T
Expand All @@ -175,7 +181,10 @@ export type PathValue<T, P> = P extends `${infer K}.${infer Rest}`
? T[P]
: never

export type ConfigPathValue<P extends ConfigPaths> = PathValue<Config, P>
export type ConfigPathValue<
T extends object,
P extends ConfigPaths<T>,
> = PathValue<T, P>

export type Join<K, P> = K extends string | number
? P extends string | number
Expand Down Expand Up @@ -223,4 +232,4 @@ export type NestedObjectPaths = Paths<Config>

export type GetSafeConfig = <P extends NestedObjectPaths>(
path: P,
) => ConfigPathValue<P>
) => ConfigPathValue<Config, P>
26 changes: 26 additions & 0 deletions packages/types/lib/general.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type RMGeoJSON = {

import masterfile = require('packages/masterfile/lib/data/masterfile.json')
import { Config } from './config'
import { SliderProps } from '@mui/material'

export type Masterfile = typeof masterfile

Expand Down Expand Up @@ -99,3 +100,28 @@ export type UAssetsClient = Config['icons']['styles'][number] & { data: UICONS }
export type FullClientIcons = Omit<Config['icons'], 'styles'> & {
styles: (Config['icons']['styles'][number] & { data: UICONS })[]
}

export interface RMSlider extends SliderProps {
label?: string
perm?: string
step?: number
i18nKey?: string
disabled?: boolean
low?: number
high?: number
i18nKey?: string
markI18n?: string
noTextInput?: boolean
marks?: number[]
}

export type RMSliderHandleChange<N extends string = string> = (
name: N,
values: number | number[],
) => void

export interface RMSliderProps {
slide: RMSlider
values: number[]
handleChange: RMSliderHandleChange
}
2 changes: 2 additions & 0 deletions packages/types/lib/scanner.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export interface Gym {
power_up_level: number
power_up_points: number
power_up_end_timestamp: number
deleted: boolean
enabled: boolean
}

export type FullGym = FullModel<Gym, GymModel>
Expand Down
19 changes: 18 additions & 1 deletion packages/types/lib/server.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Backup = require('server/src/models/Backup')
import Nest = require('server/src/models/Nest')
import NestSubmission = require('server/src/models/NestSubmission')
import Pokestop = require('server/src/models/Pokestop')
import { ModelReturn } from './utility'
import { ModelReturn, OnlyType } from './utility'
import { Profile } from 'passport-discord'
import { User } from './models'

Expand Down Expand Up @@ -235,3 +235,20 @@ export type DiscordVerifyFunction = (
profile: Profile,
done: VerifyCallback,
) => void

export type BaseFilter = import('server/src/services/filters/Base')

export type PokemonFilter =
import('server/src/services/filters/pokemon/Frontend')

export type AllFilters = ReturnType<
typeof import('server/src/services/filters/builder/base')
>

export type Categories = keyof AllFilters

export type AdvCategories = 'pokemon' | 'gyms' | 'pokestops' | 'nests'

export type UIObject = ReturnType<
typeof import('server/src/services/ui/primary')
>
1 change: 1 addition & 0 deletions packages/types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"devDependencies": {
"@apollo/client": "^3.7.15",
"@mui/material": "^5.14.0",
"@mui/system": "^5.15.2",
"@sentry/node": "^7.48.0",
"@types/config": "^3.3.0",
"@types/node": "^20.5.1",
Expand Down
2 changes: 1 addition & 1 deletion server/src/graphql/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ async function startApollo(httpServer) {
async requestDidStart(requestContext) {
requestContext.contextValue.startTime = Date.now()

log.debug(requestContext.request?.variables?.filters)
return {
async willSendResponse(context) {
const filterCount = Object.keys(
Expand All @@ -98,7 +99,6 @@ async function startApollo(httpServer) {

const data = response.body.singleResult.data?.[endpoint]
const returned = Array.isArray(data) ? data.length : 0

log.info(
HELPERS[endpoint] || `[${endpoint?.toUpperCase()}]`,
'|',
Expand Down
26 changes: 13 additions & 13 deletions server/src/models/Gym.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,16 @@ class Gym extends Model {
)

teams.forEach((team) => {
let slotCount = 0
slots.forEach((slot) => {
if (slot.team === team) {
slotCount += 1
finalSlots[team].push(+slot.slots)
}
})
const all = args.filters[`t${team}-0`]?.all
let slotCount = all ? baseGymSlotAmounts.length : 0
if (!all) {
slots.forEach((slot) => {
if (slot.team === team) {
slotCount += 1
finalSlots[team].push(+slot.slots)
}
})
}
if (slotCount === baseGymSlotAmounts.length || team == 0) {
delete finalSlots[team]
finalTeams.push(+team)
Expand Down Expand Up @@ -436,12 +439,9 @@ class Gym extends Model {
.then((r) => {
const unique = new Set()
r.forEach((result) => {
if (result.team) {
if (result.slots) {
unique.add(`g${result.team}-${result.slots}`)
} else {
unique.add(`t${result.team}-0`)
}
if (result.team !== null && result.slots !== null) {
unique.add(`t${result.team}-0`)
unique.add(`g${result.team}-${6 - result.slots}`)
}
})
return [...unique]
Expand Down
7 changes: 3 additions & 4 deletions server/src/models/Pokestop.js
Original file line number Diff line number Diff line change
Expand Up @@ -870,10 +870,9 @@ class Pokestop extends Model {
if (
quest.quest_timestamp >= midnight &&
(filters.onlyAllPokestops ||
(filters[newQuest.key] &&
(filters[newQuest.key].adv
? filters[newQuest.key].adv.includes(quest.quest_title)
: true)) ||
(filters[newQuest.key]?.adv && !filters[newQuest.key].all
? filters[newQuest.key].adv.includes(quest.quest_title)
: true) ||
filters[`u${quest.quest_reward_type}`])
) {
this.fieldAssigner(newQuest, quest, fields)
Expand Down
12 changes: 12 additions & 0 deletions server/src/services/filters/builder/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function buildDefaultFilters(perms, database) {
: undefined,
badge: perms.gymBadges ? 'all' : undefined,
raidTier: perms.raids ? 'all' : undefined,
standard: new BaseFilter(),
filter: {
...buildGyms(perms, defaultFilters.gyms),
...pokemon.raids,
Expand All @@ -67,6 +68,7 @@ function buildDefaultFilters(perms, database) {
pokemon: defaultFilters.nests.pokemon,
polygons: defaultFilters.nests.polygons,
avgFilter: defaultFilters.nests.avgFilter,
standard: new BaseFilter(),
filter: pokemon.nests,
}
: undefined,
Expand All @@ -93,6 +95,7 @@ function buildDefaultFilters(perms, database) {
? defaultFilters.pokestops.invasions
: undefined,
arEligible: perms.pokestops ? false : undefined,
standard: new BaseFilter(),
filter: {
...pokemon.rocket,
...buildPokestops(perms, defaultFilters.pokestops),
Expand Down Expand Up @@ -130,6 +133,7 @@ function buildDefaultFilters(perms, database) {
0,
Math.ceil(database.filterContext.Route.maxDistance / 1000) + 1,
],
standard: new BaseFilter(),
filter: {
global: new BaseFilter(),
},
Expand All @@ -139,6 +143,7 @@ function buildDefaultFilters(perms, database) {
perms.portals && database.models.Portal
? {
enabled: defaultFilters.portals.enabled,
standard: new BaseFilter(),
filter: {
global: new BaseFilter(),
old: new BaseFilter(),
Expand All @@ -149,6 +154,7 @@ function buildDefaultFilters(perms, database) {
scanAreas: perms.scanAreas
? {
enabled: defaultFilters.scanAreas.enabled,
standard: new BaseFilter(),
filterByAreas: false,
filter: { areas: [], search: '' },
}
Expand All @@ -161,27 +167,31 @@ function buildDefaultFilters(perms, database) {
s17Cells: defaultFilters.submissionCells.s17Cells,
s14Cells: defaultFilters.submissionCells.s14Cells,
includeSponsored: defaultFilters.submissionCells.includeSponsored,
standard: new BaseFilter(),
filter: { global: new BaseFilter() },
}
: undefined,
s2cells: perms.s2cells
? {
enabled: defaultFilters.s2cells.enabled,
cells: defaultFilters.s2cells.cells,
standard: new BaseFilter(),
filter: { global: new BaseFilter() },
}
: undefined,
weather:
perms.weather && database.models.Weather
? {
enabled: defaultFilters.weather.enabled,
standard: new BaseFilter(),
filter: { global: new BaseFilter() },
}
: undefined,
spawnpoints:
perms.spawnpoints && database.models.Spawnpoint
? {
enabled: defaultFilters.spawnpoints.enabled,
standard: new BaseFilter(),
tth: defaultFilters.spawnpoints.tth,
filter: {
global: new BaseFilter(),
Expand All @@ -194,13 +204,15 @@ function buildDefaultFilters(perms, database) {
perms.scanCells && database.models.ScanCell
? {
enabled: defaultFilters.scanCells.enabled,
standard: new BaseFilter(),
filter: { global: new BaseFilter() },
}
: undefined,
devices:
perms.devices && database.models.Device
? {
enabled: defaultFilters.devices.enabled,
standard: new BaseFilter(),
filter: {
online: new BaseFilter(),
offline: new BaseFilter(),
Expand Down
3 changes: 1 addition & 2 deletions server/src/services/filters/builder/gym.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ const BaseFilter = require('../Base')
*
* @param {import("@rm/types").Permissions} perms
* @param {import("@rm/types").Config['defaultFilters']['gyms']} defaults
* @returns
*/
function buildGyms(perms, defaults) {
const gymFilters = {}
const gymFilters = /** @type {Record<string, BaseFilter>} */ ({})

if (perms.gyms) {
Object.keys(Event.masterfile.teams).forEach((team, i) => {
Expand Down
Loading