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

refactor(sanity): remove "features" #7097

Merged
merged 1 commit into from
Jul 9, 2024
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
8 changes: 3 additions & 5 deletions dev/studio-e2e-testing/sanity.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,9 @@ const sharedSettings = definePlugin({
muxInput({mp4_support: 'standard'}),
presenceTool(),
],
features: {
beta: {
treeArrayEditing: {
enabled: true,
},
beta: {
treeArrayEditing: {
enabled: true,
},
},
})
Expand Down
8 changes: 3 additions & 5 deletions dev/test-studio/sanity.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,9 @@ const sharedSettings = definePlugin({
bundles: testStudioLocaleBundles,
},

features: {
beta: {
treeArrayEditing: {
enabled: true,
},
beta: {
treeArrayEditing: {
enabled: true,
},
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,9 @@ function getSchemaTypes(opts: GetSchemaTypesOpts) {
]
}

const FEATURES: WorkspaceOptions['features'] = {
beta: {
treeArrayEditing: {
enabled: true,
},
const FEATURES: WorkspaceOptions['beta'] = {
treeArrayEditing: {
enabled: true,
},
}

Expand All @@ -170,7 +168,7 @@ export function TreeEditingStory(props: TreeEditingStoryProps): JSX.Element {
const types = getSchemaTypes({legacyEditing})

return (
<TestWrapper schemaTypes={types} features={FEATURES}>
<TestWrapper schemaTypes={types} betaFeatures={FEATURES}>
<VirtualizerScrollInstanceProvider
containerElement={{current: document.body}}
scrollElement={document.body}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {getMockWorkspace} from '../../../../test/testUtils/getMockWorkspaceFromC

interface TestWrapperProps {
children?: ReactNode
features?: WorkspaceOptions['features']
betaFeatures?: WorkspaceOptions['beta']
schemaTypes: SchemaTypeDefinition[]
}

Expand All @@ -28,7 +28,7 @@ interface TestWrapperProps {
* It provides a mock Sanity client and a mock workspace.
*/
export const TestWrapper = (props: TestWrapperProps): JSX.Element | null => {
const {children, schemaTypes, features} = props
const {children, schemaTypes, betaFeatures} = props
const [mockWorkspace, setMockWorkspace] = useState<Workspace | null>(null)

useEffect(() => {
Expand All @@ -42,7 +42,7 @@ export const TestWrapper = (props: TestWrapperProps): JSX.Element | null => {
types: schemaTypes,
},

features,
beta: betaFeatures,
})

const workspace = await getMockWorkspace({client, config})
Expand All @@ -51,7 +51,7 @@ export const TestWrapper = (props: TestWrapperProps): JSX.Element | null => {
}

getWorkspace()
}, [schemaTypes, features])
}, [schemaTypes, betaFeatures])

if (!mockWorkspace) {
return null
Expand Down
4 changes: 2 additions & 2 deletions packages/sanity/src/core/config/configPropertyReducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,13 @@ export const arrayEditingReducer = (opts: {
const flattenedConfig = flattenConfig(config, [])

const result = flattenedConfig.reduce((acc, {config: innerConfig}) => {
const resolver = innerConfig.features?.beta?.treeArrayEditing?.enabled
const resolver = innerConfig.beta?.treeArrayEditing?.enabled

if (!resolver && typeof resolver !== 'boolean') return acc
if (typeof resolver === 'boolean') return resolver

throw new Error(
`Expected \`features.beta.treeArrayEditing.enabled\` to be a boolean, but received ${getPrintableType(
`Expected \`beta.treeArrayEditing.enabled\` to be a boolean, but received ${getPrintableType(
resolver,
)}`,
)
Expand Down
8 changes: 3 additions & 5 deletions packages/sanity/src/core/config/prepareConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,11 +627,9 @@ function resolveSource({
staticInitialValueTemplateItems,
options: config,
},
features: {
beta: {
treeArrayEditing: {
enabled: arrayEditingReducer({config, initialValue: false}),
},
beta: {
treeArrayEditing: {
enabled: arrayEditingReducer({config, initialValue: false}),
},
},
}
Expand Down
27 changes: 11 additions & 16 deletions packages/sanity/src/core/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,10 @@ export interface PluginOptions {
*/
enableLegacySearch?: boolean
}
/** Configuration for studio features.
/** Configuration for studio beta features.
* @internal
*/
features?: Features
beta?: BetaFeatures
}

/** @internal */
Expand Down Expand Up @@ -780,7 +780,7 @@ export interface Source {
/** Configuration for studio features.
* @internal
*/
features?: Features
beta?: BetaFeatures
}

/** @internal */
Expand Down Expand Up @@ -897,20 +897,15 @@ export type DefaultPluginsWorkspaceOptions = {
/**
* Configuration for studio features.
* */
interface Features {
interface BetaFeatures {
/**
* Configuration for beta features.
*/
beta?: {
* @beta
* @hidden
* */
treeArrayEditing?: {
/**
* @beta
* @hidden
* */
treeArrayEditing?: {
/**
* Enables the tree array editing feature.
*/
enabled: boolean
}
* Enables the tree array editing feature.
*/
enabled: boolean
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,9 @@ const nestedWrapper = ({children}: PropsWithChildren) => (
describe('useTreeEditingEnabled', () => {
test('should return enabled: false when config is not enabled', () => {
const features = {
features: {
beta: {
treeArrayEditing: {
enabled: false,
},
beta: {
treeArrayEditing: {
enabled: false,
},
},
}
Expand All @@ -44,11 +42,9 @@ describe('useTreeEditingEnabled', () => {

test('should return enabled: true when config is enabled', () => {
const features = {
features: {
beta: {
treeArrayEditing: {
enabled: true,
},
beta: {
treeArrayEditing: {
enabled: true,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface TreeEditingEnabledProviderProps {
export function TreeEditingEnabledProvider(props: TreeEditingEnabledProviderProps): JSX.Element {
const {children, legacyEditing: legacyEditingProp} = props

const {features} = useSource()
const {beta} = useSource()
const parentContextValue = useTreeEditingEnabled()

const value = useMemo((): TreeEditingEnabledContextValue => {
Expand All @@ -26,14 +26,10 @@ export function TreeEditingEnabledProvider(props: TreeEditingEnabledProviderProp
legacyEditingProp

return {
enabled: features?.beta?.treeArrayEditing?.enabled === true,
enabled: beta?.treeArrayEditing?.enabled === true,
legacyEditing: Boolean(legacyEditing),
}
}, [
features?.beta?.treeArrayEditing?.enabled,
legacyEditingProp,
parentContextValue.legacyEditing,
])
}, [beta?.treeArrayEditing?.enabled, legacyEditingProp, parentContextValue.legacyEditing])

return (
<TreeEditingEnabledContext.Provider value={value}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function DocumentStatusBarActionsInner(props: DocumentStatusBarActionsInnerProps
const {__internal_tasks, schemaType, openPath} = useDocumentPane()
const [firstActionState, ...menuActionStates] = states
const [buttonElement, setButtonElement] = useState<HTMLButtonElement | null>(null)
const isTreeArrayEditingEnabled = useSource().features?.beta?.treeArrayEditing?.enabled
const isTreeArrayEditingEnabled = useSource().beta?.treeArrayEditing?.enabled

// Disable the main document action if the array dialog is open
const isTreeArrayEditingEnabledOpen = useMemo(() => {
Expand Down
Loading