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/page dropdown api #388

Merged
merged 44 commits into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
7dc2ff1
fix: refactor PageSettingsModal to use getEditPageData
gweiying Mar 17, 2021
df14b4a
fix: removes getPage from api.js file
gweiying Mar 17, 2021
ce87658
fix: disables Saving PageSettingsModal when no changes
gweiying Mar 18, 2021
025e319
feat: creates rename and create API calls
gweiying Mar 18, 2021
c545021
feat: refactors PageSettingsModals saveHandler to use new API calls
gweiying Mar 18, 2021
092a5df
fix: refactor to query for EditPage details once dropdown toggle is a…
gweiying Mar 22, 2021
b9d66fe
fix: modifies updatePageData to return null when successful
gweiying Mar 22, 2021
5d9fbc3
fix: add delete functionality to FolderPages
gweiying Mar 22, 2021
12b1cd8
fix: add delete functionality to unlinked pages
gweiying Mar 22, 2021
0626f9e
fix: removes SettingsToggle from CollectionPagesSection
gweiying Mar 22, 2021
6d00fee
fix: refactors ComponentSettingsModal to remove unused page setting code
gweiying Mar 24, 2021
81795a1
fix: refactor validation for resourceSettings
gweiying Mar 24, 2021
3b01279
fix: refactors ComponentSettingsModal to remove type === 'resources' …
gweiying Mar 24, 2021
6dc0e77
fix: fix code bugs and removes unused declarations in PageSettingsModal
gweiying Mar 24, 2021
f7cd608
fix: generateResourceFileName to slugify lower
gweiying Mar 24, 2021
2be9da6
fix: refactor ComponentSettingsModal
gweiying Mar 24, 2021
26b0453
fix: clean up PageSettingsModal
gweiying Mar 24, 2021
33bdc9a
feat: adds Move To dropdown functionality to folders
gweiying Mar 24, 2021
2a3ba94
fix: tidy up Folders
gweiying Mar 24, 2021
67c9ad8
feat: refactor CollectionPagesSection
gweiying Mar 24, 2021
39ed3de
fix: minor tweak to resourceFileName generation
gweiying Mar 24, 2021
8b418a6
feat: refactor Overview Card
gweiying Mar 24, 2021
d5969d8
feat: refactor FolderContent
gweiying Mar 24, 2021
9b353f9
fix: fix MenuDropdown handler behavior when items have nested buttons
gweiying Mar 24, 2021
f014518
fix: improves MenuDropdown css appearance
gweiying Mar 24, 2021
ca11d48
fix: add infoGrey
gweiying Mar 24, 2021
f752b49
fix: add moveFile API, to be cleaned up
gweiying Mar 24, 2021
37793a8
fix: rebase typo with missing } in api.js
gweiying Mar 25, 2021
219a0fa
fix: return error for resources
gweiying Mar 25, 2021
382823f
fix: disables handleBlur
gweiying Mar 25, 2021
6710f3e
fix: clean up after settled mutations
gweiying Mar 25, 2021
ab285a0
fix: disables handleBlur
gweiying Mar 25, 2021
d033c4b
fix: removes unlinked pages from OverviewCard
gweiying Mar 25, 2021
c1d6f44
fix: removes filter for folder dropdown
gweiying Mar 25, 2021
70fa02c
fix: simplifying api endpoints
gweiying Mar 29, 2021
c82e6d0
fix: returns null from getCategories when query has not returned
gweiying Mar 29, 2021
3809add
fix: adds variable to disable blurring, used when fileModalDropdown n…
gweiying Mar 29, 2021
4967fd3
fix: changes opacity of dropdownItemChildButton background to 0%
gweiying Mar 29, 2021
4e53e09
fix: creates componentTitleLink
gweiying Mar 29, 2021
a3422b7
fix: improves behavior of MoveDropdown modal
gweiying Mar 29, 2021
fc10ea9
fix: remove encoding for redirectUrl
gweiying Mar 29, 2021
d2fa8d0
fix: removes unused variables
gweiying Mar 29, 2021
5213f6a
fix: rebase error with file filtering
gweiying Mar 30, 2021
46ee954
fix: change numItems check to check for null
gweiying Mar 30, 2021
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
120 changes: 84 additions & 36 deletions src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@ const setDirectoryFile = async (siteName, folderName, payload) => {
return await axios.post(`${BACKEND_URL}/sites/${siteName}/collections/${folderName}/pages/collection.yml`, payload);
}

