Skip to content

Commit

Permalink
panel artboard layers crud with entity fetcher strategies and actions
Browse files Browse the repository at this point in the history
  • Loading branch information
goodeats committed Apr 23, 2024
1 parent ad1b07e commit 20e794e
Show file tree
Hide file tree
Showing 31 changed files with 1,012 additions and 130 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { type designParentTypeIdEnum } from '#app/schema/design'
import { type IEntityVisible, type IEntityParentType } from '#app/schema/entity'
import {
type IEntityVisible,
type IEntityParentType,
type entityParentIdTypeEnum,
} from '#app/schema/entity'
import { type IDashboardPanelDeleteEntityStrategy } from '#app/strategies/component/dashboard-panel/delete-entity.strategy'
import { type IDashboardPanelUpdateEntityVisibleStrategy } from '#app/strategies/component/dashboard-panel/update-entity-visible.strategy'
import { SidebarPanelRowActionsContainer } from '..'
Expand All @@ -13,7 +16,7 @@ export const PanelEntityRowActions = ({
strategyEntityDelete,
}: {
entity: IEntityVisible
parentTypeId: designParentTypeIdEnum
parentTypeId: entityParentIdTypeEnum
parent: IEntityParentType
strategyToggleVisible: IDashboardPanelUpdateEntityVisibleStrategy
strategyEntityDelete: IDashboardPanelDeleteEntityStrategy
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { type designParentTypeIdEnum } from '#app/schema/design'
import { type IEntityParentType, type IEntityType } from '#app/schema/entity'
import {
type entityParentIdTypeEnum,
type IEntityParentType,
type IEntityType,
} from '#app/schema/entity'
import { type IDashboardPanelCreateEntityStrategy } from '#app/strategies/component/dashboard-panel/create-entity.strategy'
import { capitalize } from '#app/utils/string-formatting'
import { SidebarPanelHeader, SidebarPanelRowActionsContainer } from '..'
Expand All @@ -12,7 +15,7 @@ export const PanelEntityHeader = ({
strategyEntityNew,
}: {
type: IEntityType
parentTypeId: designParentTypeIdEnum
parentTypeId: entityParentIdTypeEnum
parent: IEntityParentType
strategyEntityNew: IDashboardPanelCreateEntityStrategy
}) => {
Expand Down
83 changes: 43 additions & 40 deletions app/components/templates/panel/dashboard-entity-panel.reorder.tsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
import { type designParentTypeIdEnum } from '#app/schema/design'
import { type IEntity, type IEntityParentType } from '#app/schema/entity'
import {
type entityParentIdTypeEnum,
type IEntity,
type IEntityParentType,
} from '#app/schema/entity'
import { type IDashboardPanelUpdateEntityOrderStrategy } from '#app/strategies/component/dashboard-panel/update-entity-move.strategy'
import { SidebarPanelRowReorderContainer } from '..'
import { FormFetcherMoveIcon } from '../form/fetcher/move-icon'

export const PanelEntityRowReorder = ({
entity,
parentTypeId,
parent,
entityCount,
entityIndex,
strategyReorder,
entity,
parentTypeId,
parent,
entityCount,
entityIndex,
strategyReorder,
}: {
entity: IEntity
parentTypeId: designParentTypeIdEnum
parent: IEntityParentType
entityCount: number
entityIndex: number
strategyReorder: IDashboardPanelUpdateEntityOrderStrategy
entity: IEntity
parentTypeId: entityParentIdTypeEnum
parent: IEntityParentType
entityCount: number
entityIndex: number
strategyReorder: IDashboardPanelUpdateEntityOrderStrategy
}) => {
const atTop = entityIndex === 0
const atBottom = entityIndex === entityCount - 1
const atTop = entityIndex === 0
const atBottom = entityIndex === entityCount - 1

return (
<SidebarPanelRowReorderContainer>
<FormFetcherMoveIcon
entityId={entity.id}
parentTypeId={parentTypeId}
parentId={parent.id}
route={strategyReorder.route}
formId={strategyReorder.formId}
schema={strategyReorder.schema}
direction="up"
atTopOrBottom={atTop}
/>
<FormFetcherMoveIcon
entityId={entity.id}
parentTypeId={parentTypeId}
parentId={parent.id}
route={strategyReorder.route}
formId={strategyReorder.formId}
schema={strategyReorder.schema}
direction="down"
atTopOrBottom={atBottom}
/>
</SidebarPanelRowReorderContainer>
)
return (
<SidebarPanelRowReorderContainer>
<FormFetcherMoveIcon
entityId={entity.id}
parentTypeId={parentTypeId}
parentId={parent.id}
route={strategyReorder.route}
formId={strategyReorder.formId}
schema={strategyReorder.schema}
direction="up"
atTopOrBottom={atTop}
/>
<FormFetcherMoveIcon
entityId={entity.id}
parentTypeId={parentTypeId}
parentId={parent.id}
route={strategyReorder.route}
formId={strategyReorder.formId}
schema={strategyReorder.schema}
direction="down"
atTopOrBottom={atBottom}
/>
</SidebarPanelRowReorderContainer>
)
}
4 changes: 2 additions & 2 deletions app/components/templates/panel/dashboard-entity-panel.row.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { type designParentTypeIdEnum } from '#app/schema/design'
import {
type IEntityVisible,
type IEntity,
type IEntityParentType,
type entityParentIdTypeEnum,
} from '#app/schema/entity'
import { type IDashboardPanelDeleteEntityStrategy } from '#app/strategies/component/dashboard-panel/delete-entity.strategy'
import { type IDashboardPanelUpdateEntityOrderStrategy } from '#app/strategies/component/dashboard-panel/update-entity-move.strategy'
Expand All @@ -23,7 +23,7 @@ export const PanelEntityRow = ({
children,
}: {
entity: IEntity
parentTypeId: designParentTypeIdEnum
parentTypeId: entityParentIdTypeEnum
parent: IEntityParentType
entityCount: number
entityIndex: number
Expand Down
22 changes: 9 additions & 13 deletions app/components/templates/panel/dashboard-entity-panel.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { type IArtboardVersionWithDesignsAndLayers } from '#app/models/artboard-version/artboard-version.server'
import { type IDesignWithType } from '#app/models/design.server'
import {
type designParentTypeIdEnum,
type designTypeEnum,
} from '#app/schema/design'
type IEntity,
type IEntityParentType,
type IEntityType,
type entityParentIdTypeEnum,
} from '#app/schema/entity'
import { type IDashboardPanelCreateEntityStrategy } from '#app/strategies/component/dashboard-panel/create-entity.strategy'
import { type IDashboardPanelDeleteEntityStrategy } from '#app/strategies/component/dashboard-panel/delete-entity.strategy'
import { type IDashboardPanelUpdateEntityValuesStrategy } from '#app/strategies/component/dashboard-panel/update-entity/update-entity-values'
Expand All @@ -14,10 +14,6 @@ import { PanelEntityHeader } from './dashboard-entity-panel.header'
import { PanelEntityRow } from './dashboard-entity-panel.row'
import { PanelEntityValues } from './dashboard-entity-panel.values'

type PanelEntities = IDesignWithType[]
type PanelEntityType = designTypeEnum
type PanelEntityParent = IArtboardVersionWithDesignsAndLayers

export const DashboardEntityPanel = ({
type,
parentTypeId,
Expand All @@ -29,10 +25,10 @@ export const DashboardEntityPanel = ({
strategyToggleVisible,
strategyEntityDelete,
}: {
type: PanelEntityType
parentTypeId: designParentTypeIdEnum
parent: PanelEntityParent
entities: PanelEntities
type: IEntityType
parentTypeId: entityParentIdTypeEnum
parent: IEntityParentType
entities: IEntity[]
strategyEntityNew: IDashboardPanelCreateEntityStrategy
strategyReorder: IDashboardPanelUpdateEntityOrderStrategy
strategyEntityValues: IDashboardPanelUpdateEntityValuesStrategy
Expand Down
18 changes: 18 additions & 0 deletions app/models/layer/layer.create.server.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { type IntentActionArgs } from '#app/definitions/intent-action-args'
import { NewArtboardVersionLayerSchema } from '#app/schema/layer-artboard-version'
import { ValidateArtboardVersionParentSubmissionStrategy } from '#app/strategies/validate-submission.strategy'
import { validateEntitySubmission } from '#app/utils/conform-utils'
import { prisma } from '#app/utils/db.server'
import { type ILayer } from '../layer.server'

Expand All @@ -7,6 +11,20 @@ export interface ILayerCreatedResponse {
createdLayer?: ILayer
}

export const validateArtboardVersionNewLayerSubmission = async ({
userId,
formData,
}: IntentActionArgs) => {
const strategy = new ValidateArtboardVersionParentSubmissionStrategy()

return await validateEntitySubmission({
userId,
formData,
schema: NewArtboardVersionLayerSchema,
strategy,
})
}

export const createLayer = async ({
data,
}: {
Expand Down
31 changes: 31 additions & 0 deletions app/models/layer/layer.delete.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { type IntentActionArgs } from '#app/definitions/intent-action-args'
import { DeleteArtboardVersionLayerSchema } from '#app/schema/layer-artboard-version'
import { ValidateArtboardVersionParentSubmissionStrategy } from '#app/strategies/validate-submission.strategy'
import { validateEntitySubmission } from '#app/utils/conform-utils'
import { prisma } from '#app/utils/db.server'
import { type ILayer } from '../layer.server'

export interface ILayerDeletedResponse {
success: boolean
message?: string
}

export const validateArtboardVersionDeleteLayerSubmission = async ({
userId,
formData,
}: IntentActionArgs) => {
const strategy = new ValidateArtboardVersionParentSubmissionStrategy()

return await validateEntitySubmission({
userId,
formData,
schema: DeleteArtboardVersionLayerSchema,
strategy,
})
}

export const deleteLayer = ({ id }: { id: ILayer['id'] }) => {
return prisma.layer.delete({
where: { id },
})
}
13 changes: 12 additions & 1 deletion app/models/layer/layer.get.server.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type whereArgsType } from '#app/schema/layer'
import { prisma } from '#app/utils/db.server'
import { type ILayerWithDesigns } from '../layer.server'
import { type ILayer, type ILayerWithDesigns } from '../layer.server'

export const getLayersWithDesigns = async ({
where,
Expand All @@ -26,3 +26,14 @@ export const getLayersWithDesigns = async ({
})
return layers
}

export const getLayer = async ({
where,
}: {
where: whereArgsType
}): Promise<ILayer | null> => {
const layer = await prisma.layer.findFirst({
where,
})
return layer
}
Loading

0 comments on commit 20e794e

Please sign in to comment.