-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor out factionsDataGridData.tsx
- Loading branch information
Konrad Jamrozik
committed
Jun 29, 2024
1 parent
8d84155
commit bbf3cf6
Showing
2 changed files
with
62 additions
and
64 deletions.
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
57 changes: 57 additions & 0 deletions
57
web/src/components/FactionsDataGrid/factionsDataGridData.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,57 @@ | ||
import type { GridColDef, GridRenderCellParams } from '@mui/x-data-grid' | ||
import _ from 'lodash' | ||
import type { Faction } from '../../lib/codesync/GameState' | ||
import { factionPowerResolution } from '../../lib/codesync/ruleset' | ||
import { factionNameGridColDef } from '../../lib/rendering/renderFactions' | ||
import ManageFactionDialog from './ManageFactionDialog' | ||
|
||
export function getRows(factions: Faction[]): FactionRow[] { | ||
return _.map(factions, (faction: Faction) => ({ | ||
id: faction.Id, | ||
faction: faction.Name, | ||
power: Math.floor(faction.Power / factionPowerResolution), | ||
intel: faction.IntelInvested, | ||
})) | ||
} | ||
|
||
export type FactionRow = { | ||
readonly id: number | ||
readonly faction: string | ||
readonly power: number | ||
readonly intel: number | ||
} | ||
|
||
export function getColumns(factions: Faction[]): GridColDef<FactionRow>[] { | ||
return [ | ||
factionNameGridColDef, | ||
{ | ||
field: 'power', | ||
headerName: 'Power', | ||
width: 110, | ||
disableColumnMenu: true, | ||
}, | ||
{ | ||
field: 'intel', | ||
headerName: 'Intel', | ||
width: 80, | ||
disableColumnMenu: true, | ||
}, | ||
{ | ||
field: 'deploy', | ||
disableColumnMenu: true, | ||
sortable: false, | ||
headerName: '', | ||
width: 90, | ||
renderCell: ( | ||
params: GridRenderCellParams<FactionRow>, | ||
): React.JSX.Element => { | ||
const row: FactionRow = params.row | ||
|
||
const faction: Faction = _.find(factions, { | ||
Id: row.id, | ||
})! | ||
return <ManageFactionDialog faction={faction} /> | ||
}, | ||
}, | ||
] | ||
} |