Skip to content

Commit 5e31e77

Browse files
gpousselgoniszewskiSparkenstein
authored
Fix issue #153: creation/update of root categories (#157)
* chore: release v0.4.3 (#149) * chore: release v0.4.1-hotfix.3 * fix(data-migration): early return if no categories have parents (#128) Signed-off-by: Robert Goniszewski <[email protected]> * Closes #130 (#131) Signed-off-by: Robert Goniszewski <[email protected]> * fix(database): use dynamic path for SQLite database file Signed-off-by: Robert Goniszewski <[email protected]> * docs(readme): use single README file for latest/preview version Signed-off-by: Robert Goniszewski <[email protected]> * feat(ci): add manual deployment workflow and adjust tag conditions Signed-off-by: Robert Goniszewski <[email protected]> * refactor(workflow): simplify manual-deploy GitHub Action Signed-off-by: Robert Goniszewski <[email protected]> * fix(metadata): handle multiple image URLs in mainImageUrl field Signed-off-by: Robert Goniszewski <[email protected]> * fix: auth error handling (#144) * refactor(api): migrate Swagger UI to external documentation and enhance health endpoint Signed-off-by: Robert Goniszewski <[email protected]> * chore: release v0.4.3 --------- Signed-off-by: Robert Goniszewski <[email protected]> Co-authored-by: Prabhanjan <[email protected]> * Fix creation/update of root categories --------- Signed-off-by: Robert Goniszewski <[email protected]> Co-authored-by: Robert Goniszewski <[email protected]> Co-authored-by: Prabhanjan <[email protected]>
1 parent b39fda2 commit 5e31e77

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

src/lib/components/AddCategoryForm/AddCategoryForm.svelte

+6-7
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,25 @@
2828
let form: HTMLFormElement;
2929
export let closeModal: () => void;
3030
31-
const categoriesOptions = writable<{ value: string; label: string }[]>([
31+
const categoriesOptions = writable<{ value: string | null; label: string }[]>([
3232
{
33-
value: 'null',
33+
value: null,
3434
label: 'No parent'
3535
}
3636
]);
3737
3838
$: {
3939
$categoriesOptions = [
4040
{
41-
value: 'null',
41+
value: null,
4242
label: 'No parent'
4343
},
4444
...$page.data.categories
4545
.filter((c) => {
4646
return c.id !== $category.id;
4747
})
4848
.map((c) => ({
49-
value: c.id,
49+
value: c.id.toString(),
5050
label: c.name
5151
}))
5252
];
@@ -224,13 +224,12 @@
224224
name="parent"
225225
searchable
226226
placeholder="Select parent category..."
227-
required
228-
value={$category.parent?.id || $categoriesOptions[0].value}
227+
value={$category.parent?.id?.toString() || $categoriesOptions[0].value}
229228
items={$categoriesOptions}
230229
class="this-select input input-bordered w-max"
231230
on:change={(event) => {
232231
// @ts-ignore-next-line
233-
$category.parent = $page.data.categories.find((c) => c.id === event.detail.value);
232+
$category.parent = $page.data.categories.find((c) => c.id.toString() === event.detail.value);
234233
}}
235234
/>
236235
</div>

src/lib/components/EditCategoryForm/EditCategoryForm.svelte

+6-7
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@
1616
let form: HTMLFormElement;
1717
export let closeModal: () => void;
1818
19-
const categoriesOptions = writable<{ value: number; label: string }[]>([
19+
const categoriesOptions = writable<{ value: string | null; label: string }[]>([
2020
{
21-
value: 0,
21+
value: null,
2222
label: 'No parent'
2323
}
2424
]);
2525
2626
$: {
2727
$categoriesOptions = [
2828
{
29-
value: 0,
29+
value: null,
3030
label: 'No parent'
3131
},
3232
...$page.data.categories
3333
.filter((c) => {
3434
return c.id !== $category.id;
3535
})
3636
.map((c) => ({
37-
value: c.id,
37+
value: c.id.toString(),
3838
label: c.name
3939
}))
4040
];
@@ -214,13 +214,12 @@
214214
name="parent"
215215
searchable
216216
placeholder="Select parent category..."
217-
required
218-
value={$category.parent?.id || $categoriesOptions[0].value}
217+
value={$category.parent?.id?.toString() || $categoriesOptions[0].value}
219218
items={$categoriesOptions}
220219
class="this-select input input-bordered w-max"
221220
on:change={(event) => {
222221
// @ts-ignore-next-line
223-
$category.parent = $page.data.categories.find((c) => c.id === event.detail.value);
222+
$category.parent = $page.data.categories.find((c) => c.id.toString() === event.detail.value);
224223
}}
225224
/>
226225
</div>

src/routes/+page.server.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ export const actions = {
290290
const description = data.get('description') as string;
291291
const icon = data.get('icon') as string;
292292
const color = data.get('color') as string;
293-
const parent = JSON.parse(data.get('parent') as string);
293+
const parent = data.get('parent') ? JSON.parse(data.get('parent') as string) : null;
294294
const parentValue = parent?.value ? parent.value : parent;
295295
const archived = data.get('archived') === 'on' ? new Date() : null;
296296
const setPublic = data.get('public') === 'on' ? new Date() : null;
@@ -301,7 +301,7 @@ export const actions = {
301301
description,
302302
icon,
303303
color,
304-
parentId: parentValue === 'null' ? null : parentValue,
304+
parentId: parentValue,
305305
archived,
306306
public: setPublic,
307307
ownerId,
@@ -332,7 +332,7 @@ export const actions = {
332332
const description = data.get('description') as string;
333333
const icon = data.get('icon') as string;
334334
const color = data.get('color') as string;
335-
const parent = JSON.parse(data.get('parent') as string);
335+
const parent = data.get('parent') ? JSON.parse(data.get('parent') as string) : null;
336336
const parentValue = parent?.value ? parent.value : parent;
337337
const archived = data.get('archived') === 'on' ? new Date() : null;
338338
const setPublic = data.get('public') === 'on' ? new Date() : null;
@@ -343,7 +343,7 @@ export const actions = {
343343
description,
344344
icon,
345345
color,
346-
parentId: parentValue === 'null' ? null : parentValue,
346+
parentId: parentValue,
347347
archived,
348348
public: setPublic
349349
};

0 commit comments

Comments
 (0)