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

Fix/update resource name display and fix misc bugs #294

Merged
merged 6 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/components/FolderCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const FolderCard = ({

const deleteHandler = async () => {
try {
const apiUrl = `${process.env.REACT_APP_BACKEND_URL}/sites/${siteName}/${pageType === 'collection' ? `/collections/${category}` : `/resources/${category}`}`
const apiUrl = `${process.env.REACT_APP_BACKEND_URL}/sites/${siteName}${pageType === 'collection' ? `/collections/${category}` : `/resources/${category}`}`
await axios.delete(apiUrl);

// Refresh page
Expand Down
10 changes: 7 additions & 3 deletions src/components/OverviewCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const OverviewCard = ({
const [canShowGenericWarningModal, setCanShowGenericWarningModal] = useState(false)
const [chosenCategory, setChosenCategory] = useState()
const [isOutOfViewport, setIsOutOfViewport] = useState()
const [isNewCollection, setIsNewCollection] = useState(false)
const baseApiUrl = `${process.env.REACT_APP_BACKEND_URL}/sites/${siteName}${category ? isResource ? `/resources/${category}` : `/collections/${category}` : ''}`

useEffect(() => {
Expand Down Expand Up @@ -74,7 +75,7 @@ const OverviewCard = ({
} = frontMatter;

let collectionPageData
if (!isResource && chosenCategory) {
if (!isResource && !isNewCollection && chosenCategory) {
// User selected an existing page collection
const { collectionPages } = await retrieveThirdNavOptions(siteName, chosenCategory, true)
collectionPageData = collectionPages
Expand All @@ -94,7 +95,7 @@ const OverviewCard = ({
isNewFile: false,
siteName,
collectionPageData,
isNewCollection: !chosenCategory,
isNewCollection,
}
await saveFileAndRetrieveUrl(fileInfo)

Expand All @@ -113,6 +114,7 @@ const OverviewCard = ({
{className: `${elementStyles.toastError} ${elementStyles.toastLong}`}
);
}
setIsNewCollection(false)
setCanShowGenericWarningModal(false)
console.log(err);
}
Expand Down Expand Up @@ -221,6 +223,7 @@ const OverviewCard = ({
onProceed={moveFile}
onCancel={() => {
setChosenCategory()
setIsNewCollection(false)
setCanShowGenericWarningModal(false)
}}
proceedText="Continue"
Expand Down Expand Up @@ -320,6 +323,7 @@ const OverviewCard = ({
disabledStyle={elementStyles.disabled}
className={(!!errorMessage || !newCategory) ? elementStyles.disabled : elementStyles.blue}
callback={() => {
setIsNewCollection(true)
setChosenCategory(newCategory)
fileMoveDropdownRef.current.blur()
setCanShowGenericWarningModal(true)
Expand All @@ -341,7 +345,7 @@ const OverviewCard = ({
<DeleteWarningModal
onCancel={() => setCanShowDeleteWarningModal(false)}
onDelete={deleteHandler}
type="resource"
type={isResource ? "resource" : "page"}
/>
)
}
Expand Down
10 changes: 9 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,15 @@ export function retrieveResourceFileMetadata(fileName) {
const year = tokenArray[0];
const date = `${day} ${month} ${year}`;

const title = tokenArray.slice(3).join(' ');
const titleTokenArray = tokenArray.slice(3);
const prettifiedTitleTokenArray = titleTokenArray.map((token) => {
// We search for special characters which were converted to text
// Convert dollar back to $ if it is followed by any alphanumeric character
const convertedToken = token.replaceAll(/dollar(?=([0-9]))/g, '$')
if (convertedToken.length < 2) return convertedToken.toUpperCase()
return convertedToken.slice(0,1).toUpperCase() + convertedToken.slice(1)
});
const title = prettifiedTitleTokenArray.join(' ')

return { date, title };
}
Expand Down