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

Feat/announcement block #1497

Merged
merged 52 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
0f8d904
feat(announcements): add SCSS styles from template
dcshzj Sep 14, 2023
8f1218b
feat(announcements): introduce preview component
dcshzj Sep 14, 2023
0599487
chore: sync padding and margin helpers
dcshzj Sep 19, 2023
4064e79
chore: sync template changes to CMS preview
dcshzj Sep 19, 2023
a4f2144
feat(announcements): define shape
kishore03109 Sep 14, 2023
aae494e
feat(validators): announcement validators
kishore03109 Sep 14, 2023
563a2a2
feat(announcement): add announcement block
kishore03109 Sep 14, 2023
99d1e17
feat(edit homepage): add in announcement block
kishore03109 Sep 14, 2023
9efef61
feat(useDrag): update draggable
kishore03109 Sep 14, 2023
300f5a5
fix(announcement): interface bugs
kishore03109 Sep 14, 2023
157f59b
fix(announcement): bugs after interface change
kishore03109 Sep 15, 2023
1be9ae3
feat(storybook): attempt to get out storybook
kishore03109 Sep 15, 2023
28f8c27
chore(storybook): remove storybook"
kishore03109 Sep 15, 2023
18f1c6d
fix(announcementbody): dont trigger re-render
kishore03109 Sep 15, 2023
f181a7c
fix(announcement): fix bugs wrt shape
kishore03109 Sep 15, 2023
394369a
chore(edit homepage): rm console log
kishore03109 Sep 15, 2023
2fd5173
fi(announcement): on drag bug fix
kishore03109 Sep 15, 2023
b6b8dfa
chore(edit homepage): rm console.log
kishore03109 Sep 15, 2023
5ca3005
fix(validations): should throw error for empty str
kishore03109 Sep 19, 2023
d059a01
chore(announcement body): dynamically retrieve max announcement
kishore03109 Sep 19, 2023
ef7eb56
chore(homepage): remove redundant check
kishore03109 Sep 19, 2023
ce274eb
chore(edithomepage): remove redundant console.log
kishore03109 Sep 19, 2023
5e8cd20
chore(edit homepage): modify this to announcements
kishore03109 Sep 19, 2023
df364b2
chore(announcement body): rm redundant placeholder
kishore03109 Sep 19, 2023
045571c
chore(edithomepage): rm redundant array
kishore03109 Sep 19, 2023
5dd65e2
IS-516 link to jira
kishore03109 Sep 19, 2023
7ea53be
chore(useDrag): change verb
kishore03109 Sep 20, 2023
b51adac
chore(edit homepage): clarity in comment
kishore03109 Sep 20, 2023
d818900
fix(announcement): use func to get new datetime
kishore03109 Sep 20, 2023
c9f156e
refactor(validator): change naming
kishore03109 Sep 20, 2023
73bfcab
refactor(announcement): mutate at data level
kishore03109 Sep 20, 2023
f3479d7
fix(announcement body): copy changes
kishore03109 Sep 20, 2023
87c4b03
fix(announcement): copy changes for clarity
kishore03109 Sep 20, 2023
6f1a855
fix(announcement date): show invalid dates
kishore03109 Sep 20, 2023
cc124cd
style(copy): change copy
kishore03109 Sep 20, 2023
5b1ddc1
fix(announcement): copy changes
kishore03109 Sep 20, 2023
545e9b8
fix(announcement): have 1 announcemnt by default
kishore03109 Sep 20, 2023
38b165a
build(de): fix failing build
kishore03109 Sep 21, 2023
f395799
fix(homapage prevew): rebase errors
kishore03109 Sep 21, 2023
2c77e9e
chore(validators): rm console logs
kishore03109 Sep 21, 2023
398e866
feat(feature flag): add partial ff for announment
kishore03109 Sep 21, 2023
c3b8bae
chore(announcemnt body): rm console log
kishore03109 Sep 21, 2023
8d6940e
chore(announcementBody): comments for clarity
kishore03109 Sep 21, 2023
700d1d2
fix(typing): relax constraint
kishore03109 Sep 21, 2023
c99a882
chore(announcementbody): rm redundant console.log
kishore03109 Sep 21, 2023
d444b96
refactor(editHomepage): rm redundant spread
kishore03109 Sep 21, 2023
b932615
style(edit homepage): add comments for clarity
kishore03109 Sep 21, 2023
8c46a2c
fix(announcements): empty errors bug
kishore03109 Sep 21, 2023
12fb497
chore(edit homepage): rm redundant func call
kishore03109 Sep 21, 2023
612aba0
chore(edit homepage): clarify comment
kishore03109 Sep 21, 2023
1dc61cc
fix(imports): fix imports after rebase
kishore03109 Sep 22, 2023
b13307c
fix(imports): issues after rebase
kishore03109 Sep 22, 2023
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
4 changes: 3 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"libphonenumber-js": "^1.9.48",
"lodash": "^4.17.21",
"marked": "^4.0.12",
"moment": "^2.29.4",
"moment-timezone": "^0.5.35",
"postcss": "^8.4.21",
"postcss-loader": "^7.2.4",
Expand Down
6 changes: 5 additions & 1 deletion src/components/Editable/Editable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ const EditableSidebar = ({
)
}

type HomepageDroppableZone = "dropdownelem" | "leftPane" | "highlight"
type HomepageDroppableZone =
| "dropdownelem"
| "leftPane"
| "highlight"
| "announcement"
type ContactUsDroppableZone =
| "locations"
| "contacts"
Expand Down
7 changes: 5 additions & 2 deletions src/components/PageSettingsModal/PageSettingsSchema.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
permalinkRegexTest,
specialCharactersRegexTest,
jekyllFirstCharacterRegexTest,
dateRegexTest,
resourceDateRegexTest,
PAGE_SETTINGS_PERMALINK_MIN_LENGTH,
PAGE_SETTINGS_PERMALINK_MAX_LENGTH,
PAGE_SETTINGS_TITLE_MIN_LENGTH,
Expand Down Expand Up @@ -71,7 +71,10 @@ export const PageSettingsSchema = (existingTitlesArray = []) =>
layout
? schema
.required("Date is required")
.matches(dateRegexTest, "Date must be formatted as YYYY-MM-DD")
.matches(
resourceDateRegexTest,
"Date must be formatted as YYYY-MM-DD"
)
.test(
"Date cannot be in the future",
"Date cannot be in the future",
Expand Down
178 changes: 178 additions & 0 deletions src/hooks/useDrag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import { DropResult } from "@hello-pangea/dnd"
import update from "immutability-helper"
import _ from "lodash"

import { ANNOUNCEMENT_BLOCK } from "layouts/EditHomepage/constants"

import {
EditorHeroDropdownSection,
EditorHeroHighlightsSection,
EditorHomepageElement,
EditorHomepageState,
HeroFrontmatterSection,
PossibleEditorSections,
EditorHomepageFrontmatterSection,
AnnouncementsFrontmatterSection,
AnnouncementOption,
} from "types/homepage"

const updatePositions = <T,>(
Expand All @@ -33,6 +38,12 @@ const createElement = <T,>(section: T[], elem: T): T[] => {
})
}

const createElementFromTop = <T,>(section: T[], elem: T): T[] => {
return update(section, {
$unshift: [elem],
})
}

