Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/dev' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
adrians5j committed Sep 26, 2024
2 parents ddc0012 + 5f712dd commit f9da84b
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 33 deletions.
103 changes: 103 additions & 0 deletions packages/api-headless-cms/__tests__/contentAPI/mocks/contentModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,109 @@ const models: CmsModel[] = [
tenant: "root",
webinyVersion
},
// category
{
createdOn: new Date().toISOString(),
savedOn: new Date().toISOString(),
locale: "en-US",
titleFieldId: "title",
lockedFields: [],
name: "Category Singleton",
description: "Product category Singleton",
modelId: "categorySingleton",
singularApiName: "CategoryApiNameWhichIsABitDifferentThanModelIdSingleton",
pluralApiName: "CategoriesApiModelSingleton",
group: {
id: contentModelGroup.id,
name: contentModelGroup.name
},
layout: [[ids.field11], [ids.field12]],
fields: [
{
id: ids.field11,
multipleValues: false,
helpText: "",
label: "Title",
type: "text",
storageId: "text@titleStorageId",
fieldId: "title",
validation: [
{
name: "required",
message: "This field is required"
},
{
name: "minLength",
message: "Enter at least 3 characters",
settings: {
min: 3.0
}
}
],
listValidation: [],
placeholderText: "placeholder text",
predefinedValues: {
enabled: false,
values: []
},
renderer: {
name: "renderer"
}
},
{
id: ids.field12,
multipleValues: false,
helpText: "",
label: "Slug",
type: "text",
storageId: "text@slugStorageId",
fieldId: "slug",
validation: [
{
name: "required",
message: "This field is required"
}
],
listValidation: [],
placeholderText: "placeholder text",
predefinedValues: {
enabled: false,
values: []
},
renderer: {
name: "renderer"
}
},
{
id: ids.field34,
multipleValues: false,
helpText: "",
label: "Category",
type: "ref",
storageId: "ref@categoryRef",
fieldId: "categoryRef",
validation: [],
listValidation: [],
placeholderText: "placeholder text",
settings: {
models: [
{
modelId: "categorySingleton"
}
]
},
predefinedValues: {
enabled: false,
values: []
},
renderer: {
name: "renderer"
}
}
],
tenant: "root",
webinyVersion
},
// product
{
createdOn: new Date().toISOString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CMS_MODEL_SINGLETON_TAG } from "~/constants";

