-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4775d0d
commit 957b1c6
Showing
11 changed files
with
102 additions
and
73 deletions.
There are no files selected for viewing
File renamed without changes.
18 changes: 18 additions & 0 deletions
18
...end/libs/studio-components/src/components/StudioReferenceButton/StudioReferenceButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from 'react'; | ||
import { StudioButton } from '@studio/components'; | ||
import classes from './StudioReferenceButton.module.css'; | ||
import type { ReferenceNode } from '../../../../../packages/schema-model'; | ||
|
||
export interface StudioReferenceButtonProps { | ||
name: string; | ||
onClick: () => void; | ||
node: ReferenceNode; | ||
} | ||
|
||
export const StudioReferenceButton = ({ name, onClick, node }: StudioReferenceButtonProps) => { | ||
return ( | ||
<StudioButton className={classes.root} color='second' onClick={onClick} variant='secondary'> | ||
{name} | ||
</StudioButton> | ||
); | ||
}; |
1 change: 1 addition & 0 deletions
1
frontend/libs/studio-components/src/components/StudioReferenceButton/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { StudioReferenceButton } from './StudioReferenceButton'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...a-editor/src/components/SchemaInspector/ItemFieldsTab/ItemFieldsTable/ItemFieldsTypes.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import React from 'react'; | ||
import { extractNameFromPointer, isReference, type UiSchemaNode } from '@altinn/schema-model/index'; | ||
import { StudioReferenceButton } from '@studio/components'; | ||
import { useSavableSchemaModel } from '@altinn/schema-editor/hooks/useSavableSchemaModel'; | ||
import { useSchemaEditorAppContext } from '@altinn/schema-editor/hooks/useSchemaEditorAppContext'; | ||
|
||
type ItemFieldsTypesProps = { | ||
fieldNode: UiSchemaNode; | ||
typeLabel?: string; | ||
kindLabel?: string; | ||
}; | ||
|
||
export const ItemFieldsTypes = ({ fieldNode, typeLabel, kindLabel }: ItemFieldsTypesProps) => { | ||
const savableModel = useSavableSchemaModel(); | ||
const { setSelectedTypePointer } = useSchemaEditorAppContext(); | ||
|
||
if (typeLabel) return <>{typeLabel}</>; | ||
if (kindLabel) return <>{kindLabel}</>; | ||
if (isReference(fieldNode)) { | ||
const referredNode = savableModel.getReferredNode(fieldNode); | ||
const name = extractNameFromPointer(referredNode.pointer); | ||
const handleClick = () => setSelectedTypePointer(fieldNode.reference); | ||
return <StudioReferenceButton name={name} onClick={handleClick} node={fieldNode} />; | ||
} | ||
return null; | ||
}; |
15 changes: 15 additions & 0 deletions
15
frontend/packages/schema-editor/src/components/SchemaInspector/hooks/useKindNames.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { ObjectKind } from '@altinn/schema-model/types'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
type KindNames = { | ||
[kind in ObjectKind]: string; | ||
}; | ||
|
||
export function useKindNames(): KindNames { | ||
const { t } = useTranslation(); | ||
return { | ||
[ObjectKind.Field]: t('schema_editor.field'), | ||
[ObjectKind.Combination]: t('schema_editor.combination'), | ||
[ObjectKind.Reference]: t('schema_editor.reference'), | ||
}; | ||
} |
25 changes: 0 additions & 25 deletions
25
frontend/packages/schema-editor/src/components/SchemaInspector/hooks/useKindOption.ts
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
frontend/packages/schema-editor/src/components/SchemaInspector/hooks/useKindOptions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* import { useTranslation } from 'react-i18next'; */ | ||
import type { ObjectKind } from '@altinn/schema-model'; | ||
import { useKindNames } from './useKindNames'; | ||
|
||
type KindOption = { | ||
kind: ObjectKind; | ||
label: string; | ||
}; | ||
|
||
export const useKindOptions = (): KindOption[] => { | ||
const kindNames = useKindNames(); | ||
return Object.entries(kindNames).map(([kind, label]) => ({ | ||
kind: kind as ObjectKind, | ||
label, | ||
})); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters