Skip to content

Commit 03acd17

Browse files
Pollepsjoepio
authored andcommitted
#762 Allign rows in data and default view
1 parent d550e66 commit 03acd17

File tree

5 files changed

+74
-66
lines changed

5 files changed

+74
-66
lines changed

browser/data-browser/src/components/AllProps.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Resource } from '@tomic/react';
22

33
import { styled, css } from 'styled-components';
44
import PropVal from './PropVal';
5+
import { ALL_PROPS_CONTAINER } from '../helpers/containers';
56

67
type Props = {
78
resource: Resource;
@@ -46,6 +47,8 @@ function AllProps({ resource, except = [], editable, columns, basic }: Props) {
4647
}
4748

4849
const AllPropsWrapper = styled.div<{ basic: boolean | undefined }>`
50+
container: ${ALL_PROPS_CONTAINER} / inline-size;
51+
4952
display: flex;
5053
flex-direction: column;
5154
border-radius: ${p => p.theme.radius};

browser/data-browser/src/components/Main.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { styled } from 'styled-components';
44
import { transitionName } from '../helpers/transitionName';
55
import { ViewTransitionProps } from '../helpers/ViewTransitionProps';
66
import { PARENT_PADDING_BLOCK } from './Parent';
7+
import { MAIN_CONTAINER } from '../helpers/containers';
78

89
/** Main landmark. Every page should have one of these.
910
* If the pages shows a resource a subject can be passed that enables view transitions to work. */
@@ -24,7 +25,7 @@ export function Main({
2425
}
2526

2627
const StyledMain = memo(styled.main<ViewTransitionProps>`
27-
container-type: inline-size;
28+
container: ${MAIN_CONTAINER} / inline-size;
2829
/* Makes the contents fit the entire page */
2930
/* height: calc(
3031
100% - (${p => p.theme.heights.breadCrumbBar} + ${PARENT_PADDING_BLOCK} * 2)

browser/data-browser/src/components/PropVal.tsx

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { AtomicLink } from './AtomicLink';
55
import { ErrorLook } from './ErrorLook';
66
import { ValueForm } from './forms/ValueForm';
77
import ValueComp from './ValueComp';
8+
import { ALL_PROPS_CONTAINER } from '../helpers/containers';
89

910
type Props = {
1011
propertyURL: string;
@@ -15,25 +16,6 @@ type Props = {
1516
className?: string;
1617
};
1718

18-
interface PropValRowProps {
19-
columns?: boolean;
20-
}
21-
22-
export const PropValRow = styled.div<PropValRowProps>`
23-
word-break: break-word;
24-
25-
@media screen and (min-width: 500px) {
26-
flex-direction: ${p => (p.columns ? 'row' : 'column')};
27-
display: ${p => (p.columns ? 'flex' : 'block')};
28-
}
29-
`;
30-
31-
export const PropertyLabel = styled.span`
32-
font-weight: bold;
33-
display: block;
34-
min-width: 8rem;
35-
`;
36-
3719
/**
3820
* A single Property / Value renderer that shows a label on the left, and the
3921
* value on the right. The value is editable.
@@ -75,12 +57,7 @@ function PropVal({
7557
<PropValRow columns={columns} className={className}>
7658
<AtomicLink subject={propertyURL}>
7759
<PropertyLabel title={property.description}>
78-
{property.error ? (
79-
<ErrorLook>{truncated}</ErrorLook>
80-
) : (
81-
property.shortname || truncated
82-
)}
83-
:
60+
{property.shortname || truncated}
8461
</PropertyLabel>
8562
</AtomicLink>
8663
{editable ? (
@@ -96,3 +73,23 @@ function PropVal({
9673
}
9774

9875
export default PropVal;
76+
77+
export const PropValRow = styled.div<PropValRowProps>`
78+
word-break: break-word;
79+
display: grid;
80+
grid-template-columns: 1fr;
81+
grid-template-rows: auto 1fr;
82+
83+
@container ${ALL_PROPS_CONTAINER} (min-width: 500px) {
84+
grid-template-columns: 23ch auto;
85+
grid-template-rows: 1fr;
86+
}
87+
`;
88+
89+
export const PropertyLabel = styled.span`
90+
font-weight: bold;
91+
`;
92+
93+
interface PropValRowProps {
94+
columns?: boolean;
95+
}

browser/data-browser/src/components/forms/ValueForm.tsx

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { ErrMessage } from './InputStyles';
1515
import InputSwitcher from './InputSwitcher';
1616
import { useSettings } from '../../helpers/AppSettings';
1717
import toast from 'react-hot-toast';
18+
import { Column, Row } from '../Row';
1819

1920
interface ValueFormProps {
2021
// Maybe pass Value instead of Resource?
@@ -55,6 +56,25 @@ export function ValueForm({
5556
const [err, setErr] = useState<Error | undefined>(undefined);
5657
const haveAgent = agent !== undefined;
5758

59+
function handleCancel() {
60+
setErr(undefined);
61+
setEditMode(false);
62+
// Should this maybe also remove the edits to the resource?
63+
// https://github.com/atomicdata-dev/atomic-data-browser/issues/36
64+
}
65+
66+
async function handleSave() {
67+
try {
68+
await resource.save(store);
69+
setEditMode(false);
70+
toast.success('Resource saved');
71+
} catch (e) {
72+
setErr(e);
73+
setEditMode(true);
74+
toast.error('Could not save resource...');
75+
}
76+
}
77+
5878
if (value === undefined) {
5979
return null;
6080
}
@@ -78,48 +98,33 @@ export function ValueForm({
7898
);
7999
}
80100

81-
function handleCancel() {
82-
setErr(undefined);
83-
setEditMode(false);
84-
// Should this maybe also remove the edits to the resource?
85-
// https://github.com/atomicdata-dev/atomic-data-browser/issues/36
86-
}
87-
88-
async function handleSave() {
89-
try {
90-
await resource.save(store);
91-
setEditMode(false);
92-
toast.success('Resource saved');
93-
} catch (e) {
94-
setErr(e);
95-
setEditMode(true);
96-
toast.error('Could not save resource...');
97-
}
98-
}
99-
100101
return (
101102
<ValueFormWrapper>
102-
<InputSwitcher
103-
data-test={`input-${property.subject}`}
104-
resource={resource}
105-
property={property}
106-
autoFocus
107-
/>
108-
{err && <ErrMessage>{err.message}</ErrMessage>}
109-
<Button
110-
disabled={!haveAgent}
111-
title={
112-
haveAgent
113-
? 'Save the edits'
114-
: 'You cannot save - there is no Agent set. Go to settings.'
115-
}
116-
onClick={handleSave}
117-
>
118-
save
119-
</Button>
120-
<Button subtle onClick={handleCancel}>
121-
cancel
122-
</Button>
103+
<Column gap='0.5rem'>
104+
<InputSwitcher
105+
data-test={`input-${property.subject}`}
106+
resource={resource}
107+
property={property}
108+
autoFocus
109+
/>
110+
{err && <ErrMessage>{err.message}</ErrMessage>}
111+
<Row gap='0.5rem'>
112+
<Button subtle onClick={handleCancel}>
113+
cancel
114+
</Button>
115+
<Button
116+
disabled={!haveAgent}
117+
title={
118+
haveAgent
119+
? 'Save the edits'
120+
: 'You cannot save - there is no Agent set. Go to settings.'
121+
}
122+
onClick={handleSave}
123+
>
124+
save
125+
</Button>
126+
</Row>
127+
</Column>
123128
</ValueFormWrapper>
124129
);
125130
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const MAIN_CONTAINER = 'main';
2+
export const ALL_PROPS_CONTAINER = 'all-props';

0 commit comments

Comments
 (0)