Skip to content

Commit

Permalink
feat: show child entries for all supported entity types
Browse files Browse the repository at this point in the history
Fixes #82
  • Loading branch information
eXaminator committed Oct 20, 2021
1 parent 92087fd commit b97ffe6
Show file tree
Hide file tree
Showing 22 changed files with 235 additions and 38 deletions.
13 changes: 12 additions & 1 deletion src/KankaJournal/shared/baseLayout.partial.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
{{/if}}
</h1>


<nav class="tabs" data-group="primary-tabs">
{{>tabNav name='story' label='shared.tabs.story'}}
{{#unless (kankaHasOnlyPinned kankaEntity.attributes 'is_star')}}
Expand All @@ -25,6 +24,15 @@
collection=kankaEntity.attributes
}}
{{/unless}}
{{#if kankaEntity.children.length}}
{{>tabNav
name='children'
labelString=(kankaLocalize 'entityType' kankaEntityType)
collection=kankaEntity.children
idProperty='entity_id'
showCount=true
}}
{{/if}}
{{#>nav}}{{/nav}}
{{>tabNav
name='relations'
Expand Down Expand Up @@ -93,6 +101,9 @@
<div class="tab -scrollable" data-tab="attributes" data-group="primary-tabs">
{{>tabs/attributes entity=kankaEntity}}
</div>
<div class="tab -scrollable" data-tab="children" data-group="primary-tabs">
{{>tabs/children entity=kankaEntity}}
</div>
<div class="tab -scrollable" data-tab="relations" data-group="primary-tabs">
{{>tabs/relations entity=kankaEntity}}
</div>
Expand Down
6 changes: 5 additions & 1 deletion src/KankaJournal/shared/tabNav.partial.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{{#with (lookup (kankaFilterReferences collection idProperty type optionalReference=optionalReference) 'length') as |count| }}
{{#if (kankaOr count (kankaEq ../collection undefined))}}
<a class="item" data-tab="{{../name}}">
{{ kankaLocalize 'journal' ../label }}
{{#if ../labelString}}
{{../labelString}}
{{else}}
{{ kankaLocalize 'journal' ../label }}
{{/if}}
{{#if ../showCount}}<span class="counter">{{count}}</span>{{/if}}
</a>
{{/if}}
Expand Down
17 changes: 17 additions & 0 deletions src/KankaJournal/shared/tabs/children.partial.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<ul class="kanka-cards">
{{#each (kankaFilterReferences entity.children 'entity_id') as |rel|}}
{{#with (kankaFindReference rel.entity_id) as | ref | }}
<li class="kanka-card {{#if (kankaIsSecret ref) }}-secret{{/if}}">
<div class="kanka-avatar">
{{#if ref.thumb}}
<img src="{{ref.thumb}}" alt="{{ref.name}}" />
{{/if}}
</div>

<h2 class="kanka-card-header">{{{ kankaLinkReference ref }}}</h2>

<div class="kanka-card-content">{{{ rel.type }}}</div>
</li>
{{/with}}
{{/each}}
</ul>
33 changes: 0 additions & 33 deletions src/KankaJournal/sheets/ability.partial.hbs
Original file line number Diff line number Diff line change
@@ -1,40 +1,7 @@
{{#>../shared/baseLayout}}
{{#*inline 'nav'}}
{{>../shared/tabNav
name='abilities'
label='shared.tabs.abilities'
collection=kankaEntity.abilities
idProperty='this'
type='ability'
showCount=true
}}
{{~/inline}}

{{#*inline 'profile'~}}
{{~>../shared/detailRow value=kankaEntity.type label='shared.labels.type' }}
{{~>../shared/detailRowAncestors ancestors=kankaEntity.ancestors label='shared.labels.parent' }}
{{~>../shared/detailRow value=kankaEntity.charges label='ability.labels.charges' }}
{{~/inline}}

{{#*inline 'content'}}
<div class="tab -scrollable" data-tab="abilities" data-group="primary-tabs">
<ul class="kanka-cards">
{{#each kankaEntity.abilities }}
{{#with this as | rel | }}
{{#with (kankaFindReference rel 'ability') as | ability | }}
<li class="kanka-card {{#if (kankaIsSecret ability rel) }}-secret{{/if}}">
<div class="kanka-avatar">
{{#if ability.thumb}}
<img src="{{ability.thumb}}" alt="{{ability.name}}">
{{/if}}
</div>

<h2 class="kanka-card-header">{{{ kankaLinkReference ability }}}</h2>
</li>
{{/with}}
{{/with}}
{{/each}}
</ul>
</div>
{{~/inline}}
{{/../shared/baseLayout}}
9 changes: 9 additions & 0 deletions src/api/KankaApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,15 @@ export default class KankaApi {
entity.ancestors.unshift(parent.entity_id);
current = parent;
}

// eslint-disable-next-line no-param-reassign
entity.children = entities
.filter(e => e[parentProperty] === entity.id)
.map(e => ({
// eslint-disable-next-line @typescript-eslint/naming-convention
entity_id: e.entity_id,
type: e.type,
}));
});

return entities;
Expand Down
5 changes: 3 additions & 2 deletions src/module/TypeLoaders/AbilityTypeLoader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function createAbility(data: Partial<KankaApiAbility> = {}): KankaApiAbility {
return {
abilities: [],
ancestors: [],
children: [],
relations: [],
inventory: [],
entity_abilities: [],
Expand Down Expand Up @@ -201,9 +202,9 @@ describe('AbilityTypeLoader', () => {
});
});

it('includes abilities from the lookup array', async () => {
it('includes children from the lookup array', async () => {
const expectedResult = createAbility({
abilities: [2002],
children: [{ entity_id: 1002 }],
});

const entities = [
Expand Down
2 changes: 1 addition & 1 deletion src/module/TypeLoaders/AbilityTypeLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export default class AbilityTypeLoader extends AbstractTypeLoader<KankaApiAbilit

await Promise.all([
collection.addById(entity.ability_id, 'ability'),
...entity.abilities.map(ability => collection.addById(ability, 'ability')),
...entity.ancestors.map(ancestor => collection.addByEntityId(ancestor)),
...entity.children.map(child => collection.addByEntityId(child.entity_id)),
]);

return collection;
Expand Down
24 changes: 24 additions & 0 deletions src/module/TypeLoaders/FamilyTypeLoader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function createFamily(data: Partial<KankaApiFamily> = {}): KankaApiFamily {
return {
members: [],
ancestors: [],
children: [],
relations: [],
inventory: [],
entity_abilities: [],
Expand Down Expand Up @@ -201,6 +202,29 @@ describe('FamilyTypeLoader', () => {
});
});

it('includes children from the lookup array', async () => {
const expectedResult = createFamily({
children: [{ entity_id: 1002 }],
});

const entities = [
createEntity(1001, 2001, 'location'),
createEntity(1002, 2002, 'family'),
createEntity(1003, 2003, 'quest'),
];

const loader = new FamilyTypeLoader(api);
const collection = await loader.createReferenceCollection(4711, expectedResult, entities);

expect(collection.getRecord()).toMatchObject({
1002: {
id: 2002,
entityId: 1002,
type: 'family',
},
});
});

it('includes members from the lookup array', async () => {
const expectedResult = createFamily({
members: [2002],
Expand Down
1 change: 1 addition & 0 deletions src/module/TypeLoaders/FamilyTypeLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export default class FamilyTypeLoader extends AbstractTypeLoader<KankaApiFamily>
collection.addById(entity.family_id, 'family'),
...entity.ancestors.map(ancestor => collection.addByEntityId(ancestor)),
...entity.members.map(member => collection.addById(member, 'character')),
...entity.children.map(child => collection.addByEntityId(child.entity_id)),
]);

return collection;
Expand Down
24 changes: 24 additions & 0 deletions src/module/TypeLoaders/JournalTypeLoader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function createJournal(data: Partial<KankaApiJournal> = {}): KankaApiJournal {
inventory: [],
entity_abilities: [],
ancestors: [],
children: [],
...data,
} as KankaApiJournal;
}
Expand Down Expand Up @@ -177,6 +178,29 @@ describe('JournalTypeLoader', () => {
});
});

it('includes children from the lookup array', async () => {
const expectedResult = createJournal({
children: [{ entity_id: 1002 }],
});

const entities = [
createEntity(1001, 2001, 'location'),
createEntity(1002, 2002, 'journal'),
createEntity(1003, 2003, 'quest'),
];

const loader = new JournalTypeLoader(api);
const collection = await loader.createReferenceCollection(4711, expectedResult, entities);

expect(collection.getRecord()).toMatchObject({
1002: {
id: 2002,
entityId: 1002,
type: 'journal',
},
});
});

it('includes parent from the lookup array', async () => {
const expectedResult = createJournal({
journal_id: 2002,
Expand Down
1 change: 1 addition & 0 deletions src/module/TypeLoaders/JournalTypeLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class JournalTypeLoader extends AbstractTypeLoader<KankaApiJourna
collection.addById(entity.location_id, 'location'),
collection.addById(entity.character_id, 'character'),
...entity.ancestors.map(ancestor => collection.addByEntityId(ancestor)),
...entity.children.map(child => collection.addByEntityId(child.entity_id)),
]);

return collection;
Expand Down
24 changes: 24 additions & 0 deletions src/module/TypeLoaders/LocationTypeLoader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function createLocation(data: Partial<KankaApiLocation> = {}): KankaApiLocation
inventory: [],
entity_abilities: [],
ancestors: [],
children: [],
...data,
} as KankaApiLocation;
}
Expand Down Expand Up @@ -177,6 +178,29 @@ describe('LocationTypeLoader', () => {
});
});

it('includes children from the lookup array', async () => {
const expectedResult = createLocation({
children: [{ entity_id: 1002 }],
});

const entities = [
createEntity(1001, 2001, 'location'),
createEntity(1002, 2002, 'location'),
createEntity(1003, 2003, 'quest'),
];

const loader = new LocationTypeLoader(api);
const collection = await loader.createReferenceCollection(4711, expectedResult, entities);

expect(collection.getRecord()).toMatchObject({
1002: {
id: 2002,
entityId: 1002,
type: 'location',
},
});
});

it('includes parent from the lookup array', async () => {
const expectedResult = createLocation({
parent_location_id: 2002,
Expand Down
1 change: 1 addition & 0 deletions src/module/TypeLoaders/LocationTypeLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default class LocationTypeLoader extends AbstractTypeLoader<KankaApiLocat
await Promise.all([
collection.addById(entity.parent_location_id, 'location'),
...entity.ancestors.map(ancestor => collection.addByEntityId(ancestor)),
...entity.children.map(child => collection.addByEntityId(child.entity_id)),
]);

return collection;
Expand Down
24 changes: 24 additions & 0 deletions src/module/TypeLoaders/NoteTypeLoader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function createNote(data: Partial<KankaApiNote> = {}): KankaApiNote {
inventory: [],
entity_abilities: [],
ancestors: [],
children: [],
...data,
} as KankaApiNote;
}
Expand Down Expand Up @@ -177,6 +178,29 @@ describe('NoteTypeLoader', () => {
});
});

it('includes children from the lookup array', async () => {
const expectedResult = createNote({
children: [{ entity_id: 1002 }],
});

const entities = [
createEntity(1001, 2001, 'location'),
createEntity(1002, 2002, 'note'),
createEntity(1003, 2003, 'quest'),
];

const loader = new NoteTypeLoader(api);
const collection = await loader.createReferenceCollection(4711, expectedResult, entities);

expect(collection.getRecord()).toMatchObject({
1002: {
id: 2002,
entityId: 1002,
type: 'note',
},
});
});

it('includes parent from the lookup array', async () => {
const expectedResult = createNote({
note_id: 2002,
Expand Down
1 change: 1 addition & 0 deletions src/module/TypeLoaders/NoteTypeLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default class NoteTypeLoader extends AbstractTypeLoader<KankaApiNote> {
await Promise.all([
collection.addById(entity.note_id, 'note'),
...entity.ancestors.map(ancestor => collection.addByEntityId(ancestor)),
...entity.children.map(child => collection.addByEntityId(child.entity_id)),
]);

return collection;
Expand Down
24 changes: 24 additions & 0 deletions src/module/TypeLoaders/OrganisationTypeLoader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function createOrganisation(data: Partial<KankaApiOrganisation> = {}): KankaApiO
return {
members: [],
ancestors: [],
children: [],
relations: [],
inventory: [],
entity_abilities: [],
Expand Down Expand Up @@ -202,6 +203,29 @@ describe('OrganisationTypeLoader', () => {
});
});

it('includes children from the lookup array', async () => {
const expectedResult = createOrganisation({
children: [{ entity_id: 1002 }],
});

const entities = [
createEntity(1001, 2001, 'location'),
createEntity(1002, 2002, 'organisation'),
createEntity(1003, 2003, 'quest'),
];

const loader = new OrganisationTypeLoader(api);
const collection = await loader.createReferenceCollection(4711, expectedResult, entities);

expect(collection.getRecord()).toMatchObject({
1002: {
id: 2002,
entityId: 1002,
type: 'organisation',
},
});
});

it('includes members from the lookup array', async () => {
const expectedResult = createOrganisation({
members: [{ character_id: 2002 } as KankaApiCharacterOrganisationLink],
Expand Down
1 change: 1 addition & 0 deletions src/module/TypeLoaders/OrganisationTypeLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export default class OrganisationTypeLoader extends AbstractTypeLoader<KankaApiO
collection.addById(entity.location_id, 'location'),
...entity.ancestors.map(ancestor => collection.addByEntityId(ancestor)),
...entity.members.map(member => collection.addById(member.character_id, 'character')),
...entity.children.map(child => collection.addByEntityId(child.entity_id)),
]);

return collection;
Expand Down
Loading

0 comments on commit b97ffe6

Please sign in to comment.