[CORL 547] org-wide announcements (#2813)

* CRUD announcements

* only show announcement if not disabled

* make announcements dismissable

* add announcement mutations

* update announcement form logic

* style announcements on stream

* update snap

* localize strings

* close form if announcement is removed

* move announcement config below sitewide commenting config

* move date calculation inside useMemo

* move announcementconfig code to announcementconfigcontainer

* use coralContext for localStorage

* fix type of announcement createdAt

* move announcement form to modal

* remove payload pruning from configure route

* simplify announcement display logic

* make validation message full width

Co-authored-by: Kim Gardner <kgardnr@gmail.com>
This commit is contained in:
Tessa Thornton
2020-02-03 13:12:25 -05:00
committed by GitHub
co-authored by Kim Gardner
parent a7b2af85fc
commit a1a8652f7e
29 changed files with 855 additions and 1 deletions
@@ -1,6 +1,8 @@
import GraphContext from "coral-server/graph/context";
import { Tenant } from "coral-server/models/tenant";
import {
createAnnouncement,
deleteAnnouncement,
disableFeatureFlag,
enableFeatureFlag,
regenerateSSOKey,
@@ -8,6 +10,7 @@ import {
} from "coral-server/services/tenant";
import {
GQLCreateAnnouncementInput,
GQLFEATURE_FLAG,
GQLUpdateSettingsInput,
} from "coral-server/graph/schema/__generated__/types";
@@ -28,4 +31,8 @@ export const Settings = ({
enableFeatureFlag(mongo, redis, tenantCache, tenant, flag),
disableFeatureFlag: (flag: GQLFEATURE_FLAG) =>
disableFeatureFlag(mongo, redis, tenantCache, tenant, flag),
createAnnouncement: (input: GQLCreateAnnouncementInput) =>
createAnnouncement(mongo, redis, tenantCache, tenant, input, now),
deleteAnnouncement: () =>
deleteAnnouncement(mongo, redis, tenantCache, tenant),
});
@@ -237,4 +237,12 @@ export const Mutation: Required<GQLMutationTypeResolver<void>> = {
flags: await ctx.mutators.Settings.disableFeatureFlag(input.flag),
clientMutationId: input.clientMutationId,
}),
createAnnouncement: async (source, { input }, ctx) => ({
settings: await ctx.mutators.Settings.createAnnouncement(input),
clientMutationId: input.clientMutationId,
}),
deleteAnnouncement: async (source, { input }, ctx) => ({
settings: await ctx.mutators.Settings.deleteAnnouncement(),
clientMutationId: input.clientMutationId,
}),
};
+6 -1
View File
@@ -1,4 +1,7 @@
import { Tenant } from "coral-server/models/tenant";
import {
retrieveAnnouncementIfEnabled,
Tenant,
} from "coral-server/models/tenant";
import {
GQLFEATURE_FLAG,
@@ -18,4 +21,6 @@ export const Settings: GQLSettingsTypeResolver<Tenant> = {
slack: ({ slack = {} }) => slack,
featureFlags: ({ featureFlags = [] }) =>
featureFlags.filter(filterValidFeatureFlags()),
announcement: ({ announcement }) =>
retrieveAnnouncementIfEnabled(announcement),
};
@@ -1215,6 +1215,37 @@ type NewCommentersConfiguration {
approvedCommentsThreshold: Int!
}
"""
Announcement is an organization-wide announcement displayed above the stream
for a set duration
"""
type Announcement {
"""
id is a canonical identifier for this Annoucnement, used to dismiss on front-end.
"""
id: ID!
"""
createdAt is the creation date.
"""
createdAt: Time!
"""
disableAt is the computed date at which announcement will be invalid.
"""
disableAt: Time!
"""
duration determines how long the announcement will be valid for.
"""
duration: Int!
"""
content is the content displayed for the announcement.
"""
content: String!
}
"""
Settings stores the global settings for a given Tenant.
"""
@@ -1365,6 +1396,8 @@ type Settings {
newCommenters is the configuration for how new commenters comments are treated.
"""
newCommenters: NewCommentersConfiguration! @auth(roles: [ADMIN])
announcement: Announcement
}
################################################################################
@@ -3353,6 +3386,44 @@ input RecentCommentHistoryConfigurationInput {
triggerRejectionRate: Float
}
input CreateAnnouncementInput {
"""
content of the announcement.
"""
content: String!
duration: Int!
"""
clientMutationId is required for Relay support.
"""
clientMutationId: String!
}
input DeleteAnnouncementInput {
"""
clientMutationId is required for Relay support.
"""
clientMutationId: String!
}
type CreateAnnouncementPayload {
"""
clientMutationId is required for Relay support.
"""
clientMutationId: String!
settings: Settings!
}
type DeleteAnnouncementPayload {
"""
clientMutationId is required for Relay support.
"""
clientMutationId: String!
settings: Settings!
}
input SettingsCommunityGuidelinesInput {
"""
enable set to true will show the guidelines above the message box.
@@ -5763,6 +5834,14 @@ type Mutation {
disableFeatureFlag(
input: DisableFeatureFlagInput!
): DisableFeatureFlagPayload! @auth(roles: [ADMIN])
createAnnouncement(
input: CreateAnnouncementInput!
): CreateAnnouncementPayload! @auth(roles: [ADMIN])
deleteAnnouncement(
input: DeleteAnnouncementInput!
): DeleteAnnouncementPayload! @auth(roles: [ADMIN])
}
##################