Skip to content

Commit

Permalink
Merge branch 'fer/2015' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandolucchesi committed Jan 2, 2024
2 parents 5fe7e77 + 56b836e commit e59241b
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/DEV-studio-v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
datasetName: ${{ matrix.dataset }}
githubToken: ${{ secrets.GITHUB_TOKEN }}
sanityApiToken: ${{ secrets.SANITY_API_TOKEN }}
sanityMutationToken: ${{ secrets.SANITY_STUDIO_MUTATION_TOKEN }}
sanityHistoryApiToken: ${{ secrets.SANITY_STUDIO_HISTORY_API_TOKEN }}
sanityPreviewToken: ${{ secrets.SANITY_STUDIO_PREVIEW_SECRET }}
brandmasterUrl: ${{ secrets.SANITY_STUDIO_BRANDMASTER_URL }}
brandmasterPluginSource: ${{ secrets.SANITY_STUDIO_BRANDMASTER_PLUGIN_SOURCE }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/PREPROD-studios-v3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
datasetName: ${{ matrix.dataset }}
githubToken: ${{ secrets.GITHUB_TOKEN }}
sanityApiToken: ${{ secrets.SANITY_API_TOKEN }}
sanityMutationToken: ${{ secrets.SANITY_STUDIO_MUTATION_TOKEN }}
sanityHistoryApiToken: ${{ secrets.SANITY_STUDIO_HISTORY_API_TOKEN }}
sanityPreviewToken: ${{ secrets.SANITY_STUDIO_PREVIEW_SECRET }}
brandmasterUrl: ${{ secrets.SANITY_STUDIO_BRANDMASTER_URL }}
brandmasterPluginSource: ${{ secrets.SANITY_STUDIO_BRANDMASTER_PLUGIN_SOURCE }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/PROD-all-studios-v3.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
SANITY_STUDIO_BRANDMASTER_URL: ${{ secrets.SANITY_STUDIO_BRANDMASTER_URL }}
SANITY_STUDIO_BRANDMASTER_PLUGIN_SOURCE: ${{ secrets.SANITY_STUDIO_BRANDMASTER_PLUGIN_SOURCE }}
SANITY_STUDIO_PREVIEW_SECRET: ${{ secrets.SANITY_STUDIO_PREVIEW_SECRET }}
SANITY_STUDIO_MUTATION_TOKEN: ${{ secrets.SANITY_STUDIO_MUTATION_TOKEN }}
SANITY_STUDIO_HISTORY_API_TOKEN: ${{ secrets.SANITY_STUDIO_HISTORY_API_TOKEN }}
SANITY_STUDIO_API_DATASET: global
SANITY_STUDIO_FOTOWARE_CLIENT_ID: ${{ secrets.SANITY_STUDIO_FOTOWARE_CLIENT_ID }}
SANITY_STUDIO_FOTOWARE_TENANT_URL: ${{ secrets.SANITY_STUDIO_FOTOWARE_TENANT_URL }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/PROD-studios-rollback.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
SANITY_STUDIO_PREVIEW_SECRET: ${{ secrets.SANITY_STUDIO_PREVIEW_SECRET }}
SANITY_STUDIO_API_DATASET: global
SANITY_STUDIO_API_TOKEN: ${{ secrets.SANITY_API_TOKEN }}
SANITY_STUDIO_MUTATION_TOKEN: ${{ secrets.SANITY_STUDIO_MUTATION_TOKEN }}
SANITY_STUDIO_HISTORY_API_TOKEN: ${{ secrets.SANITY_STUDIO_HISTORY_API_TOKEN }}
SANITY_STUDIO_FOTOWARE_CLIENT_ID: ${{ secrets.SANITY_STUDIO_FOTOWARE_CLIENT_ID }}
SANITY_STUDIO_FOTOWARE_TENANT_URL: ${{ secrets.SANITY_STUDIO_FOTOWARE_TENANT_URL }}
SANITY_STUDIO_FOTOWARE_REDIRECT_ORIGIN: ${{ secrets.SANITY_STUDIO_FOTOWARE_REDIRECT_ORIGIN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/TEST-studio.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ jobs:
datasetName: ${{ matrix.dataset }}
githubToken: ${{ secrets.GITHUB_TOKEN }}
sanityApiToken: ${{ secrets.SANITY_API_TOKEN }}
sanityMutationToken: ${{ secrets.SANITY_STUDIO_MUTATION_TOKEN }}
sanityHistoryApiToken: ${{ secrets.SANITY_STUDIO_HISTORY_API_TOKEN }}
sanityPreviewToken: ${{ secrets.SANITY_STUDIO_PREVIEW_SECRET }}
brandmasterUrl: ${{ secrets.SANITY_STUDIO_BRANDMASTER_URL }}
brandmasterPluginSource: ${{ secrets.SANITY_STUDIO_BRANDMASTER_PLUGIN_SOURCE }}
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/deploy-v3/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ inputs:
sanityApiToken:
description: 'Sanity API token'
required: true
sanityMutationToken:
description: 'Sanity API mutation token'
sanityHistoryApiToken:
description: 'Sanity History API token'
required: true
screen9accountId:
description: 'Screen 9 Account Id'
Expand Down Expand Up @@ -100,7 +100,7 @@ runs:
--build-arg ARG_SANITY_DATASET=${{ inputs.datasetName }} \
--build-arg ARG_SANITY_PREVIEW=${{ inputs.sanityPreviewToken }} \
--build-arg ARG_SANITY_API_TOKEN=${{ inputs.sanityApiToken }} \
--build-arg ARG_SANITY_MUTATION_TOKEN=${{ inputs.sanityMutationToken }} \
--build-arg ARG_SANITY_HISTORY_API_TOKEN=${{ inputs.sanityHistoryApiToken }} \
--build-arg ARG_BRANDMASTER_URL=${{ inputs.brandmasterUrl }} \
--build-arg ARG_BRANDMASTER_PLUGIN="${{ inputs.brandmasterPluginSource }}" \
--build-arg ARG_FOTOWARE_CLIENT_ID="${{ inputs.fotowareClientId }}" \
Expand Down
2 changes: 2 additions & 0 deletions sanityv3/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ COPY ./sanityv3 ./sanityv3

ARG ARG_SANITY_API_TOKEN
ARG ARG_SANITY_MUTATION_TOKEN
ARG ARG_SANITY_HISTORY_API_TOKEN
ARG ARG_SANITY_PROJECT_ID
ARG ARG_SANITY_DATASET
ARG ARG_SANITY_PREVIEW
Expand All @@ -32,6 +33,7 @@ ARG ARG_SCREEN9_TOKEN

ENV SANITY_STUDIO_API_TOKEN ${ARG_SANITY_API_TOKEN}
ENV SANITY_STUDIO_MUTATION_TOKEN ${ARG_SANITY_MUTATION_TOKEN}
ENV SANITY_STUDIO_HISTORY_API_TOKEN ${ARG_SANITY_HISTORY_API_TOKEN}
ENV SANITY_STUDIO_API_PROJECT_ID ${ARG_SANITY_PROJECT_ID}
ENV SANITY_STUDIO_API_DATASET ${ARG_SANITY_DATASET}
ENV SANITY_STUDIO_PREVIEW_SECRET ${ARG_SANITY_PREVIEW}
Expand Down
16 changes: 9 additions & 7 deletions sanityv3/actions/CustomPublishAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import {
DocumentActionConfirmDialogProps,
DocumentActionDescription,
DocumentActionProps,
DocumentActionsContext,
SanityClient,
} from 'sanity'
import { dataset, sanityClient, apiVersion } from '../sanity.client'
import { dataset, apiVersion } from '../sanity.client'
import { useToast } from '@sanity/ui'

const projectId = import.meta.env.SANITY_STUDIO_API_PROJECT_ID || 'h61q9gi9'
const token = import.meta.env.SANITY_STUDIO_MUTATION_TOKEN
const client = sanityClient.withConfig({ token: token, ignoreBrowserTokenWarning: true })
/** Secret site already exposes the mutation token. So we can reuse it instead. */
const token = import.meta.env.SANITY_STUDIO_HISTORY_API_TOKEN || import.meta.env.SANITY_STUDIO_MUTATION_TOKEN

const FIRST_PUBLISHED_AT_FIELD_NAME = 'firstPublishedAt'

Expand All @@ -20,7 +22,6 @@ const requiresFirstPublished = ['news', 'localNews', 'magazine']
const shouldAddFirstPublishedAt = async (props: DocumentActionProps) => {
if (!requiresFirstPublished.includes(props.type)) return false
let error = false

// https://github.com/sanity-io/sanity/issues/2179
const revisions = await fetch(
`https://${projectId}.api.sanity.io/${apiVersion}/data/history/${dataset}/transactions/${props.id}?excludeContent=true`,
Expand All @@ -44,7 +45,7 @@ const shouldAddFirstPublishedAt = async (props: DocumentActionProps) => {
return !hasBeenPublished || !props.published?.[FIRST_PUBLISHED_AT_FIELD_NAME]
}

const addFirstPublishedAtField = async (id: string) => {
const addFirstPublishedAtField = async (id: string, client: SanityClient) => {
await client
.patch(id)
.set({ [FIRST_PUBLISHED_AT_FIELD_NAME]: new Date().toISOString() })
Expand All @@ -54,7 +55,8 @@ const addFirstPublishedAtField = async (id: string) => {
})
}

export function createCustomPublishAction(originalAction: DocumentActionComponent) {
export function createCustomPublishAction(originalAction: DocumentActionComponent, context: DocumentActionsContext) {
const client = context.getClient({ apiVersion: apiVersion })
return (props: DocumentActionProps) => {
const [dialogOpen, setDialogOpen] = useState(false)
const originalResult = originalAction(props as DocumentActionProps) as DocumentActionDescription
Expand All @@ -63,7 +65,7 @@ export function createCustomPublishAction(originalAction: DocumentActionComponen
const handlePublish = async () => {
try {
if (await shouldAddFirstPublishedAt(props)) {
await addFirstPublishedAtField(props.draft?._id || props.id)
await addFirstPublishedAtField(props.draft?._id || props.id, client)
}
originalResult.onHandle && originalResult.onHandle()
} catch (e) {
Expand Down
1 change: 1 addition & 0 deletions sanityv3/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface ImportMetaEnv {
readonly SANITY_STUDIO_BRANDMASTER_URL: string
readonly SANITY_STUDIO_PREVIEW_SECRET: string
readonly SANITY_STUDIO_BRANDMASTER_PLUGIN_SOURCE: string
readonly SANITY_STUDIO_HISTORY_API_TOKEN: string
// more env variables...
}
interface ImportMeta {
Expand Down
8 changes: 5 additions & 3 deletions sanityv3/sanity.config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
SchemaTypeDefinition,
Template,
} from 'sanity'
import type { InputProps, ArrayOfObjectsInputProps, SchemaType, ArraySchemaType } from 'sanity'
import type { InputProps, ArrayOfObjectsInputProps, SchemaType, ArraySchemaType, DocumentActionsContext } from 'sanity'
import { scheduledPublishing } from '@sanity/scheduled-publishing'

import { deskTool, StructureBuilder } from 'sanity/desk'
Expand Down Expand Up @@ -102,14 +102,16 @@ const getConfig = (datasetParam: string, projectIdParam: string, isSecret = fals
templates: (prev: Template<any, any>[]) => [...prev, ...initialValueTemplates],
},
document: {
actions: (prev: DocumentActionComponent[]) => {
actions: (prev: DocumentActionComponent[], context: DocumentActionsContext) => {
if (isSecret) prev.push(ResetCrossDatasetToken)
return prev
.filter(({ action, name }: DocumentActionComponent) => {
return !(name !== 'DuplicateAction' && action === 'duplicate') // two actions are named duplicate, so we filter on two values to get the correct one
})
.map((originalAction) =>
originalAction.action === 'publish' ? createCustomPublishAction(createPublishAction(i18n)) : originalAction,
originalAction.action === 'publish'
? createCustomPublishAction(createPublishAction(i18n), context)
: originalAction,
)
},
},
Expand Down
37 changes: 3 additions & 34 deletions sanityv3/schemas/objects/textWithIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
import { puzzle_filled } from '@equinor/eds-icons'
import { Rule } from 'sanity'
import blocksToText from '../../helpers/blocksToText'
import { EdsIcon } from '../../icons'
import { sanityClient } from '../../sanity.client'
import { Flags } from '../../src/lib/datasetHelpers'
import { configureBlockContent } from '../editors/blockContentType'
import type { ImageWithAlt } from './imageWithAlt'

const client = sanityClient.withConfig({
projectId: import.meta.env.SANITY_STUDIO_API_PROJECT_ID || 'h61q9gi9',
token: import.meta.env.SANITY_STUDIO_MUTATION_TOKEN,
ignoreBrowserTokenWarning: true,
})

const blockContentType = configureBlockContent({
h1: false,
Expand Down Expand Up @@ -40,29 +30,8 @@ export default {
type: 'array',
of: [blockContentType],
},
Flags.IS_DEV && {
title: 'Icon',
name: 'icon',
type: 'imageWithAlt',
options: {
accept: 'image/svg+xml',
hotspot: false,
},
validation: (Rule: Rule) =>
Rule.custom((imageWithAlt: ImageWithAlt) => {
const referencedId = imageWithAlt?.asset?._ref
if (referencedId) {
return client
.fetch(`*[_id == $id][0]{extension}`, {
id: referencedId,
})
.then((res: any) => {
return res.extension === 'svg' ? true : 'Only svg files are allowed'
})
} else return true
}),
},
!Flags.IS_DEV && {

{
title: 'Icon',
name: 'icon',
type: 'imageWithAlt',
Expand All @@ -71,7 +40,7 @@ export default {
hotspot: false,
},
},
].filter((e) => e),
],
preview: {
select: {
title: `title`,
Expand Down

0 comments on commit e59241b

Please sign in to comment.