Skip to content

Commit

Permalink
Replace convert-type-suggestion with cannot-convert-type-message in s…
Browse files Browse the repository at this point in the history
…chemaInspector
  • Loading branch information
standeren committed Nov 14, 2024
1 parent d6a081a commit 06e6e85
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 43 deletions.
2 changes: 1 addition & 1 deletion frontend/language/src/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"app_create_release.still_building_release": "Bygger fortsatt versjon {{version}}",
"app_create_release_errors.check_status_on_build_error": "Det har skjedd en teknisk feil, så vi får ikke oppdatert statusen på bygget ditt. Vi prøver å sjekke statusen på nytt …",
"app_create_release_errors.fetch_release_failed": "Det har skjedd en teknisk feil som gjør at du ikke kan bygge versjoner akkurat nå. Prøv igjen senere. Hvis problemet fortsetter, <a>ta kontakt med oss</a>.",
"app_data_modelling.fields_information": "Hvis du vil legge til felter på dette elementet, må du konvertere det til et objekt.",
"app_data_modelling.landing_dialog_create": "Lag en ny datamodell",
"app_data_modelling.landing_dialog_header": "Last opp eller lag en ny datamodell for å starte",
"app_data_modelling.landing_dialog_paragraph": "Velkommen til datamodellering! Her kan du laste opp en datamodell du har fra før, eller lage en ny modell du kan bruke i appen din.",
Expand Down Expand Up @@ -875,6 +874,7 @@
"schema_editor.field": "Objekt",
"schema_editor.field_name": "Navn på felt",
"schema_editor.fields": "Felter",
"schema_editor.fields_not_available_on_type": "Denne typen har ingen felter.",
"schema_editor.format": "Format",
"schema_editor.format_date": "Dato",
"schema_editor.format_date-time": "Dato og klokkeslett",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.noItem {
margin: 0;
display: flex;
padding-left: var(--fds-spacing-3);
border-bottom: var(--studio-border-divider);
width: 100%;
padding-block: var(--fds-spacing-5);
text-align: center;
padding-block: var(--fds-spacing-4);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
align-items: center;
display: flex;
padding: var(--gap) 0;
padding-inline: var(--gap);
gap: var(--gap);
}

Expand All @@ -11,13 +12,7 @@
}

.heading .headingButton {
border-bottom-left-radius: 0;
border-left-color: transparent;
border-left-style: solid;
border-left-width: var(--studio-treeitem-vertical-line-width);
border-top-left-radius: 0;
font: var(--fds-typography-paragraph-short-large);
min-height: var(--fds-sizing-12);
font: var(--fds-typography-paragraph-short-medium);
}

