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

chore: enable edit all person attributes in edit mode #16

Merged
merged 4 commits into from
Aug 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
46 changes: 37 additions & 9 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ function App(props: AppProps) {
const [trees, setTreesValue] = useCache('trees', props.trees);

const [split, setSplitValue] = useCache('split', !!props.split);
const [hidePersonCode, setHideCode] = useCache('hideCode', false);
const [showPersonCode, setShowCode] = useCache('showPersonCode', true);
const [showSex, setShowSex] = useCache('showSex', false);
const [showDeathdate, setShowDeathdate] = useCache('showDeathdate', false);
const [editMode, setEditModeValue] = useState(false);

const [modalPerson, setModalPerson] = useState(null as Person | null);
Expand Down Expand Up @@ -79,7 +81,9 @@ function App(props: AppProps) {
value={{
split,
editMode,
hidePersonCode,
showPersonCode,
showSex,
showDeathdate,
treeMap,
setTreesValue,
upsertPerson,
Expand All @@ -96,18 +100,42 @@ function App(props: AppProps) {
onChange={() => setSplitValue(!split)}
/>
<Label for="split-switch" check>
Split Family
Split family
</Label>
</FormGroup>
<FormGroup switch>
<Input
type="switch"
checked={hidePersonCode}
id="hidePersonCode-switch"
onChange={() => setHideCode(!hidePersonCode)}
checked={showPersonCode}
id="showPersonCode-switch"
onChange={() => setShowCode(!showPersonCode)}
/>
<Label for="hidePersonCode-switch" check>
Hide Code
<Label for="showPersonCode-switch" check>
Show person code
</Label>
</FormGroup>
<FormGroup switch>
<Input
type="switch"
checked={editMode || showSex}
id="showSex-switch"
disabled={editMode}
onChange={() => setShowSex(!showSex)}
/>
<Label for="showSex-switch" check>
Show person sex
</Label>
</FormGroup>
<FormGroup switch>
<Input
type="switch"
checked={editMode || showDeathdate}
id="showDeathdate-switch"
disabled={editMode}
onChange={() => setShowDeathdate(!showDeathdate)}
/>
<Label for="showDeathdate-switch" check>
Show person death date
</Label>
</FormGroup>
<FormGroup switch>
Expand All @@ -118,7 +146,7 @@ function App(props: AppProps) {
onChange={() => setEditModeValue(!editMode)}
/>
<Label for="editMode-switch" check>
Edit Mode
Edit mode
</Label>
</FormGroup>
<FormGroup>
Expand Down
8 changes: 6 additions & 2 deletions src/components/AppContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { Person } from '../family.interface';
interface AppContextValue {
split: boolean;
editMode: boolean;
hidePersonCode: boolean;
showPersonCode: boolean;
showSex: boolean;
showDeathdate: boolean;
setTreesValue: (ps: Person[]) => void;
upsertPerson: (p: Person) => void;
deletePerson: (p: Person) => void;
Expand All @@ -14,7 +16,9 @@ interface AppContextValue {
const AppContext = createContext<AppContextValue>({
split: false,
editMode: false,
hidePersonCode: false,
showPersonCode: false,
showSex: false,
showDeathdate: false,
setTreesValue: () => {},
upsertPerson: () => {},
deletePerson: () => {},
Expand Down
59 changes: 49 additions & 10 deletions src/components/FamilyGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,21 @@ interface FamilyGridProps {
}

export default function FamilyGrid({ trees }: FamilyGridProps) {
const { hidePersonCode } = useContext(AppContext);
const { editMode, showPersonCode, showSex, showDeathdate } =
useContext(AppContext);

return (
<Table size="sm" bordered hover responsive>
<thead>
<tr>
<th style={{ width: '7em' }} hidden={hidePersonCode}>
Code
</th>
{showPersonCode && <th style={{ width: '7em' }}>Code</th>}
<th style={{ width: '15.5em' }}>Name</th>
<th style={{ width: '7em' }}>Birthplace</th>
<th style={{ width: '7em' }}>Birthdate</th>
{(editMode || showSex) && <th style={{ width: '5em' }}>Sex</th>}
<th style={{ width: '7em' }}>Birth place</th>
<th style={{ width: '7em' }}>Birth date</th>
{(editMode || showDeathdate) && (
<th style={{ width: '7em' }}>Death date</th>
)}
<th style={{ width: '8.5em' }}>Phone</th>
<th style={{ width: '18.5em' }}>Address</th>
<th style={{ width: '8.5em' }}>IG</th>
Expand Down Expand Up @@ -58,7 +61,8 @@ function FamilyRows({ person, ...props }: PersonRowProps) {
}

function PersonRow({ person }: PersonRowProps) {
const { editMode, hidePersonCode, upsertPerson } = useContext(AppContext);
const { editMode, showPersonCode, showSex, showDeathdate, upsertPerson } =
useContext(AppContext);
const name = person.name || person.id;

const updatePerson = function (e: ChangeEvent<any>, key: string) {
Expand All @@ -71,12 +75,18 @@ function PersonRow({ person }: PersonRowProps) {
inputClass = 'd-print-none';
spanClass = 'd-none d-print-block';
}
const sexMap: Record<string, string> = {
F: 'Female',
M: 'Male',
};

return (
<tr>
<td hidden={hidePersonCode}>
<span>{person.code}</span>
</td>
{showPersonCode && (
<td>
<span>{person.code}</span>
</td>
)}
<td>
<Input
bsSize="sm"
Expand All @@ -90,6 +100,24 @@ function PersonRow({ person }: PersonRowProps) {
{person.name && <small className="fw-light"> ({person.id})</small>}
</span>
</td>
{(editMode || showSex) && (
<td>
<Input
type="select"
bsSize="sm"
className={inputClass}
value={person.sex || ''}
onChange={e => updatePerson(e, 'sex')}
>
<option value=""></option>
<option value="M">{sexMap.M}</option>
<option value="F">{sexMap.F}</option>
</Input>
<span className={spanClass}>
{person.sex ? sexMap[person.sex] || '' : ''}
</span>
</td>
)}
<td>
<Input
bsSize="sm"
Expand All @@ -108,6 +136,17 @@ function PersonRow({ person }: PersonRowProps) {
/>
<span className={spanClass}>{person.birthdate}</span>
</td>
{(editMode || showDeathdate) && (
<td>
<Input
bsSize="sm"
className={inputClass}
value={person.deathdate || ''}
onChange={e => updatePerson(e, 'deathdate')}
/>
<span className={spanClass}>{person.deathdate}</span>
</td>
)}
<td>
<Input
bsSize="sm"
Expand Down
Loading