const getFolderContents = async (siteName, folderName, subfolderName) => {
return await axios.get(`${BACKEND_URL}/sites/${siteName}/folders?path=_${folderName}${subfolderName ? `/${subfolderName}` : ''}`);
}

// EditPage
const getPageApiEndpoint = ({folderName, subfolderName, fileName, siteName, resourceName}) => {
const getPageApiEndpoint = ({folderName, subfolderName, fileName, siteName, resourceName, newFileName}) => {
if (folderName) {
return `${process.env.REACT_APP_BACKEND_URL}/sites/${siteName}/collections/${folderName}/pages/${encodeURIComponent(`${subfolderName ? `${subfolderName}/` : ''}${fileName}`)}`
}
Expand All @@ -31,6 +27,36 @@ const getPageApiEndpoint = ({folderName, subfolderName, fileName, siteName, reso
return `${process.env.REACT_APP_BACKEND_URL}/sites/${siteName}/pages/${fileName}`
}

const getCreatePageApiEndpoint = ({folderName, subfolderName, siteName, resourceName, newFileName}) => {
if (folderName) {
return `${process.env.REACT_APP_BACKEND_URL}/sites/${siteName}/collections/${folderName}/pages/new/${encodeURIComponent(`${subfolderName ? `${subfolderName}/` : ''}${newFileName}`)}`
}
if (resourceName) {
return `${process.env.REACT_APP_BACKEND_URL}/sites/${siteName}/resources/${resourceName}/pages/new/${newFileName}`
}
return `${process.env.REACT_APP_BACKEND_URL}/sites/${siteName}/pages/new/${newFileName}`
}

const getRenamePageApiEndpoint = ({folderName, subfolderName, fileName, siteName, resourceName, newFileName}) => {
if (folderName) {
return `${process.env.REACT_APP_BACKEND_URL}/sites/${siteName}/collections/${folderName}/pages/${encodeURIComponent(`${subfolderName ? `${subfolderName}/` : ''}${fileName}`)}/rename/${encodeURIComponent(`${subfolderName ? `${subfolderName}/` : ''}${newFileName}`)}`
}
if (resourceName) {
return `${process.env.REACT_APP_BACKEND_URL}/sites/${siteName}/resources/${resourceName}/pages/${fileName}/rename/${newFileName}`
}
return `${process.env.REACT_APP_BACKEND_URL}/sites/${siteName}/pages/${fileName}/rename/${newFileName}`
}

const getMovePageEndpoint = ({siteName, resourceName, folderName, subfolderName, newPath}) => {
if (folderName) {
return `${BACKEND_URL}/sites/${siteName}/collections/${encodeURIComponent(`${folderName ? `${folderName}`: ''}${subfolderName ? `/${subfolderName}` : ''}`)}/move/${encodeURIComponent(`${newPath}`)}`
}
if (resourceName) {
return `${BACKEND_URL}/sites/${siteName}/resources/${resourceName}/move/${encodeURIComponent(`${newPath}`)}`
}
return `${BACKEND_URL}/sites/${siteName}/pages/move/${encodeURIComponent(`${newPath}`)}`
}

const getEditPageData = async ({folderName, subfolderName, fileName, siteName, resourceName}) => {
const apiEndpoint = getPageApiEndpoint({folderName, subfolderName, fileName, siteName, resourceName})
const resp = await axios.get(apiEndpoint);
Expand All @@ -49,13 +75,38 @@ const getCsp = async (siteName) => {
return await axios.get(`${process.env.REACT_APP_BACKEND_URL}/sites/${siteName}/netlify-toml`);
}

const createPageData = async ({folderName, subfolderName, newFileName, siteName, resourceName}, content) => {
const apiEndpoint = getCreatePageApiEndpoint({folderName, subfolderName, newFileName, siteName, resourceName})
const params = { content }
await axios.post(apiEndpoint, params)

// redirect to new page upon successful creation
if (folderName) {
return `/sites/${siteName}/folder/${folderName}/${subfolderName ? `subfolder/${subfolderName}/` : ''}${newFileName}`
}
if (resourceName) {
return `/sites/${siteName}/resources/${resourceName}/${newFileName}`
}
return `/sites/${siteName}/pages/${newFileName}`
}

const renamePageData = async ({folderName, subfolderName, fileName, siteName, resourceName, newFileName}, content, sha) => {
const apiEndpoint = getRenamePageApiEndpoint({folderName, subfolderName, fileName, siteName, resourceName, newFileName})
const params = {
content,
sha,
};
await axios.post(apiEndpoint, params)
}

const updatePageData = async ({folderName, subfolderName, fileName, siteName, resourceName}, content, sha) => {
const apiEndpoint = getPageApiEndpoint({folderName, subfolderName, fileName, siteName, resourceName})
const params = {
content,
sha,
};
return await axios.post(apiEndpoint, params);
await axios.post(apiEndpoint, params);
return
}

const deletePageData = async ({folderName, subfolderName, fileName, siteName, resourceName}, sha) => {
Expand Down Expand Up @@ -88,6 +139,19 @@ const renameResourceCategory = async ({ siteName, categoryName, newCategoryName}
return await axios.post(apiUrl)
}

const getAllCategoriesApiEndpoint = ({siteName, isResource}) => {
if (isResource) {
return `${BACKEND_URL}/sites/${siteName}/resources`
}
return `${BACKEND_URL}/sites/${siteName}/collections`
}

const getAllCategories = async ({siteName, isResource}) => {
const apiEndpoint = getAllCategoriesApiEndpoint({siteName, isResource})
const resp = await axios.get(apiEndpoint);
return resp.data
}

const getAllResourceCategories = async (siteName) => {
return await axios.get(`${BACKEND_URL}/sites/${siteName}/resources`);
}
Expand All @@ -111,10 +175,8 @@ const getEditNavBarData = async(siteName) => {
const { content, sha } = resp.data;
navContent = content
navSha = sha
const collectionResp = await axios.get(`${BACKEND_URL}/sites/${siteName}/collections`)
collectionContent = collectionResp.data
const resourceResp = await axios.get(`${BACKEND_URL}/sites/${siteName}/resources`)
resourceContent = resourceResp.data
collectionContent = await getAllCategories({siteName, isResource: false})
resourceContent = await getAllCategories({siteName, isResource: true})
const foldersResp = await axios.get(`${BACKEND_URL}/sites/${siteName}/folders/all`)
if (foldersResp.data && foldersResp.data.allFolderContent) {
// parse directory files
Expand Down Expand Up @@ -148,27 +210,6 @@ const updateNavBarData = async (siteName, originalNav, links, sha) => {
return await axios.post(`${BACKEND_URL}/sites/${siteName}/navigation`, params);
}

const createPage = async (endpointUrl, content) => {
return await axios.post(`${BACKEND_URL}/sites/${endpointUrl}`, { content });
}

const getPage = async (pageType, siteName, collectionName, pageName) => {
const endpointUrl = (pageType === 'collection')
? `${siteName}/collections/${collectionName}/pages/${pageName}`
: `${siteName}/pages/${pageName}`
const resp = await axios.get(`${BACKEND_URL}/sites/${endpointUrl}`);
return resp.data
}

const updatePage = async(endpointUrl, content, sha) => {
return await axios.post(`${BACKEND_URL}/sites/${endpointUrl}`, { content, sha });
}

const deletePage = async(endpointUrl, sha) => {
return
// return await axios.delete(`${BACKEND_URL}/sites/${endpointUrl}`, { content, sha });
}

const moveFiles = async (siteName, selectedFiles, title, parentFolder) => {
const baseApiUrl = `${process.env.REACT_APP_BACKEND_URL}/sites/${siteName}${parentFolder ? `/collections/${parentFolder}` : '/pages'}`
const params = {
Expand All @@ -178,10 +219,17 @@ const moveFiles = async (siteName, selectedFiles, title, parentFolder) => {
return await axios.post(`${baseApiUrl}/move/${newPath}`, params)
}

const moveFile = async ({selectedFile, siteName, resourceName, folderName, subfolderName, newPath}) => {
const apiEndpoint = getMovePageEndpoint({siteName, resourceName, folderName, subfolderName, newPath})
const params = {
files: [selectedFile],
}
return await axios.post(apiEndpoint, params)
}

export {
getDirectoryFile,
setDirectoryFile,
getFolderContents,
getEditPageData,
getCsp,
updatePageData,
Expand All @@ -195,9 +243,9 @@ export {
getResourcePages,
getEditNavBarData,
updateNavBarData,
createPage,
getPage,
updatePage,
deletePage,
createPageData,
renamePageData,
getAllCategories,
moveFiles,
moveFile,
}
Loading