describe("singleton model content entries", () => {
const plugins = createPluginFromCmsModel({
...getCmsModel("category"),
...getCmsModel("categorySingleton"),
tags: [CMS_MODEL_SINGLETON_TAG]
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const updateCategoryMutation = (model: CmsModel) => {
};

export const useSingletonCategoryHandler = (params: GraphQLHandlerParams) => {
const model = getCmsModel("category");
const model = getCmsModel("categorySingleton");
const contentHandler = useGraphQLHandler(params);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const createSingularResolvers: CreateSingularResolvers = ({
}

const createFieldResolvers = createFieldResolversFactory({
endpointType: "manage",
endpointType: type,
models,
model,
fieldTypePlugins
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const createSingularSDL: CreateSingularSDL = ({
models,
model,
fields: model.fields,
type: "manage",
type,
fieldTypePlugins
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ interface Params {
export const createGraphQLSchemaPluginFromFieldPlugins = (params: Params) => {
const { models, fieldTypePlugins, type, createPlugin = defaultCreatePlugin } = params;

const apiType = TYPE_MAP[type];

const plugins: ICmsGraphQLSchemaPlugin[] = [];
for (const key in fieldTypePlugins) {
const fieldTypePlugin = fieldTypePlugins[key];
if (!TYPE_MAP[type] || !fieldTypePlugin[TYPE_MAP[type]]) {
if (!apiType || !fieldTypePlugin[apiType]) {
continue;
}
const createSchema = fieldTypePlugin[TYPE_MAP[type]].createSchema;
const createSchema = fieldTypePlugin[apiType].createSchema;
// Render gql types generated by field type plugins
if (!createSchema) {
continue;
Expand Down
4 changes: 2 additions & 2 deletions packages/app-aco/src/contexts/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ interface CreateAppParams {
getFields?: () => AcoModelField[];
}

const createApp = (data: CreateAppParams): AcoApp => {
export const createAppFromModel = (data: CreateAppParams): AcoApp => {
return {
...data,
getFields:
Expand Down Expand Up @@ -138,7 +138,7 @@ export const AcoAppProvider = ({
...prev,
loading: false,
model: inputModel,
app: createApp({
app: createAppFromModel({
id,
model: inputModel,
getFields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,19 @@ import {
import { useCms } from "~/admin/hooks";
import { FullWidthDialog } from "./dialog/Dialog";
import { NavigateFolderProvider as AbstractNavigateFolderProvider } from "@webiny/app-aco/contexts/navigateFolder";
import { SearchRecordsProvider } from "@webiny/app-aco/contexts/records";
import { FolderTree, useNavigateFolder } from "@webiny/app-aco";
import styled from "@emotion/styled";
import { Elevation } from "@webiny/ui/Elevation";
import { SplitView, LeftPanel, RightPanel } from "@webiny/app-admin/components/SplitView";
import { CircularProgress } from "@webiny/ui/Progress";
import { usePersistEntry } from "~/admin/hooks/usePersistEntry";
import {
AcoAppContext,
AcoAppProviderContext,
createAppFromModel
} from "@webiny/app-aco/contexts/app";
import { DialogsProvider } from "@webiny/app-admin";

const t = i18n.ns("app-headless-cms/admin/fields/ref");

Expand Down Expand Up @@ -159,22 +166,46 @@ export const NewReferencedEntryDialog = ({
},
[onChange, model]
);

if (!model) {
return null;
}

const acoAppContext: AcoAppProviderContext = {
app: createAppFromModel({
model,
id: `cms:${model.modelId}`
}),
mode: "cms",
client: apolloClient,
model,
folderIdPath: "wbyAco_location.folderId",
folderIdInPath: "wbyAco_location.folderId_in",
loading: false
};

return (
<ContentEntriesProvider contentModel={model} key={model.modelId} insideDialog={true}>
<FoldersProvider type={`cms:${model.modelId}`}>
<NavigateFolderProvider modelId={model.modelId}>
<ContentEntryProviderWithCurrentFolderId
model={model}
onClose={onClose}
onCreate={onCreate}
/>
</NavigateFolderProvider>
<AcoAppContext.Provider value={acoAppContext}>
<FoldersProvider>
<SearchRecordsProvider>
<NavigateFolderProvider modelId={model.modelId}>
<DialogsProvider>
<ContentEntriesProvider
contentModel={model}
key={model.modelId}
insideDialog={true}
>
<ContentEntryProviderWithCurrentFolderId
model={model}
onClose={onClose}
onCreate={onCreate}
/>
</ContentEntriesProvider>
</DialogsProvider>
</NavigateFolderProvider>
</SearchRecordsProvider>
</FoldersProvider>
</ContentEntriesProvider>
</AcoAppContext.Provider>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,7 @@ const NewContentModelDialog = ({ open, onClose }: NewContentModelDialogProps) =>
return (
<Dialog open={open} onClose={onClose} data-testid="cms-new-content-model-modal">
{open && (
<Form<CmsModelData>
data={{ group, singleton: false }}
onSubmit={data => {
console.log("submitting", data);
onSubmit(data);
}}
>
<Form<CmsModelData> data={{ group, singleton: false }} onSubmit={onSubmit}>
{({ Bind, submit, data }) => {
return (
<>
Expand Down Expand Up @@ -288,12 +282,7 @@ const NewContentModelDialog = ({ open, onClose }: NewContentModelDialogProps) =>
</Grid>
</UID.DialogContent>
<UID.DialogActions>
<ButtonPrimary
onClick={ev => {
console.log("submitting click", data);
submit(ev);
}}
>
<ButtonPrimary onClick={submit}>
+ {t`Create Model`}
</ButtonPrimary>
</UID.DialogActions>
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/DelayedOnChange/DelayedOnChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const emptyFunction = (): undefined => {
export interface ApplyValueCb<TValue> {
(value: TValue): void;
}

/**
* This component is used to wrap Input and Textarea components to optimize form re-render.
* These 2 are the only components that trigger form model change on each character input.
Expand Down Expand Up @@ -145,7 +146,7 @@ export const DelayedOnChange = <TValue = any>({
if (ev.key === "Tab") {
applyValue((ev.target as HTMLInputElement).value as any as TValue);
realOnKeyDown(ev);
} else if (ev.key === "Enter" && props["data-on-enter"]) {
} else if (ev.key === "Enter") {
applyValue((ev.target as HTMLInputElement).value as any as TValue);
realOnKeyDown(ev);
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/Select/styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const webinySelect = css`
background-color: transparent;
border-color: transparent;
color: var(--webiny-theme-color-primary);
min-width: 200px;
width: 100%;
.rmwc-select__native-control {
opacity: 0;
Expand Down

0 comments on commit f9da84b

Please sign in to comment.