Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions TESTING_COVERAGE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Row dialog fields (#1796, 2026-09-25): `browser/data-browser/src/components/PropVal.test.tsx` checks that the row dialog labels a value with its property's name (or a readable shortname when it has none), with the shortname in the tooltip. The label must not be a link, the property opens in a new tab, and the edited checkbox gets its accessible name from the label. Resource pages keep the linked shortname. `browser/e2e/tests/row-dialog.spec.ts` covers the same in a real Grocery list and runs axe (`label`, `link-name`) on the open dialog. It also covers the `ValueFormEdit` key warning through the browser-diagnostics fixture: that warning only shows with the wuchale transform, which vitest does not run.

Server descriptor budget (2026-09-22): `server/src/serve.rs` tests the HTTP
connection budget at small, staging-sized, and effectively unlimited process
descriptor limits. Startup reads the process soft `RLIMIT_NOFILE`, limits Actix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export function ExpandedRowDialog({
<AllProps
editable
columns
labelByName
resource={resource}
except={EXCLUDED_PROPS}
/>
Expand Down
12 changes: 11 additions & 1 deletion browser/data-browser/src/components/AllProps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,19 @@ type Props = {
*/
columns?: boolean;
basic?: boolean;
/** Label each value with its property's name, not its shortname. See PropVal. */
labelByName?: boolean;
};

/** Lists all PropVals for some resource. Optionally ignores a bunch of subjects */
function AllProps({ resource, except = [], editable, columns, basic }: Props) {
function AllProps({
resource,
except = [],
editable,
columns,
basic,
labelByName,
}: Props) {
const props = useSortedProps(resource, except, !!editable);

if (!props || props.length === 0) {
Expand All @@ -40,6 +49,7 @@ function AllProps({ resource, except = [], editable, columns, basic }: Props) {
propertyURL={prop}
resource={resource}
editable={!!editable}
labelByName={labelByName}
/>
),
)}
Expand Down
115 changes: 115 additions & 0 deletions browser/data-browser/src/components/PropVal.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// @vitest-environment jsdom
// @wc-ignore-file
import React from 'react';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { cleanup, fireEvent, render, screen } from '@testing-library/react';
import { ThemeProvider } from 'styled-components';
import { core, Datatype, Resource, Store } from '@tomic/lib';
import { StoreContext } from '@tomic/react';
import { buildTheme } from '../styling';
// PropVal → ValueComp → NestedResource → AllProps → PropVal is a cycle. Enter it
// at AllProps, as the app does, or AllProps styles a PropVal not yet defined.
import './AllProps';
import PropVal from './PropVal';

// Editing needs an agent with write access; neither is what is under test.
vi.mock('../helpers/AppSettings', () => ({
useSettings: () => ({ agent: { subject: 'atomic:agent:test' } }),
}));
vi.mock('@tomic/react', async importOriginal => ({
...(await importOriginal<typeof import('@tomic/react')>()),
useCanWrite: () => true,
}));

const BOUGHT = 'https://example.com/properties/bought';
const DUE = 'https://example.com/properties/due-date';
const ROW = 'https://example.com/rows/milk';

async function property(
subject: string,
shortname: string,
datatype: Datatype,
name?: string,
) {
const resource = new Resource(subject);
await resource.set(core.properties.shortname, shortname, false);
await resource.set(core.properties.datatype, datatype, false);
await resource.set(core.properties.description, `About ${shortname}`, false);

if (name) await resource.set(core.properties.name, name, false);

resource.loading = false;

return resource;
}

async function setup(labelByName: boolean, propertyURL = BOUGHT) {
const store = new Store();
store.addResource(
await property(BOUGHT, 'bought', Datatype.BOOLEAN, 'Bought'),
);
store.addResource(await property(DUE, 'due-date', Datatype.DATE));
const row = new Resource(ROW);
row.loading = false;
store.addResource(row);

return render(
<StoreContext.Provider value={store}>
<ThemeProvider theme={buildTheme(false, '#1b50d8')}>
<PropVal
editable
labelByName={labelByName}
propertyURL={propertyURL}
resource={store.getResourceLoading(ROW)}
/>
</ThemeProvider>
</StoreContext.Provider>,
);
}

afterEach(cleanup);

describe('a value in the row dialog', () => {
it("is labelled with the property's name, with the shortname as tooltip", async () => {
await setup(true);

const label = screen.getByText('Bought');
expect(label.tagName).toBe('LABEL');
expect(label.getAttribute('title')).toBe('bought: About bought');
expect(screen.queryByText('bought')).toBeNull();
});

it('falls back to a readable shortname when the property has no name', async () => {
await setup(true, DUE);

expect(screen.getByText('Due date').tagName).toBe('LABEL');
});

it('does not navigate away: the label is no link, the property opens in a new tab', async () => {
await setup(true);

expect(screen.getByText('Bought').closest('a')).toBeNull();
const open = screen.getByRole('link', { name: 'Open Bought in a new tab' });
expect(open.getAttribute('target')).toBe('_blank');
expect(open.getAttribute('href')).toContain(encodeURIComponent(BOUGHT));
});

it('names the checkbox after its label once it is being edited', async () => {
await setup(true);

fireEvent.click(screen.getByTitle('Click to add a value'));

// The accessible name, computed the way assistive technology does.
const checkbox = screen.getByRole('checkbox', { name: 'Bought' });
expect(checkbox).toBeTruthy();
});
});

describe('a value on a resource page', () => {
it('keeps the shortname, linked to the property', async () => {
await setup(false);

const label = screen.getByText('bought');
expect(label.closest('a')?.getAttribute('href')).toBe(BOUGHT);
});
});
86 changes: 79 additions & 7 deletions browser/data-browser/src/components/PropVal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { useProperty, truncateUrl, Resource } from '@tomic/react';
import {
core,
useProperty,
useResource,
useString,
truncateUrl,
Resource,
} from '@tomic/react';
import { useId } from 'react';
import { FaArrowUpRightFromSquare } from 'react-icons/fa6';

import { styled } from 'styled-components';
import { AtomicLink } from './AtomicLink';
import { columnLabel } from '@chunks/TablePage/helpers/columnLabel';
import { constructOpenURL } from '@helpers/navigation';
import { ErrorLook } from './ErrorLook';
import { ValueForm } from './forms/ValueForm';
import ValueComp from './ValueComp';
Expand All @@ -18,6 +29,14 @@ type Props = {
// If set to true, will render the properties in a left column, and the Values in the right one, but only on large screens.
columns?: boolean;
className?: string;
/**
* Label the value with the property's name ("Due date") instead of its
* shortname (`due-date`), as a form label rather than a link. For places
* where leaving the page is not what a click on a label should do, like the
* row dialog over a table. The property opens in a new tab from a separate
* icon, and the shortname is in the label's tooltip.
*/
labelByName?: boolean;
};

/**
Expand All @@ -30,9 +49,14 @@ function PropVal({
editable,
columns,
className,
labelByName,
}: Props): JSX.Element {
const property = useProperty(propertyURL);
const propertyResource = useResource(propertyURL);
// The property's own name, not its title: see `columnLabel`.
const [name] = useString(propertyResource, core.properties.name);
const truncated = truncateUrl(propertyURL, 10, true);
const inputId = useId();

if (property.loading || resource.loading) {
return (
Expand All @@ -55,15 +79,45 @@ function PropVal({
);
}

const shortname = property.shortname || truncated;
const label = labelByName ? columnLabel(name, shortname) : shortname;

return (
<PropValRow columns={columns} className={className}>
<AtomicLink subject={propertyURL}>
<PropertyLabel title={property.description}>
{property.shortname || truncated}
</PropertyLabel>
</AtomicLink>
{labelByName ? (
<LabelRow>
<PropertyLabel
as='label'
htmlFor={inputId}
title={
property.description
? `${shortname}: ${property.description}`
: shortname
}
>
{label}
</PropertyLabel>
<OpenPropertyLink
href={constructOpenURL(propertyURL)}
target='_blank'
rel='noopener noreferrer'
aria-label={`Open ${label} in a new tab`}
title={`Open ${label} in a new tab`}
>
<FaArrowUpRightFromSquare aria-hidden />
</OpenPropertyLink>
</LabelRow>
) : (
<AtomicLink subject={propertyURL}>
<PropertyLabel title={property.description}>{label}</PropertyLabel>
</AtomicLink>
)}
{editable ? (
<ValueForm resource={resource} propertyURL={propertyURL} />
<ValueForm
resource={resource}
propertyURL={propertyURL}
inputId={inputId}
/>
) : (
<ValueComp
datatype={property.datatype}
Expand Down Expand Up @@ -97,6 +151,24 @@ export const PropertyLabel = styled.span`
font-weight: bold;
`;

const LabelRow = styled.span`
display: flex;
align-items: baseline;
gap: 0.4rem;
color: ${p => p.theme.colors.main};
`;

const OpenPropertyLink = styled.a`
color: ${p => p.theme.colors.textLight};
font-size: 0.75em;
line-height: 1;

&:hover,
&:focus-visible {
color: ${p => p.theme.colors.main};
}
`;

const StyledLoader = styled(LoaderInline)`
grid-column: 1 / 3;
margin-inline: 1rem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ interface ValueFormProps {
/** Whether the form should start in edit mode when mounted. */
defaultEditState?: boolean;
onStateChange?: (editMode: boolean) => void;
/** The id the input gets while editing, for a `<label htmlFor>` outside. */
inputId?: string;
}

/**
Expand All @@ -42,6 +44,7 @@ export function ValueForm({
datatype,
defaultEditState = false,
onStateChange,
inputId,
}: ValueFormProps) {
const { changes, oldResources } = useAIChanges();
const hasAiChanges = changes.includes(resource.subject);
Expand Down Expand Up @@ -125,6 +128,7 @@ export function ValueForm({
<ValueFormEdit
resource={resource}
property={property}
inputId={inputId}
onClose={() => handleEditModeChange(false)}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ interface ValueFormEditProps {
resource: Resource;
property: Property;
onClose: () => void;
/** Lets a label outside the form name the input. */
inputId?: string;
}

export function ValueFormEdit({
resource,
property,
onClose,
inputId,
}: ValueFormEditProps): React.JSX.Element {
const [err, setErr] = useState<Error | undefined>(undefined);
const [isFormValid, setIsFormValid] = useState(false);
Expand Down Expand Up @@ -49,6 +52,7 @@ export function ValueFormEdit({
<FormValidationContextProvider onValidationChange={setIsFormValid}>
<Column gap='0.5rem'>
<InputSwitcher
id={inputId}
data-test={`input-${property.subject}`}
resource={resource}
property={property}
Expand All @@ -61,7 +65,7 @@ export function ValueFormEdit({
</Button>
<Button onClick={save} disabled={!isFormValid}>
<FaFloppyDisk />
Save
<span>Save</span>
</Button>
</Row>
</Column>
Expand Down
13 changes: 10 additions & 3 deletions browser/data-browser/src/locales/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -1341,9 +1341,8 @@ msgstr ""
msgid "Plugin Description"
msgstr ""

#: src/components/forms/ValueForm/ValueFormEdit.tsx
msgid "<0/> Save"
msgstr ""
#~ msgid "<0/> Save"
#~ msgstr ""

#: src/views/Installation/InstallationPage.tsx
#: src/views/Installation/InstallationPage.tsx
Expand Down Expand Up @@ -1445,6 +1444,7 @@ msgstr ""
#: src/components/Settings/IntegrationSettings.tsx
#: src/components/Settings/IntegrationSettings.tsx
#: src/components/forms/ResourceForm.tsx
#: src/components/forms/ValueForm/ValueFormEdit.tsx
#: src/views/Article/ArticleDescription.tsx
#: src/views/Installation/InstallationPage.tsx
#: src/views/OntologyPage/NewClassButton.tsx
Expand Down Expand Up @@ -12272,3 +12272,10 @@ msgstr ""
#: src/chunks/TablePage/Issues/IssuesView.tsx
msgid "Nothing closed."
msgstr ""

#. 0: label
#. 0: label
#: src/components/PropVal.tsx
#: src/components/PropVal.tsx
msgid "Open {0} in a new tab"
msgstr ""
Loading