const deleteElement = <T,>(section: T[], indexToDelete: number): T[] => {
return update(section, {
$splice: [[indexToDelete, 1]],
Expand All @@ -54,6 +65,32 @@ const updateEditorSection = (
errors: { ...homepageState.errors, sections: newSectionErrors },
})

const updateAnnouncementSection = (
homepageState: EditorHomepageState,
newDisplayAnnouncementItems: unknown[],
newAnnouncementOptions: unknown[],
newAnnouncementErrors: unknown[],
announcementsIndex: number
): EditorHomepageState => {
return {
...homepageState,
displayAnnouncementItems: newDisplayAnnouncementItems,
frontMatter: {
...homepageState.frontMatter,
sections: _.set(
// NOTE: Deep clone here to avoid mutation
_.cloneDeep(homepageState.frontMatter.sections),
[announcementsIndex, ANNOUNCEMENT_BLOCK.id, "announcement_items"],
newAnnouncementOptions
),
},
errors: {
...homepageState.errors,
announcementItems: newAnnouncementErrors,
},
}
}

const updateDropdownSection = (
homepageState: EditorHomepageState,
newDisplayDropdownElems: unknown[],
Expand Down Expand Up @@ -120,6 +157,7 @@ const updateHomepageState = (
displaySections,
displayDropdownElems,
displayHighlights,
displayAnnouncementItems,
} = homepageState

// If the user dropped the draggable to no known droppable
Expand Down Expand Up @@ -241,6 +279,61 @@ const updateHomepageState = (
newHighlightErrors
)
}
case "announcement": {
const doesAnnouncementKeyExist = !_.isEmpty(
frontMatter.sections.find((section) =>
EditorHomepageFrontmatterSection.isAnnouncements(section)
)
)
if (!doesAnnouncementKeyExist) {
// should not reach here, but defensively return the original state
return homepageState
}

const announcementsIndex = frontMatter.sections.findIndex((section) =>
EditorHomepageFrontmatterSection.isAnnouncements(section)
)
const draggedElem = (frontMatter.sections[
announcementsIndex
// safe to assert as check is done above
] as AnnouncementsFrontmatterSection).announcements.announcement_items[
source.index
]

const newAnnouncementsOptions = updatePositions(
(frontMatter.sections[
announcementsIndex
// safe to assert as check is done above
] as AnnouncementsFrontmatterSection).announcements.announcement_items,
source.index,
destination.index,
draggedElem
)

const draggedError = errors.announcementItems[source.index]
const newAnnouncementErrors = updatePositions(
errors.announcementItems,
source.index,
destination.index,
draggedError
)
const displayBool = displayAnnouncementItems[source.index]
const newDisplayAnnouncementItems = updatePositions(
displayAnnouncementItems,
source.index,
destination.index,
displayBool
)

return updateAnnouncementSection(
homepageState,
newDisplayAnnouncementItems,
newAnnouncementsOptions,
newAnnouncementErrors,
announcementsIndex
)
}

default:
return homepageState
}
Expand All @@ -260,6 +353,7 @@ export const onCreate = <E,>(
displaySections,
displayDropdownElems,
displayHighlights,
displayAnnouncementItems,
} = homepageState

switch (elemType) {
Expand Down Expand Up @@ -332,6 +426,50 @@ export const onCreate = <E,>(

return updateHighlightsSection(homepageState, [true], [val], [err])
}
case "announcement": {
const announcementKeyExist = !_.isEmpty(
frontMatter.sections.find((section) =>
EditorHomepageFrontmatterSection.isAnnouncements(section)
)
)
if (!announcementKeyExist) {
// should not reach here, but defensively return the original state
return homepageState
}

const announcementsIndex = frontMatter.sections.findIndex((section) =>
EditorHomepageFrontmatterSection.isAnnouncements(section)
)
const announcementBlockSection: AnnouncementsFrontmatterSection = frontMatter
.sections[announcementsIndex] as AnnouncementsFrontmatterSection

const announcements = createElementFromTop(
announcementBlockSection.announcements.announcement_items,
val as AnnouncementOption
)

const resetDisplaySections = _.fill(
Array(displayAnnouncementItems.length),
false
)
const newDisplayAnnouncementItems = createElementFromTop(
resetDisplaySections,
true
)

const newAnnouncementErrors = createElementFromTop(
errors.announcementItems,
err
)

return updateAnnouncementSection(
homepageState,
newDisplayAnnouncementItems,
announcements,
newAnnouncementErrors,
announcementsIndex
)
}
default:
return homepageState
}
Expand All @@ -348,6 +486,7 @@ export const onDelete = (
displaySections,
displayDropdownElems,
displayHighlights,
displayAnnouncementItems,
} = homepageState

switch (elemType) {
Expand Down Expand Up @@ -406,6 +545,45 @@ export const onDelete = (
newHighlightErrors
)
}
case "announcement": {
const announcementKeyExist = !_.isEmpty(
frontMatter.sections.find((section) =>
EditorHomepageFrontmatterSection.isAnnouncements(section)
)
)
if (!announcementKeyExist) {
// should not reach here, but defensively return the original state
return homepageState
}

const announcementsIndex = frontMatter.sections.findIndex((section) =>
EditorHomepageFrontmatterSection.isAnnouncements(section)
)
const announcementsSection: AnnouncementsFrontmatterSection = frontMatter
.sections[announcementsIndex] as AnnouncementsFrontmatterSection

const newAnnouncementOptions = deleteElement(
announcementsSection.announcements.announcement_items,
indexToDelete
)
const newAnnouncementErrors = deleteElement(
errors.announcementItems,
indexToDelete
)

const newDisplayAnnouncements = deleteElement(
displayAnnouncementItems,
indexToDelete
)
kishore03109 marked this conversation as resolved.
Show resolved Hide resolved

return updateAnnouncementSection(
homepageState,
newDisplayAnnouncements,
newAnnouncementOptions,
newAnnouncementErrors,
announcementsIndex
)
}
default:
return homepageState
}
Expand Down
Loading