From d3a6cc43ad0bf01f39977c61d7f3879e234ea70f Mon Sep 17 00:00:00 2001 From: Pat Needham Date: Sat, 27 Apr 2024 13:39:41 -0400 Subject: [PATCH] fixed bug for finding first visible design -- needed to order linked list of design types first --- .../templates/form/fetcher/number.tsx | 2 ++ app/models/design-artboard-version.server.ts | 12 ------------ .../design-artboard-version.get.server.ts | 19 +++++++++++++++++++ app/models/design-layer.server.ts | 12 ------------ .../design-layer/design-layer.get.server.ts | 19 +++++++++++++++++++ .../design/update-selected.service.ts | 1 + .../design/update-selected.strategy.ts | 4 ++-- 7 files changed, 43 insertions(+), 26 deletions(-) create mode 100644 app/models/design-artboard-version/design-artboard-version.get.server.ts create mode 100644 app/models/design-layer/design-layer.get.server.ts diff --git a/app/components/templates/form/fetcher/number.tsx b/app/components/templates/form/fetcher/number.tsx index 92b47615..cae56c25 100644 --- a/app/components/templates/form/fetcher/number.tsx +++ b/app/components/templates/form/fetcher/number.tsx @@ -52,6 +52,8 @@ export const FormFetcherNumber = ({ id: `${formId}-${parentId}-${entityId}`, constraint: getFieldsetConstraint(schema), lastSubmission: actionData?.submission, + shouldValidate: 'onInput', + shouldRevalidate: 'onInput', onValidate: ({ formData }) => { return parse(formData, { schema: schema }) }, diff --git a/app/models/design-artboard-version.server.ts b/app/models/design-artboard-version.server.ts index 4ee46bae..876235ea 100644 --- a/app/models/design-artboard-version.server.ts +++ b/app/models/design-artboard-version.server.ts @@ -18,18 +18,6 @@ export interface IDesignWithArtboardVersion extends IDesign { artboardVersion: IArtboardVersion } -export const findFirstVisibleArtboardVersionDesignByType = async ({ - artboardVersionId, - type, -}: { - artboardVersionId: IArtboardVersion['id'] - type: designTypeEnum -}): Promise => { - return await prisma.design.findFirst({ - where: { artboardVersionId, type, visible: true }, - }) -} - export const updateArtboardVersionSelectedDesign = ({ artboardVersionId, designId, diff --git a/app/models/design-artboard-version/design-artboard-version.get.server.ts b/app/models/design-artboard-version/design-artboard-version.get.server.ts new file mode 100644 index 00000000..b23d7d9b --- /dev/null +++ b/app/models/design-artboard-version/design-artboard-version.get.server.ts @@ -0,0 +1,19 @@ +import { type designTypeEnum } from '#app/schema/design' +import { prisma } from '#app/utils/db.server' +import { orderLinkedItems } from '#app/utils/linked-list.utils' +import { type IArtboardVersion } from '../artboard-version/artboard-version.server' +import { type IDesign } from '../design.server' + +export const findFirstVisibleArtboardVersionDesignByType = async ({ + artboardVersionId, + type, +}: { + artboardVersionId: IArtboardVersion['id'] + type: designTypeEnum +}): Promise => { + const designs = await prisma.design.findMany({ + where: { artboardVersionId, type }, + }) + const orderedDesigns = orderLinkedItems(designs) + return orderedDesigns.find(design => design.visible) || null +} diff --git a/app/models/design-layer.server.ts b/app/models/design-layer.server.ts index df292dd9..88a8d416 100644 --- a/app/models/design-layer.server.ts +++ b/app/models/design-layer.server.ts @@ -18,18 +18,6 @@ export interface IDesignWithLayer extends IDesign { layer: ILayer } -export const findFirstVisibleLayerDesignByType = async ({ - layerId, - type, -}: { - layerId: ILayer['id'] - type: designTypeEnum -}): Promise => { - return await prisma.design.findFirst({ - where: { layerId, type, visible: true }, - }) -} - export const updateLayerSelectedDesign = ({ layerId, designId, diff --git a/app/models/design-layer/design-layer.get.server.ts b/app/models/design-layer/design-layer.get.server.ts new file mode 100644 index 00000000..b9f28b29 --- /dev/null +++ b/app/models/design-layer/design-layer.get.server.ts @@ -0,0 +1,19 @@ +import { type designTypeEnum } from '#app/schema/design' +import { prisma } from '#app/utils/db.server' +import { orderLinkedItems } from '#app/utils/linked-list.utils' +import { type IDesign } from '../design.server' +import { type ILayer } from '../layer.server' + +export const findFirstVisibleLayerDesignByType = async ({ + layerId, + type, +}: { + layerId: ILayer['id'] + type: designTypeEnum +}): Promise => { + const designs = await prisma.design.findMany({ + where: { layerId, type }, + }) + const orderedDesigns = orderLinkedItems(designs) + return orderedDesigns.find(design => design.visible) || null +} diff --git a/app/services/design/update-selected.service.ts b/app/services/design/update-selected.service.ts index bfbc9d5d..90c322f5 100644 --- a/app/services/design/update-selected.service.ts +++ b/app/services/design/update-selected.service.ts @@ -28,6 +28,7 @@ export const updateSelectedDesignService = async ({ targetEntityId, type, }) + // if first visible design by type is found, // update the selected design if (firstVisibleDesign) { diff --git a/app/strategies/design/update-selected.strategy.ts b/app/strategies/design/update-selected.strategy.ts index 3cfa9938..5a57507a 100644 --- a/app/strategies/design/update-selected.strategy.ts +++ b/app/strategies/design/update-selected.strategy.ts @@ -1,8 +1,8 @@ import { type IArtboardVersion } from '#app/models/artboard-version/artboard-version.server' import { type IArtboard } from '#app/models/artboard.server' +import { findFirstVisibleArtboardVersionDesignByType } from '#app/models/design-artboard-version/design-artboard-version.get.server' import { deselectArtboardVersionSelectedDesign, - findFirstVisibleArtboardVersionDesignByType, updateArtboardVersionSelectedDesign, } from '#app/models/design-artboard-version.server' import { @@ -10,9 +10,9 @@ import { findFirstVisibleArtboardDesignByType, updateArtboardSelectedDesign, } from '#app/models/design-artboard.server' +import { findFirstVisibleLayerDesignByType } from '#app/models/design-layer/design-layer.get.server' import { deselectLayerSelectedDesign, - findFirstVisibleLayerDesignByType, updateLayerSelectedDesign, } from '#app/models/design-layer.server' import {