.root.selected .headingButton {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const HeadingRow = ({ schemaPointer }: HeadingRowProps) => {
<StudioButton
className={classes.headingButton}
color='second'
size='small'
icon={<NodeIcon node={node} />}
onClick={selectNodeRoot}
variant='tertiary'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { useUserQuery } from 'app-development/hooks/queries';
import { useStudioEnvironmentParams } from 'app-shared/hooks/useStudioEnvironmentParams';

export const SchemaEditor = () => {
const { schemaModel, selectedTypePointer, selectedUniquePointer } = useSchemaEditorAppContext();
const { schemaModel, selectedTypePointer } = useSchemaEditorAppContext();
const { org } = useStudioEnvironmentParams();
const { data: user } = useUserQuery();
const moveProperty = useMoveProperty();
Expand Down Expand Up @@ -45,11 +45,7 @@ export const SchemaEditor = () => {
<NodePanel schemaPointer={selectedType?.schemaPointer} />
</div>
</StudioResizableLayout.Element>
<StudioResizableLayout.Element
minimumSize={300}
collapsed={!selectedUniquePointer}
collapsedSize={180}
>
<StudioResizableLayout.Element minimumSize={300} collapsedSize={180}>
<aside className={classes.inspector}>
<SchemaInspector />
</aside>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ChangeEvent } from 'react';
import React, { useState } from 'react';
import { ReferenceSelectionComponent } from './ReferenceSelectionComponent';
import { getCombinationOptions } from './helpers/options';
import { Fieldset, Textfield, Switch } from '@digdir/designsystemet-react';
import { Fieldset, Switch } from '@digdir/designsystemet-react';
import classes from './ItemDataComponent.module.css';
import { ItemRestrictions } from './ItemRestrictions';
import type { CombinationKind, UiSchemaNode } from '@altinn/schema-model';
Expand Down Expand Up @@ -30,7 +30,7 @@ import { useTranslation } from 'react-i18next';
import { CustomProperties } from '@altinn/schema-editor/components/SchemaInspector/CustomProperties';
import { NameField } from './NameField';
import { useSchemaEditorAppContext } from '@altinn/schema-editor/hooks/useSchemaEditorAppContext';
import { StudioNativeSelect, StudioTextarea } from '@studio/components';
import { StudioNativeSelect, StudioTextarea, StudioTextfield } from '@studio/components';

export type IItemDataComponentProps = {
schemaNode: UiSchemaNode;
Expand Down Expand Up @@ -178,12 +178,13 @@ export function ItemDataComponent({ schemaNode }: IItemDataComponentProps) {
{hasCustomProps && <CustomProperties path={schemaPointer} />}
<Fieldset legend={t('schema_editor.descriptive_fields')} className={classes.fieldSet}>
<div>
<Textfield
<StudioTextfield
id={titleId}
label={t('schema_editor.title')}
aria-label={t('schema_editor.title')}
onBlur={onChangeTitle}
onChange={(e: ChangeEvent) => setItemItemTitle((e.target as HTMLInputElement)?.value)}
size='small'
onChange={(e: ChangeEvent<HTMLInputElement>) => setItemItemTitle(e.target.value)}
value={itemTitle}
/>
</div>
Expand All @@ -196,7 +197,7 @@ export function ItemDataComponent({ schemaNode }: IItemDataComponentProps) {
onChange={(event: ChangeEvent<HTMLTextAreaElement>) =>
setItemItemDescription(event.target.value)
}
style={{ height: 100 }}
size='small'
value={itemDescription}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@
import React, { useEffect } from 'react';
import type { FieldType, FieldNode, ObjectKind } from '@altinn/schema-model';
import { isField, isReference } from '@altinn/schema-model';
import { isField, isObject, isReference } from '@altinn/schema-model';
import classes from './ItemFieldsTab.module.css';
import { usePrevious } from '@studio/components';
import { ItemFieldsTable } from './ItemFieldsTable';
import { useAddProperty } from '@altinn/schema-editor/hooks/useAddProperty';
import { getLastNameField } from '@altinn/schema-editor/components/SchemaInspector/ItemFieldsTab/domUtils';
import { AddPropertiesMenu } from '../../AddPropertiesMenu';
import { Alert } from '@digdir/designsystemet-react';
import type { UiSchemaNode } from '@altinn/schema-model/types';
import { useTranslation } from 'react-i18next';

export interface ItemFieldsTabProps {
selectedItem: FieldNode;
export type ItemFieldsTabProps = {
selectedItem: UiSchemaNode;
};

export function ItemFieldsTab({ selectedItem }: ItemFieldsTabProps): React.ReactElement {
const { t } = useTranslation();

const shouldDisplayFieldsTabContent = isField(selectedItem) && isObject(selectedItem);

return shouldDisplayFieldsTabContent ? (
<ItemFieldsTabContent selectedItem={selectedItem} />
) : (
<Alert size='small'>{t('schema_editor.fields_not_available_on_type')}</Alert>
);
}

export const ItemFieldsTab = ({ selectedItem }: ItemFieldsTabProps) => {
type ItemFieldsTabContentProps = {
selectedItem: FieldNode;
};

const ItemFieldsTabContent = ({ selectedItem }: ItemFieldsTabContentProps) => {
const addProperty = useAddProperty();

const numberOfChildNodes = selectedItem.children.length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ describe('SchemaInspector', () => {
expect(saveDataModel).not.toHaveBeenCalled();
});

it('Does not display the fields tab when the selected item is a combination', async () => {
it('Does not display the fields tab content when the selected item is a combination', async () => {
const itemPointer = '#/properties/testcombination';
const rootNode: FieldNode = {
...rootNodeMock,
Expand All @@ -171,7 +171,9 @@ describe('SchemaInspector', () => {
validateTestUiSchema(testUiSchema);
renderSchemaInspector(testUiSchema, item);
await user.click(getFieldsTab());
expect(screen.getByText(textMock('app_data_modelling.fields_information'))).toBeInTheDocument();
expect(
screen.getByText(textMock('schema_editor.fields_not_available_on_type')),
).toBeInTheDocument();
});

const getFieldsTab = () => screen.getByRole('tab', { name: textMock('schema_editor.fields') });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import { Alert, Tabs } from '@digdir/designsystemet-react';
import { Tabs } from '@digdir/designsystemet-react';
import type { UiSchemaNode } from '@altinn/schema-model';
import { isField, isObject } from '@altinn/schema-model';
import { ItemPropertiesTab } from './ItemPropertiesTab';
import { ItemFieldsTab } from './ItemFieldsTab';
import classes from './SchemaInspector.module.css';
Expand All @@ -20,24 +19,19 @@ export const SchemaInspector = () => {
}

const selectedItem: UiSchemaNode = savableModel.getNodeByUniquePointer(selectedUniquePointer);
const shouldDisplayFieldsTab = isField(selectedItem) && isObject(selectedItem);

return (
<Tabs defaultValue={t('schema_editor.properties')} className={classes.root}>
<Tabs defaultValue='Properties' className={classes.root}>
<Tabs.List>
<Tabs.Tab value={t('schema_editor.properties')}>{t('schema_editor.properties')}</Tabs.Tab>
<Tabs.Tab value={t('schema_editor.fields')}>{t('schema_editor.fields')}</Tabs.Tab>
<Tabs.Tab value='Properties'>{t('schema_editor.properties')}</Tabs.Tab>
<Tabs.Tab value='Fields'>{t('schema_editor.fields')}</Tabs.Tab>
</Tabs.List>
<Tabs.Content value={t('schema_editor.properties')}>
<Tabs.Content value='Properties'>
<ItemPropertiesTab selectedItem={selectedItem} />
</Tabs.Content>
{shouldDisplayFieldsTab ? (
<Tabs.Content value={t('schema_editor.fields')}>
<ItemFieldsTab selectedItem={selectedItem} />
</Tabs.Content>
) : (
<Alert severity='info'>{t('app_data_modelling.fields_information')}</Alert>
)}
<Tabs.Content value='Fields'>
<ItemFieldsTab selectedItem={selectedItem} />
</Tabs.Content>
</Tabs>
);
};

0 comments on commit 06e6e85

Please sign in to comment.