Skip to content

Commit

Permalink
Merge branch 'feature/AB#16658' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefwint committed Jan 26, 2024
2 parents cc45740 + e8d6ed3 commit d6d8e7e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 11 deletions.
46 changes: 41 additions & 5 deletions src/components/DynamicObject/ObjectArea/ObjectArea.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,62 @@
import { Heading, Notification, Text } from '@pzh-ui/components'
import { LayerGroup, Lightbulb } from '@pzh-ui/icons'

import { Werkingsgebied } from '@/api/fetchers.schemas'
import {
useModulesModuleIdObjectWerkingsgebiedLatestLineageIdGet,
useWerkingsgebiedenLatestLineageIdGet,
} from '@/api/fetchers'
import { WerkingsgebiedStatics } from '@/api/fetchers.schemas'
import { LeafletTinyViewer } from '@/components/Leaflet'
import { Model } from '@/config/objects/types'

interface ObjectAreaProps extends Werkingsgebied {
interface ObjectAreaProps extends WerkingsgebiedStatics {
objectTitle?: string
moduleId?: string
model: Model
}

const ObjectArea = ({ objectTitle, model, UUID, Title }: ObjectAreaProps) => {
const ObjectArea = ({
objectTitle,
moduleId,
model,
Object_ID,
}: ObjectAreaProps) => {
const { singular, prefixSingular } = model.defaults

const { data: moduleData, isSuccess } =
useModulesModuleIdObjectWerkingsgebiedLatestLineageIdGet(
parseInt(moduleId!),
Object_ID,
{
query: {
enabled: !!moduleId && !!Object_ID,
},
}
)

const { data: validData } = useWerkingsgebiedenLatestLineageIdGet(
Object_ID,
{
query: {
enabled:
(!moduleId && !!Object_ID) ||
(!!moduleId && !!Object_ID && !moduleData && isSuccess),
},
}
)

const data = moduleId && isSuccess ? moduleData : validData

if (!data) return null

return (
<div data-section="Werkingsgebied">
<Heading level="2" className="mb-4">
Werkingsgebied
</Heading>
<Text className="mb-4 first-letter:capitalize">
{prefixSingular} {singular}{objectTitle}’ heeft als
werkingsgebied ‘{Title}’.
werkingsgebied ‘{data.Title}’.
</Text>

<Notification icon={Lightbulb} className="mb-3">
Expand All @@ -35,7 +71,7 @@ const ObjectArea = ({ objectTitle, model, UUID, Title }: ObjectAreaProps) => {
</Notification>

<div className="h-[500px] overflow-hidden rounded-lg">
<LeafletTinyViewer uuid={UUID} />
<LeafletTinyViewer uuid={data.Area?.Source_UUID || ''} />
</div>
</div>
)
Expand Down
15 changes: 11 additions & 4 deletions src/pages/protected/DynamicObject/ObjectEdit/ObjectEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,21 @@ const ObjectEdit = ({ model }: ObjectEditProps) => {
onCancel={() => navigate(`/muteer/modules/${moduleId}`)}
isLocked={isLocked}
isLoading={isLoading || moduleIsLoading}
defaultValues={
object?.Hierarchy_Statics && {
defaultValues={{
...(object?.Hierarchy_Statics && {
Hierarchy_Code: {
label: object?.Hierarchy_Statics?.Cached_Title,
value: object?.Hierarchy_Statics?.Code,
},
}
}
}),
...(object?.Werkingsgebied_Statics && {
Werkingsgebied_Code: {
label: object?.Werkingsgebied_Statics
?.Cached_Title,
value: object?.Werkingsgebied_Statics?.Code,
},
}),
}}
/>
</div>
</MutateLayout>
Expand Down
5 changes: 3 additions & 2 deletions src/pages/public/DynamicObject/DynamicObject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,12 +221,13 @@ const DynamicObject = ({ model, isRevision }: DynamicObjectProps) => {
/>
</div>

{data?.Gebied && (
{data?.Werkingsgebied_Statics && (
<div className="order-7">
<ObjectArea
model={model}
objectTitle={data.Title}
{...data.Gebied}
moduleId={moduleId}
{...data.Werkingsgebied_Statics}
/>
</div>
)}
Expand Down

0 comments on commit d6d8e7e

Please sign in to comment.