Skip to content

Commit

Permalink
Merge pull request #976 from griffithlab/last-org-action-fixes
Browse files Browse the repository at this point in the history
Improvements to Most Recent Event timestamps for orgs and users
  • Loading branch information
acoffman authored Jan 10, 2024
2 parents 0462bbb + a35dd0d commit bec0439
Show file tree
Hide file tree
Showing 16 changed files with 240 additions and 144 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<td
nzRight
nzAlign="right">
{{ organization.mostRecentEvent?.createdAt | timeAgo }}
{{ organization.mostRecentActivityTimestamp | timeAgo }}
</td>
</tr>
</ng-template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ fragment OrganizationBrowseTableRowFields on Organization {
name
id
}
mostRecentEvent {
createdAt
}
mostRecentActivityTimestamp
# orgStatsHash @include(if: $cardView) {
# comments
# revisions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@
</td>
<td nzAlign="right">
<ng-container
*ngIf="user.mostRecentActionTimestamp; else eventElse">
{{ user.mostRecentActionTimestamp | timeAgo }}
*ngIf="user.mostRecentActivityTimestamp; else eventElse">
{{ user.mostRecentActivityTimestamp | timeAgo }}
</ng-container>
<ng-template #eventElse> -- </ng-template>
</td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ fragment UserBrowseTableRowFields on User {
revisions
}
profileImagePath(size: 64)
mostRecentActionTimestamp
mostRecentActivityTimestamp
}
10 changes: 6 additions & 4 deletions client/src/app/core/pipes/timeago-formatter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, Pipe } from '@angular/core'
import { Pipe } from '@angular/core'

const SECONDS_IN_MINUTE = 60
const SECONDS_IN_HOUR = SECONDS_IN_MINUTE * 60
Expand All @@ -24,14 +24,16 @@ const withYearFormatter = new Intl.DateTimeFormat('en-US', withYearOptions)

