Skip to content

Commit

Permalink
Load external objectives in the timeline view
Browse files Browse the repository at this point in the history
Load external objectives (objectives that the current item are
"contributors" to (as per a new `objectiveContributors` table)) in the
timeline view.

There is currently no way to create `objectiveContributors` entries in
the web UI, but this lays the groundwork for it.
  • Loading branch information
simenheg committed Aug 17, 2023
1 parent 315788e commit 962de57
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
7 changes: 7 additions & 0 deletions firestore.rules
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ service cloud.firestore {
allow delete: if isSuperAdmin();
}

/*
* TODO: Needs to be extended with rules for `create` and `delete`.
*/
match /objectiveContributors/{document} {
allow read: if isSignedIn();
}

match /periods/{document} {
allow read: if isSignedIn();
allow create: if isSuperAdmin() || isMemberOfParent(document, 'periods') || isAdminOfParent(document, 'periods');
Expand Down
15 changes: 14 additions & 1 deletion src/store/actions/set_active_period_and_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default firestoreAction(
if (!periodId && !item) {
unbindFirestoreRef('periods');
unbindFirestoreRef('objectives');
unbindFirestoreRef('objectiveContributors');
unbindFirestoreRef('activePeriod');
return false;
}
Expand All @@ -28,14 +29,26 @@ export default firestoreAction(
.where('parent', '==', parentRef)
.orderBy('name');

const objectiveContributorsRef = db
.collection('objectiveContributors')
.where('item', '==', parentRef);

const activeObjectivesList = await objectivesRef
.get()
.then((snapshot) => snapshot.docs.map((doc) => doc.ref));

if (activeObjectivesList.length) {
const objectiveContributorsList = await objectiveContributorsRef
.get()
.then((snapshot) => snapshot.docs.map((doc) => doc.ref));

if (activeObjectivesList.length || objectiveContributorsList.length) {
await bindFirestoreRef('objectives', objectivesRef, { maxRefDepth: 1 });
await bindFirestoreRef('objectiveContributors', objectiveContributorsRef, {
maxRefDepth: 1,
});
} else {
unbindFirestoreRef('objectives');
unbindFirestoreRef('objectiveContributors');
}

return true;
Expand Down
8 changes: 6 additions & 2 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,13 @@ export const storeGetters = {
},

/**
* Return `state.objectives` enriched with ID.
* Return `state.objectives` and external objectives from
* `state.objectiveContributors` enriched with ID.
*/
objectivesWithID: (state) => {
return state.objectives.map((o) => ({
const externalObjectives = state.objectiveContributors.map((oc) => oc.objective);

return state.objectives.concat(externalObjectives).map((o) => ({
...o,
id: o.id,
}));
Expand Down Expand Up @@ -294,6 +297,7 @@ export default new Vuex.Store({
activeObjective: null,
periods: [],
objectives: [],
objectiveContributors: [],
kpis: [],
subKpis: [],
loginError: null,
Expand Down

0 comments on commit 962de57

Please sign in to comment.