Skip to content

Commit 9083c8d

Browse files
committed
refactor: remove primary field in pattern
1 parent 10f2112 commit 9083c8d

File tree

4 files changed

+3
-65
lines changed

4 files changed

+3
-65
lines changed

packages/core/admin/screens/Patterns/CreatePage/index.tsx

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,7 @@ const CreatePatternPage = () => {
6161
{ setSubmitting, setErrors }: FormikProps<PatternFormValues>,
6262
) => {
6363
try {
64-
// Check if another primary pattern for the content type already exists
65-
if (values.primary) {
66-
const response = await get<PatternEntity[]>('/webtools/url-pattern/findMany', { method: 'GET' });
67-
// Find the other pattern with the same contenttype that is marked as primary
68-
const existingPrimary = response.data.find(
69-
(pattern: PatternEntity) => pattern.contenttype ===
70-
values.contenttype &&
71-
pattern.primary === true,
72-
);
73-
74-
if (existingPrimary) {
75-
// Step 2: Unset the primary status of the existing primary pattern
76-
await put(`/webtools/url-pattern/update/${existingPrimary.id}`, {
77-
data: { ...existingPrimary, primary: false },
78-
});
79-
}
80-
}
81-
82-
// Proceed to create the new pattern (with primary if checked)
64+
// Proceed to create the new pattern
8365
await post('/webtools/url-pattern/create', {
8466
data: values,
8567
});
@@ -143,7 +125,7 @@ const CreatePatternPage = () => {
143125
<Formik<PatternFormValues>
144126
enableReinitialize
145127
initialValues={{
146-
label: '', pattern: '', contenttype: '', languages: [], localized: false, primary: false,
128+
label: '', pattern: '', contenttype: '', languages: [], localized: false,
147129
}}
148130
onSubmit={handleCreateSubmit}
149131
validationSchema={schema}
@@ -232,16 +214,6 @@ const CreatePatternPage = () => {
232214
</GridItem>
233215
<GridItem col={12} />
234216

235-
<GridItem col={12}>
236-
<Checkbox
237-
name="isPrimary"
238-
checked={values.primary}
239-
onChange={(e: { target: { checked: boolean; }; }) => setFieldValue('primary', e.target.checked)}
240-
>
241-
Set as primary
242-
</Checkbox>
243-
</GridItem>
244-
245217
{(values.contenttype !== '') && (
246218
<GridItem col={6}>
247219
<PatternField

packages/core/admin/screens/Patterns/EditPage/index.tsx

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -74,25 +74,7 @@ const EditPatternPage = () => {
7474
{ setSubmitting, setErrors }: FormikProps<PatternFormValues>,
7575
) => {
7676
try {
77-
// Check if another primary pattern for the content type already exists
78-
if (values.primary) {
79-
const response = await get<PatternEntity[]>('/webtools/url-pattern/findMany', { method: 'GET' });
80-
// Find the other pattern with the same contenttype that is marked as primary
81-
const existingPrimary = response.data.find(
82-
(pattern: PatternEntity) => pattern.contenttype === values.contenttype &&
83-
pattern.primary === true &&
84-
pattern.id !== patternEntity.id,
85-
);
86-
87-
if (existingPrimary) {
88-
// Unset the primary status of the existing primary pattern
89-
await put(`/webtools/url-pattern/update/${existingPrimary.id}`, {
90-
data: { ...existingPrimary, primary: false },
91-
});
92-
}
93-
}
94-
95-
// Proceed to update the current pattern (with primary if checked)
77+
// Proceed to update the current pattern
9678
await put(`/webtools/url-pattern/update/${patternEntity.id}`, {
9779
data: values,
9880
});
@@ -168,7 +150,6 @@ const EditPatternPage = () => {
168150
languages: patternEntity.languages,
169151
code: patternEntity.code,
170152
localized: false,
171-
primary: patternEntity.primary || false,
172153
}}
173154
onSubmit={handleEditSubmit}
174155
validationSchema={schema}
@@ -272,16 +253,6 @@ const EditPatternPage = () => {
272253
</GridItem>
273254
<GridItem col={12} />
274255

275-
<GridItem col={12}>
276-
<Checkbox
277-
name="primary"
278-
checked={values.primary}
279-
onChange={(e: { target: { checked: any; }; }) => setFieldValue('primary', e.target.checked)}
280-
>
281-
Set as primary
282-
</Checkbox>
283-
</GridItem>
284-
285256
{values.contenttype !== '' && (
286257
<GridItem col={6}>
287258
<PatternField

packages/core/admin/types/url-patterns.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export interface PatternEntity {
55
code: string
66
contenttype: string
77
languages: any[]
8-
primary?: boolean
98
createdAt: string
109
updatedAt: string
1110
}
@@ -17,7 +16,6 @@ export interface PatternFormValues {
1716
languages: any[],
1817
localized: boolean,
1918
code?: string,
20-
primary?: boolean,
2119
}
2220

2321
export interface ValidatePatternResponse {

packages/core/server/admin-api/content-types/url-pattern/schema.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@
3939
"languages": {
4040
"type": "json",
4141
"required": true
42-
},
43-
"primary": {
44-
"type": "boolean"
4542
}
4643
}
4744
}

0 commit comments

Comments
 (0)