@Pipe({
name: 'timeAgo',
pure: true
pure: true,
})
export class CivicTimeagoFormatter {
transform(input: number | string): string {
if (!input) return '--'

let then: number
if (typeof input =='number') {
if (typeof input == 'number') {
then = input
} else {
} else {
then = Date.parse(input)
}

Expand Down
16 changes: 8 additions & 8 deletions client/src/app/generated/civic.apollo-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ export type GeneEdgeFieldPolicy = {
cursor?: FieldPolicy<any> | FieldReadFunction<any>,
node?: FieldPolicy<any> | FieldReadFunction<any>
};
export type LeaderboardOrganizationKeySpecifier = ('actionCount' | 'description' | 'eventCount' | 'events' | 'id' | 'memberCount' | 'members' | 'mostRecentEvent' | 'name' | 'orgAndSuborgsStatsHash' | 'orgStatsHash' | 'profileImagePath' | 'rank' | 'ranks' | 'subGroups' | 'url' | LeaderboardOrganizationKeySpecifier)[];
export type LeaderboardOrganizationKeySpecifier = ('actionCount' | 'description' | 'eventCount' | 'events' | 'id' | 'memberCount' | 'members' | 'mostRecentActivityTimestamp' | 'name' | 'orgAndSuborgsStatsHash' | 'orgStatsHash' | 'profileImagePath' | 'rank' | 'ranks' | 'subGroups' | 'url' | LeaderboardOrganizationKeySpecifier)[];
export type LeaderboardOrganizationFieldPolicy = {
actionCount?: FieldPolicy<any> | FieldReadFunction<any>,
description?: FieldPolicy<any> | FieldReadFunction<any>,
Expand All @@ -892,7 +892,7 @@ export type LeaderboardOrganizationFieldPolicy = {
id?: FieldPolicy<any> | FieldReadFunction<any>,
memberCount?: FieldPolicy<any> | FieldReadFunction<any>,
members?: FieldPolicy<any> | FieldReadFunction<any>,
mostRecentEvent?: FieldPolicy<any> | FieldReadFunction<any>,
mostRecentActivityTimestamp?: FieldPolicy<any> | FieldReadFunction<any>,
name?: FieldPolicy<any> | FieldReadFunction<any>,
orgAndSuborgsStatsHash?: FieldPolicy<any> | FieldReadFunction<any>,
orgStatsHash?: FieldPolicy<any> | FieldReadFunction<any>,
Expand Down Expand Up @@ -920,7 +920,7 @@ export type LeaderboardRankFieldPolicy = {
actionCount?: FieldPolicy<any> | FieldReadFunction<any>,
rank?: FieldPolicy<any> | FieldReadFunction<any>
};
export type LeaderboardUserKeySpecifier = ('actionCount' | 'areaOfExpertise' | 'bio' | 'country' | 'displayName' | 'email' | 'events' | 'facebookProfile' | 'id' | 'linkedinProfile' | 'mostRecentActionTimestamp' | 'mostRecentConflictOfInterestStatement' | 'mostRecentEvent' | 'mostRecentOrganizationId' | 'name' | 'notifications' | 'orcid' | 'organizations' | 'profileImagePath' | 'rank' | 'ranks' | 'role' | 'statsHash' | 'twitterHandle' | 'url' | 'username' | LeaderboardUserKeySpecifier)[];
export type LeaderboardUserKeySpecifier = ('actionCount' | 'areaOfExpertise' | 'bio' | 'country' | 'displayName' | 'email' | 'events' | 'facebookProfile' | 'id' | 'linkedinProfile' | 'mostRecentActivityTimestamp' | 'mostRecentConflictOfInterestStatement' | 'mostRecentEvent' | 'mostRecentOrganizationId' | 'name' | 'notifications' | 'orcid' | 'organizations' | 'profileImagePath' | 'rank' | 'ranks' | 'role' | 'statsHash' | 'twitterHandle' | 'url' | 'username' | LeaderboardUserKeySpecifier)[];
export type LeaderboardUserFieldPolicy = {
actionCount?: FieldPolicy<any> | FieldReadFunction<any>,
areaOfExpertise?: FieldPolicy<any> | FieldReadFunction<any>,
Expand All @@ -932,7 +932,7 @@ export type LeaderboardUserFieldPolicy = {
facebookProfile?: FieldPolicy<any> | FieldReadFunction<any>,
id?: FieldPolicy<any> | FieldReadFunction<any>,
linkedinProfile?: FieldPolicy<any> | FieldReadFunction<any>,
mostRecentActionTimestamp?: FieldPolicy<any> | FieldReadFunction<any>,
mostRecentActivityTimestamp?: FieldPolicy<any> | FieldReadFunction<any>,
mostRecentConflictOfInterestStatement?: FieldPolicy<any> | FieldReadFunction<any>,
mostRecentEvent?: FieldPolicy<any> | FieldReadFunction<any>,
mostRecentOrganizationId?: FieldPolicy<any> | FieldReadFunction<any>,
Expand Down Expand Up @@ -1284,15 +1284,15 @@ export type ObjectFieldDiffFieldPolicy = {
removedObjects?: FieldPolicy<any> | FieldReadFunction<any>,
suggestedObjects?: FieldPolicy<any> | FieldReadFunction<any>
};
export type OrganizationKeySpecifier = ('description' | 'eventCount' | 'events' | 'id' | 'memberCount' | 'members' | 'mostRecentEvent' | 'name' | 'orgAndSuborgsStatsHash' | 'orgStatsHash' | 'profileImagePath' | 'ranks' | 'subGroups' | 'url' | OrganizationKeySpecifier)[];
export type OrganizationKeySpecifier = ('description' | 'eventCount' | 'events' | 'id' | 'memberCount' | 'members' | 'mostRecentActivityTimestamp' | 'name' | 'orgAndSuborgsStatsHash' | 'orgStatsHash' | 'profileImagePath' | 'ranks' | 'subGroups' | 'url' | OrganizationKeySpecifier)[];
export type OrganizationFieldPolicy = {
description?: FieldPolicy<any> | FieldReadFunction<any>,
eventCount?: FieldPolicy<any> | FieldReadFunction<any>,
events?: FieldPolicy<any> | FieldReadFunction<any>,
id?: FieldPolicy<any> | FieldReadFunction<any>,
memberCount?: FieldPolicy<any> | FieldReadFunction<any>,
members?: FieldPolicy<any> | FieldReadFunction<any>,
mostRecentEvent?: FieldPolicy<any> | FieldReadFunction<any>,
mostRecentActivityTimestamp?: FieldPolicy<any> | FieldReadFunction<any>,
name?: FieldPolicy<any> | FieldReadFunction<any>,
orgAndSuborgsStatsHash?: FieldPolicy<any> | FieldReadFunction<any>,
orgStatsHash?: FieldPolicy<any> | FieldReadFunction<any>,
Expand Down Expand Up @@ -1844,7 +1844,7 @@ export type UpdateSourceSuggestionStatusPayloadFieldPolicy = {
clientMutationId?: FieldPolicy<any> | FieldReadFunction<any>,
sourceSuggestion?: FieldPolicy<any> | FieldReadFunction<any>
};
export type UserKeySpecifier = ('areaOfExpertise' | 'bio' | 'country' | 'displayName' | 'email' | 'events' | 'facebookProfile' | 'id' | 'linkedinProfile' | 'mostRecentActionTimestamp' | 'mostRecentConflictOfInterestStatement' | 'mostRecentEvent' | 'mostRecentOrg' | 'mostRecentOrganizationId' | 'name' | 'notifications' | 'orcid' | 'organizations' | 'profileImagePath' | 'ranks' | 'role' | 'statsHash' | 'twitterHandle' | 'url' | 'username' | UserKeySpecifier)[];
export type UserKeySpecifier = ('areaOfExpertise' | 'bio' | 'country' | 'displayName' | 'email' | 'events' | 'facebookProfile' | 'id' | 'linkedinProfile' | 'mostRecentActivityTimestamp' | 'mostRecentConflictOfInterestStatement' | 'mostRecentEvent' | 'mostRecentOrg' | 'mostRecentOrganizationId' | 'name' | 'notifications' | 'orcid' | 'organizations' | 'profileImagePath' | 'ranks' | 'role' | 'statsHash' | 'twitterHandle' | 'url' | 'username' | UserKeySpecifier)[];
export type UserFieldPolicy = {
areaOfExpertise?: FieldPolicy<any> | FieldReadFunction<any>,
bio?: FieldPolicy<any> | FieldReadFunction<any>,
Expand All @@ -1855,7 +1855,7 @@ export type UserFieldPolicy = {
facebookProfile?: FieldPolicy<any> | FieldReadFunction<any>,
id?: FieldPolicy<any> | FieldReadFunction<any>,
linkedinProfile?: FieldPolicy<any> | FieldReadFunction<any>,
mostRecentActionTimestamp?: FieldPolicy<any> | FieldReadFunction<any>,
mostRecentActivityTimestamp?: FieldPolicy<any> | FieldReadFunction<any>,
mostRecentConflictOfInterestStatement?: FieldPolicy<any> | FieldReadFunction<any>,
mostRecentEvent?: FieldPolicy<any> | FieldReadFunction<any>,
mostRecentOrg?: FieldPolicy<any> | FieldReadFunction<any>,
Expand Down
22 changes: 10 additions & 12 deletions client/src/app/generated/civic.apollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2130,7 +2130,7 @@ export type LeaderboardOrganization = {
id: Scalars['Int'];
memberCount: Scalars['Int'];
members: UserConnection;
mostRecentEvent?: Maybe<Event>;
mostRecentActivityTimestamp?: Maybe<Scalars['ISO8601DateTime']>;
name: Scalars['String'];
orgAndSuborgsStatsHash: Stats;
orgStatsHash: Stats;
Expand Down Expand Up @@ -2204,7 +2204,7 @@ export type LeaderboardUser = {
facebookProfile?: Maybe<Scalars['String']>;
id: Scalars['Int'];
linkedinProfile?: Maybe<Scalars['String']>;
mostRecentActionTimestamp?: Maybe<Scalars['ISO8601DateTime']>;
mostRecentActivityTimestamp?: Maybe<Scalars['ISO8601DateTime']>;
mostRecentConflictOfInterestStatement?: Maybe<Coi>;
mostRecentEvent?: Maybe<Event>;
mostRecentOrganizationId?: Maybe<Scalars['Int']>;
Expand Down Expand Up @@ -3167,7 +3167,7 @@ export type Organization = {
id: Scalars['Int'];
memberCount: Scalars['Int'];
members: UserConnection;
mostRecentEvent?: Maybe<Event>;
mostRecentActivityTimestamp?: Maybe<Scalars['ISO8601DateTime']>;
name: Scalars['String'];
orgAndSuborgsStatsHash: Stats;
orgStatsHash: Stats;
Expand Down Expand Up @@ -5270,7 +5270,7 @@ export type User = {
facebookProfile?: Maybe<Scalars['String']>;
id: Scalars['Int'];
linkedinProfile?: Maybe<Scalars['String']>;
mostRecentActionTimestamp?: Maybe<Scalars['ISO8601DateTime']>;
mostRecentActivityTimestamp?: Maybe<Scalars['ISO8601DateTime']>;
mostRecentConflictOfInterestStatement?: Maybe<Coi>;
mostRecentEvent?: Maybe<Event>;
mostRecentOrg?: Maybe<Organization>;
Expand Down Expand Up @@ -6277,9 +6277,9 @@ export type OrganizationsBrowseQueryVariables = Exact<{
}>;


export type OrganizationsBrowseQuery = { __typename: 'Query', organizations: { __typename: 'OrganizationConnection', totalCount: number, pageInfo: { __typename: 'PageInfo', hasNextPage: boolean, hasPreviousPage: boolean, startCursor?: string | undefined, endCursor?: string | undefined }, edges: Array<{ __typename: 'OrganizationEdge', cursor: string, node?: { __typename: 'Organization', id: number, name: string, description: string, url: string, memberCount: number, eventCount: number, subGroups: Array<{ __typename: 'Organization', name: string, id: number }>, mostRecentEvent?: { __typename: 'Event', createdAt: any } | undefined } | undefined }> } };
export type OrganizationsBrowseQuery = { __typename: 'Query', organizations: { __typename: 'OrganizationConnection', totalCount: number, pageInfo: { __typename: 'PageInfo', hasNextPage: boolean, hasPreviousPage: boolean, startCursor?: string | undefined, endCursor?: string | undefined }, edges: Array<{ __typename: 'OrganizationEdge', cursor: string, node?: { __typename: 'Organization', id: number, name: string, description: string, url: string, memberCount: number, eventCount: number, mostRecentActivityTimestamp?: any | undefined, subGroups: Array<{ __typename: 'Organization', name: string, id: number }> } | undefined }> } };

export type OrganizationBrowseTableRowFieldsFragment = { __typename: 'Organization', id: number, name: string, description: string, url: string, memberCount: number, eventCount: number, subGroups: Array<{ __typename: 'Organization', name: string, id: number }>, mostRecentEvent?: { __typename: 'Event', createdAt: any } | undefined };
export type OrganizationBrowseTableRowFieldsFragment = { __typename: 'Organization', id: number, name: string, description: string, url: string, memberCount: number, eventCount: number, mostRecentActivityTimestamp?: any | undefined, subGroups: Array<{ __typename: 'Organization', name: string, id: number }> };

export type PhenotypePopoverQueryVariables = Exact<{
phenotypeId: Scalars['Int'];
Expand Down Expand Up @@ -6541,9 +6541,9 @@ export type UsersBrowseQueryVariables = Exact<{
}>;


export type UsersBrowseQuery = { __typename: 'Query', users: { __typename: 'UserConnection', totalCount: number, pageInfo: { __typename: 'PageInfo', endCursor?: string | undefined, hasNextPage: boolean, hasPreviousPage: boolean, startCursor?: string | undefined }, edges: Array<{ __typename: 'UserEdge', cursor: string, node?: { __typename: 'User', id: number, name?: string | undefined, displayName: string, role: UserRole, profileImagePath?: string | undefined, mostRecentActionTimestamp?: any | undefined, organizations: Array<{ __typename: 'Organization', id: number, name: string }>, statsHash: { __typename: 'Stats', submittedEvidenceItems: number, revisions: number } } | undefined }> } };
export type UsersBrowseQuery = { __typename: 'Query', users: { __typename: 'UserConnection', totalCount: number, pageInfo: { __typename: 'PageInfo', endCursor?: string | undefined, hasNextPage: boolean, hasPreviousPage: boolean, startCursor?: string | undefined }, edges: Array<{ __typename: 'UserEdge', cursor: string, node?: { __typename: 'User', id: number, name?: string | undefined, displayName: string, role: UserRole, profileImagePath?: string | undefined, mostRecentActivityTimestamp?: any | undefined, organizations: Array<{ __typename: 'Organization', id: number, name: string }>, statsHash: { __typename: 'Stats', submittedEvidenceItems: number, revisions: number } } | undefined }> } };

export type UserBrowseTableRowFieldsFragment = { __typename: 'User', id: number, name?: string | undefined, displayName: string, role: UserRole, profileImagePath?: string | undefined, mostRecentActionTimestamp?: any | undefined, organizations: Array<{ __typename: 'Organization', id: number, name: string }>, statsHash: { __typename: 'Stats', submittedEvidenceItems: number, revisions: number } };
export type UserBrowseTableRowFieldsFragment = { __typename: 'User', id: number, name?: string | undefined, displayName: string, role: UserRole, profileImagePath?: string | undefined, mostRecentActivityTimestamp?: any | undefined, organizations: Array<{ __typename: 'Organization', id: number, name: string }>, statsHash: { __typename: 'Stats', submittedEvidenceItems: number, revisions: number } };

export type VariantGroupPopoverQueryVariables = Exact<{
variantGroupId: Scalars['Int'];
Expand Down Expand Up @@ -8333,9 +8333,7 @@ export const OrganizationBrowseTableRowFieldsFragmentDoc = gql`
name
id
}
mostRecentEvent {
createdAt
}
mostRecentActivityTimestamp
}
`;
export const PhenotypeBrowseTableRowFieldsFragmentDoc = gql`
Expand Down Expand Up @@ -8621,7 +8619,7 @@ export const UserBrowseTableRowFieldsFragmentDoc = gql`
revisions
}
profileImagePath(size: 64)
mostRecentActionTimestamp
mostRecentActivityTimestamp
}
`;
export const VariantGroupPopoverFieldsFragmentDoc = gql`
Expand Down
8 changes: 4 additions & 4 deletions client/src/app/generated/server.model.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3506,7 +3506,7 @@ type LeaderboardOrganization {
"""
last: Int
): UserConnection!
mostRecentEvent: Event
mostRecentActivityTimestamp: ISO8601DateTime
name: String!
orgAndSuborgsStatsHash: Stats!
orgStatsHash: Stats!
Expand Down Expand Up @@ -3598,7 +3598,7 @@ type LeaderboardUser {
facebookProfile: String
id: Int!
linkedinProfile: String
mostRecentActionTimestamp: ISO8601DateTime
mostRecentActivityTimestamp: ISO8601DateTime
mostRecentConflictOfInterestStatement: Coi
mostRecentEvent: Event
mostRecentOrganizationId: Int
Expand Down Expand Up @@ -5044,7 +5044,7 @@ type Organization {
"""
last: Int
): UserConnection!
mostRecentEvent: Event
mostRecentActivityTimestamp: ISO8601DateTime
name: String!
orgAndSuborgsStatsHash: Stats!
orgStatsHash: Stats!
Expand Down Expand Up @@ -8483,7 +8483,7 @@ type User {
facebookProfile: String
id: Int!
linkedinProfile: String
mostRecentActionTimestamp: ISO8601DateTime
mostRecentActivityTimestamp: ISO8601DateTime
mostRecentConflictOfInterestStatement: Coi
mostRecentEvent: Event
mostRecentOrganizationId: Int
Expand Down
16 changes: 8 additions & 8 deletions client/src/app/generated/server.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -16980,12 +16980,12 @@
"deprecationReason": null
},
{
"name": "mostRecentEvent",
"name": "mostRecentActivityTimestamp",
"description": null,
"args": [],
"type": {
"kind": "OBJECT",
"name": "Event",
"kind": "SCALAR",
"name": "ISO8601DateTime",
"ofType": null
},
"isDeprecated": false,
Expand Down Expand Up @@ -17522,7 +17522,7 @@
"deprecationReason": null
},
{
"name": "mostRecentActionTimestamp",
"name": "mostRecentActivityTimestamp",
"description": null,
"args": [],
"type": {
Expand Down Expand Up @@ -24358,12 +24358,12 @@
"deprecationReason": null
},
{
"name": "mostRecentEvent",
"name": "mostRecentActivityTimestamp",
"description": null,
"args": [],
"type": {
"kind": "OBJECT",
"name": "Event",
"kind": "SCALAR",
"name": "ISO8601DateTime",
"ofType": null
},
"isDeprecated": false,
Expand Down Expand Up @@ -39093,7 +39093,7 @@
"deprecationReason": null
},
{
"name": "mostRecentActionTimestamp",
"name": "mostRecentActivityTimestamp",
"description": null,
"args": [],
"type": {
Expand Down
2 changes: 1 addition & 1 deletion server/app/graphql/resolvers/top_level_users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Resolvers::TopLevelUsers < GraphQL::Schema::Resolver
when 'ROLE'
scope.reorder("users.role #{value.direction}")
when 'LAST_ACTION'
scope.reorder("users.most_recent_action_timestamp #{value.direction} NULLS LAST")
scope.reorder("users.most_recent_activity_timestamp #{value.direction} NULLS LAST")
end
end
end
6 changes: 1 addition & 5 deletions server/app/graphql/types/entities/organization_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class OrganizationType < Types::BaseObject
field :org_stats_hash, Types::StatsType, null: false
field :org_and_suborgs_stats_hash, Types::StatsType, null: false
field :members, Types::Entities::UserType.connection_type, null: false
field :most_recent_event, Types::Entities::EventType, null: true
field :most_recent_activity_timestamp, GraphQL::Types::ISO8601DateTime, null: true
field :member_count, Int, null: false
field :event_count, Int, null: false
field :ranks, Types::Entities::RanksType, null: false
Expand All @@ -29,10 +29,6 @@ def events
Loaders::AssociationLoader.for(Organization, :events).load(object)
end

def most_recent_event
Loaders::AssociationLoader.for(Organization, :most_recent_event).load(object)
end

def sub_groups
Loaders::AssociationLoader.for(Organization, :groups).load(object)
end
Expand Down
2 changes: 1 addition & 1 deletion server/app/graphql/types/entities/user_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class UserType < Types::BaseObject
field :stats_hash, Types::StatsType, null: false
field :most_recent_conflict_of_interest_statement, Types::Entities::CoiType, null: true
field :most_recent_event, Types::Entities::EventType, null: true
field :most_recent_action_timestamp, GraphQL::Types::ISO8601DateTime, null: true
field :most_recent_activity_timestamp, GraphQL::Types::ISO8601DateTime, null: true
field :most_recent_organization_id, Int, null: true
field :ranks, Types::Entities::RanksType, null: false

Expand Down
11 changes: 11 additions & 0 deletions server/app/models/activities/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def execute
link_activity
set_verbiage
after_completed
update_timestamps
end

def create_activity
Expand Down Expand Up @@ -50,5 +51,15 @@ def set_verbiage
def after_completed
#no op
end

def update_timestamps
activity.user.most_recent_activity_timestamp = activity.created_at
activity.user.save!(validate: false)

if activity.organization_id.present?
activity.organization.most_recent_activity_timestamp = activity.created_at
activity.organization.save!(validate: false)
end
end
end
end
Loading

0 comments on commit bec0439

Please sign in to comment.