-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chore/remove-old-feature-flags
- Loading branch information
Showing
402 changed files
with
10,673 additions
and
4,768 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Empty config file so defaults will be respected instead of users' own global config | ||
# (prevent directory traversal) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from 'react' | ||
|
||
const RSSIcon = ( | ||
props: React.JSX.IntrinsicAttributes & React.SVGProps<SVGSVGElement>, | ||
) => { | ||
return ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="16" | ||
height="16" | ||
enableBackground="new 0 0 512 512" | ||
version="1.1" | ||
viewBox="0 0 512 512" | ||
xmlSpace="preserve" | ||
{...props} | ||
> | ||
<g> | ||
<rect | ||
width="512" | ||
height="512" | ||
x="-512" | ||
y="-512" | ||
fill="#ea7819" | ||
fillOpacity="1" | ||
stroke="none" | ||
rx="70" | ||
ry="70" | ||
transform="scale(-1)" | ||
></rect> | ||
<path | ||
fill="#fff" | ||
d="M81.056 267.05c43.705 0 84.79 17.072 115.665 48.124 30.931 31.051 47.961 72.411 47.961 116.44h67.35c0-127.885-103.62-231.921-230.976-231.921v67.357zm.106-119.4c155.76 0 282.488 127.42 282.488 284.049H431C431 237.925 274.054 80.301 81.162 80.301v67.35zm93.135 236.998c0 25.757-20.892 46.649-46.649 46.649-25.756 0-46.648-20.885-46.648-46.649C81 358.878 101.885 338 127.641 338c25.757 0 46.656 20.878 46.656 46.648z" | ||
></path> | ||
</g> | ||
</svg> | ||
) | ||
} | ||
|
||
export default RSSIcon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { default as HeroImage } from './HeroImage' | ||
export { default as RSSIcon } from './RSSFeedIcon' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { NextApiRequest } from 'next' | ||
import initApollo from '../../graphql/client' | ||
import { SUB_GET_CASES } from '../../graphql/queries.graphql' | ||
import { SubGetCasesQuery } from '../../graphql/queries.graphql.generated' | ||
import { SUB_PAGE_SIZE, SUB_STATUSES_TO_FETCH } from '../../utils/consts/consts' | ||
|
||
type CaseItem = { | ||
id?: number | null | ||
caseNumber?: string | null | ||
name?: string | null | ||
institutionName?: string | null | ||
policyAreaName?: string | null | ||
} | ||
|
||
export default async function handler(req: NextApiRequest, res) { | ||
const client = initApollo() | ||
try { | ||
const { | ||
data: { consultationPortalGetCases }, | ||
} = await client.query<SubGetCasesQuery>({ | ||
query: SUB_GET_CASES, | ||
variables: { | ||
input: { | ||
caseStatuses: SUB_STATUSES_TO_FETCH, | ||
pageSize: SUB_PAGE_SIZE, | ||
}, | ||
}, | ||
}) | ||
|
||
const host: string = req.headers.host | ||
const protocol = `http${host.startsWith('localhost') ? '' : 's'}://` | ||
const baseUrl = `${protocol}${host}` | ||
|
||
const getCases = (post: CaseItem) => { | ||
return `<item> | ||
<title>${post.name}</title> | ||
<description>${post.name}</description> | ||
<link>${baseUrl}/samradsgatt/mal/${post.id}</link> | ||
</item>` | ||
} | ||
|
||
const feed = `<?xml version="1.0" encoding="UTF-8" ?> | ||
<rss version="2.0"> | ||
<channel> | ||
<title>Samráðsgátt - Áskriftir RSS Veita</title> | ||
<description>Island.is</description> | ||
${consultationPortalGetCases.cases.map((i) => getCases(i)).join('')} | ||
</channel> | ||
</rss>` | ||
|
||
res.set('Content-Type', 'text/xml;charset=UTF-8') | ||
return res.status(200).send(feed) | ||
} catch (error) { | ||
if (error.networkError) { | ||
res.status(500).send('Network error') | ||
return | ||
} else { | ||
res.status(500).send('Internal Server Error') | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
apps/contentful-apps/pages/fields/project-subpage-slug-field.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
import { useEffect, useRef, useState } from 'react' | ||
import { useDebounce } from 'react-use' | ||
import type { EntryProps } from 'contentful-management' | ||
import { FieldExtensionSDK } from '@contentful/app-sdk' | ||
import { Stack, Text, TextInput } from '@contentful/f36-components' | ||
import { useCMA, useSDK } from '@contentful/react-apps-toolkit' | ||
import slugify from '@sindresorhus/slugify' | ||
|
||
const DEBOUNCE_TIME = 100 | ||
|
||
const ProjectSubpageSlugField = () => { | ||
const sdk = useSDK<FieldExtensionSDK>() | ||
const cma = useCMA() | ||
const [value, setValue] = useState(sdk.field?.getValue() ?? '') | ||
const [isValid, setIsValid] = useState(true) | ||
const [projectPage, setProjectPage] = useState<EntryProps | null>(null) | ||
const initialTitleChange = useRef(true) | ||
const [hasEntryBeenPublished, setHasEntryBeenPublished] = useState( | ||
Boolean(sdk.entry.getSys()?.firstPublishedAt), | ||
) | ||
|
||
const defaultLocale = sdk.locales.default | ||
|
||
useEffect(() => { | ||
const fetchProjectPage = async () => { | ||
const response = await cma.entry.getMany({ | ||
query: { | ||
links_to_entry: sdk.entry.getSys().id, | ||
content_type: 'projectPage', | ||
'sys.archivedVersion[exists]': false, | ||
limit: 1, | ||
}, | ||
}) | ||
if (response.items.length > 0) { | ||
setProjectPage(response.items[0]) | ||
} | ||
} | ||
fetchProjectPage() | ||
}, [cma.entry, sdk.entry]) | ||
|
||
useEffect(() => { | ||
sdk.entry.onSysChanged((newSys) => { | ||
setHasEntryBeenPublished(Boolean(newSys?.firstPublishedAt)) | ||
}) | ||
}, [sdk.entry]) | ||
|
||
// Update slug field if the title field changes | ||
useEffect(() => { | ||
return sdk.entry.fields.title | ||
.getForLocale(sdk.field.locale) | ||
.onValueChanged((newTitle) => { | ||
if (hasEntryBeenPublished) { | ||
return | ||
} | ||
|
||
// Callback gets called on initial render, so we want to ignore that | ||
if (initialTitleChange.current) { | ||
initialTitleChange.current = false | ||
return | ||
} | ||
|
||
if (newTitle) { | ||
setValue(slugify(String(newTitle))) | ||
} | ||
}) | ||
}, [hasEntryBeenPublished, sdk.entry.fields.title, sdk.field.locale]) | ||
|
||
useEffect(() => { | ||
sdk.window.startAutoResizer() | ||
}, [sdk.window]) | ||
|
||
// Validate the user input | ||
useDebounce( | ||
async () => { | ||
if (!projectPage) { | ||
setIsValid(true) | ||
return | ||
} | ||
|
||
const subpageIds: string[] = | ||
projectPage?.fields?.projectSubpages?.[defaultLocale]?.map( | ||
(subpage) => subpage.sys.id, | ||
) ?? [] | ||
|
||
const subpagesWithSameSlug = ( | ||
await cma.entry.getMany({ | ||
query: { | ||
locale: sdk.field.locale, | ||
content_type: 'projectSubpage', | ||
'fields.slug': value, | ||
'sys.id[ne]': sdk.entry.getSys().id, | ||
'sys.archivedVersion[exists]': false, | ||
limit: 1000, | ||
select: 'sys', | ||
}, | ||
}) | ||
).items | ||
|
||
const subpageExistsWithSameSlug = subpagesWithSameSlug.some((subpage) => | ||
subpageIds.includes(subpage.sys.id), | ||
) | ||
|
||
if (subpageExistsWithSameSlug) { | ||
setIsValid(false) | ||
return | ||
} | ||
setIsValid(true) | ||
}, | ||
DEBOUNCE_TIME, | ||
[value, projectPage], | ||
) | ||
|
||
useDebounce( | ||
() => { | ||
if (isValid) { | ||
sdk.field.setValue(value) | ||
} else { | ||
sdk.field.setValue(null) // Set to null to prevent entry publish | ||
} | ||
sdk.field.setInvalid(!isValid) | ||
}, | ||
DEBOUNCE_TIME, | ||
[isValid, value], | ||
) | ||
|
||
const isInvalid = value.length === 0 || !isValid | ||
|
||
return ( | ||
<Stack spacing="spacingXs" flexDirection="column" alignItems="flex-start"> | ||
<TextInput | ||
value={value} | ||
onChange={(ev) => { | ||
setValue(ev.target.value) | ||
}} | ||
isInvalid={isInvalid} | ||
/> | ||
{value.length === 0 && sdk.field.locale === defaultLocale && ( | ||
<Text fontColor="red400">Invalid slug</Text> | ||
)} | ||
{value.length > 0 && isInvalid && ( | ||
<Text fontColor="red400"> | ||
Project subpage already exists with this slug | ||
</Text> | ||
)} | ||
</Stack> | ||
) | ||
} | ||
|
||
export default ProjectSubpageSlugField |
Oops, something went wrong.