@startsimpli/ui 0.4.158 → 0.4.159
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/components/collection/InlineReviewActions.tsx +23 -1
- package/src/components/collection/__tests__/inline-review-reader.test.tsx +77 -0
- package/src/components/unified-table/__tests__/components/TableFilters.option-labels.test.tsx +52 -0
- package/src/components/unified-table/components/TableFilters/index.tsx +2 -2
- package/src/components/unified-table/types.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startsimpli/ui",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.159",
|
|
4
4
|
"description": "Shared UI components package for StartSimpli applications",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"@codemirror/language": "^6.0.0",
|
|
56
56
|
"@codemirror/state": "^6.0.0",
|
|
57
57
|
"@codemirror/view": "^6.0.0",
|
|
58
|
-
"@startsimpli/i18n": "^0.1.3",
|
|
59
58
|
"@startsimpli/api": "^0.5.68",
|
|
59
|
+
"@startsimpli/i18n": "^0.1.3",
|
|
60
60
|
"@startsimpli/auth": "^0.4.42"
|
|
61
61
|
},
|
|
62
62
|
"peerDependenciesMeta": {
|
|
@@ -64,9 +64,23 @@ export interface InlineReviewActionsProps {
|
|
|
64
64
|
config?: ReviewConfig;
|
|
65
65
|
/** Fired after a successful save so the parent can refetch/invalidate. */
|
|
66
66
|
onSaved?: () => void;
|
|
67
|
+
/**
|
|
68
|
+
* Whether this reader may change THIS record (bd startsim-m7fdm.32). False
|
|
69
|
+
* draws the record's state as a plain pill and no decisions, the same pill
|
|
70
|
+
* ReviewDrawer shows in place of its State select, so a view-only reader is
|
|
71
|
+
* not offered buttons that can only end in "Could not save.". Defaults to true.
|
|
72
|
+
*/
|
|
73
|
+
canEdit?: boolean;
|
|
67
74
|
}
|
|
68
75
|
|
|
69
|
-
export function InlineReviewActions({
|
|
76
|
+
export function InlineReviewActions({
|
|
77
|
+
client,
|
|
78
|
+
type,
|
|
79
|
+
record,
|
|
80
|
+
config,
|
|
81
|
+
onSaved,
|
|
82
|
+
canEdit = true,
|
|
83
|
+
}: InlineReviewActionsProps) {
|
|
70
84
|
const cfg = useMemo(() => resolveReviewConfig(type, config), [type, config]);
|
|
71
85
|
/** The type's declared attribute names — the spellings a write must send back. */
|
|
72
86
|
const declaredNames = useMemo(() => (type.attributes ?? []).map((a) => a.name), [type]);
|
|
@@ -152,6 +166,14 @@ export function InlineReviewActions({ client, type, record, config, onSaved }: I
|
|
|
152
166
|
}
|
|
153
167
|
|
|
154
168
|
if (decisions.length === 0) return null;
|
|
169
|
+
if (!canEdit) {
|
|
170
|
+
const status = fieldStr(record.data, cfg.statusName);
|
|
171
|
+
return status ? (
|
|
172
|
+
<span className="whitespace-nowrap rounded-full bg-muted px-2 py-0.5 text-xs capitalize text-muted-foreground">
|
|
173
|
+
{status.replace(/_/g, ' ')}
|
|
174
|
+
</span>
|
|
175
|
+
) : null;
|
|
176
|
+
}
|
|
155
177
|
return (
|
|
156
178
|
<div className="flex items-center justify-end gap-1" onClick={(e) => e.stopPropagation()}>
|
|
157
179
|
{decisions.map((d) =>
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The table-row and board-card decision cluster follows the record's
|
|
3
|
+
* permissions, like the drawer (bd startsim-m7fdm.32; drawer half startsim-j9agp).
|
|
4
|
+
*
|
|
5
|
+
* Before this, InlineReviewActions drew Reject / Approve / Needs work for every
|
|
6
|
+
* reader, and a view-only reader learned from "Could not save." that they could
|
|
7
|
+
* not decide. With `canEdit={false}` it draws the record's state instead, the
|
|
8
|
+
* same pill the drawer shows in place of its State select.
|
|
9
|
+
*/
|
|
10
|
+
import * as React from 'react';
|
|
11
|
+
import { render, screen } from '@testing-library/react';
|
|
12
|
+
|
|
13
|
+
import { InlineReviewActions } from '../InlineReviewActions';
|
|
14
|
+
import type { CollectionClient, EntityRecord, EntityTypeDef, Paginated } from '../types';
|
|
15
|
+
|
|
16
|
+
const TOPIC_TYPE: EntityTypeDef = {
|
|
17
|
+
id: 1,
|
|
18
|
+
key: 'topic',
|
|
19
|
+
label: 'Topic',
|
|
20
|
+
attributes: [
|
|
21
|
+
{
|
|
22
|
+
id: 'status',
|
|
23
|
+
name: 'status',
|
|
24
|
+
dataType: 'enum',
|
|
25
|
+
required: false,
|
|
26
|
+
config: { choices: ['suggested', 'ready', 'written', 'rejected'] },
|
|
27
|
+
},
|
|
28
|
+
{ id: 'title', name: 'title', dataType: 'text', required: false, config: {} },
|
|
29
|
+
{ id: 'team_verdict', name: 'team_verdict', dataType: 'text', required: false, config: {} },
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function topic(status: string): EntityRecord {
|
|
34
|
+
return {
|
|
35
|
+
id: 1,
|
|
36
|
+
entityType: 'topic',
|
|
37
|
+
externalId: null,
|
|
38
|
+
name: 'Oman customs',
|
|
39
|
+
data: { title: 'Oman customs', status },
|
|
40
|
+
createdAt: '2026-09-01T00:00:00Z',
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function page<T>(results: T[]): Paginated<T> {
|
|
45
|
+
return { count: results.length, next: null, previous: null, results };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function stubClient(): CollectionClient {
|
|
49
|
+
return {
|
|
50
|
+
listTypes: jest.fn(async () => page([TOPIC_TYPE])),
|
|
51
|
+
listAllEntities: jest.fn(async () => []),
|
|
52
|
+
updateEntity: jest.fn(async () => topic('ready')),
|
|
53
|
+
} as unknown as CollectionClient;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
describe('InlineReviewActions for a view-only reader', () => {
|
|
57
|
+
it('draws the state and no decision buttons', () => {
|
|
58
|
+
render(
|
|
59
|
+
<InlineReviewActions client={stubClient()} type={TOPIC_TYPE} record={topic('ready_for_review')} canEdit={false} />,
|
|
60
|
+
);
|
|
61
|
+
expect(screen.queryByRole('button')).toBeNull();
|
|
62
|
+
expect(screen.getByText('ready for review')).toBeInTheDocument();
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('draws nothing when the record has no state', () => {
|
|
66
|
+
const record = { ...topic('x'), data: { title: 'Oman customs' } };
|
|
67
|
+
const { container } = render(
|
|
68
|
+
<InlineReviewActions client={stubClient()} type={TOPIC_TYPE} record={record} canEdit={false} />,
|
|
69
|
+
);
|
|
70
|
+
expect(container).toBeEmptyDOMElement();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('keeps all three decisions for an editor (the default)', () => {
|
|
74
|
+
render(<InlineReviewActions client={stubClient()} type={TOPIC_TYPE} record={topic('suggested')} />);
|
|
75
|
+
expect(screen.getAllByRole('button')).toHaveLength(3);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A chip filter can show a label while it filters on a key (review bead
|
|
3
|
+
* startsim-y78xg). The marketing-agents Kind chips read "weekly_brief" and
|
|
4
|
+
* "lead_magnet" beside a sidebar saying "Weekly Briefs" and "Evergreen"; the
|
|
5
|
+
* key has to stay the value because it is what travels in the URL.
|
|
6
|
+
*/
|
|
7
|
+
import * as React from 'react'
|
|
8
|
+
import { fireEvent, render, screen } from '@testing-library/react'
|
|
9
|
+
|
|
10
|
+
import { TableFilters } from '../../components/TableFilters'
|
|
11
|
+
import type { FilterConfig, UseFiltersReturn } from '../../types'
|
|
12
|
+
|
|
13
|
+
const config: FilterConfig = {
|
|
14
|
+
sections: [
|
|
15
|
+
{
|
|
16
|
+
id: 'kind',
|
|
17
|
+
type: 'chips',
|
|
18
|
+
filters: [
|
|
19
|
+
{
|
|
20
|
+
id: 'content_type',
|
|
21
|
+
label: 'Kind',
|
|
22
|
+
options: ['weekly_brief', 'lead_magnet', 'general'],
|
|
23
|
+
optionLabels: { weekly_brief: 'Weekly Briefs', lead_magnet: 'Evergreen' },
|
|
24
|
+
},
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function filtersStub(value: Record<string, string> = {}): UseFiltersReturn {
|
|
31
|
+
return {
|
|
32
|
+
filters: value,
|
|
33
|
+
setFilter: jest.fn(),
|
|
34
|
+
clearFilter: jest.fn(),
|
|
35
|
+
clearAllFilters: jest.fn(),
|
|
36
|
+
hasActiveFilters: () => Object.keys(value).length > 0,
|
|
37
|
+
getActiveFilterCount: () => Object.keys(value).length,
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
describe('TableFilters chip labels', () => {
|
|
42
|
+
it('shows the label and filters on the key', () => {
|
|
43
|
+
const filters = filtersStub()
|
|
44
|
+
render(<TableFilters config={config} filters={filters} defaultExpanded />)
|
|
45
|
+
|
|
46
|
+
expect(screen.queryByRole('button', { name: 'weekly_brief' })).toBeNull()
|
|
47
|
+
fireEvent.click(screen.getByRole('button', { name: 'Evergreen' }))
|
|
48
|
+
expect(filters.setFilter).toHaveBeenCalledWith('content_type', 'lead_magnet')
|
|
49
|
+
// An option with no label still reads as itself.
|
|
50
|
+
expect(screen.getByRole('button', { name: 'general' })).toBeInTheDocument()
|
|
51
|
+
})
|
|
52
|
+
})
|
|
@@ -64,7 +64,7 @@ export function TableFilters({ config, filters, className, defaultExpanded = fal
|
|
|
64
64
|
}}
|
|
65
65
|
className="h-7 px-2 text-xs"
|
|
66
66
|
>
|
|
67
|
-
{option}
|
|
67
|
+
{filter.optionLabels?.[option] ?? option}
|
|
68
68
|
</Button>
|
|
69
69
|
)
|
|
70
70
|
})}
|
|
@@ -122,7 +122,7 @@ export function TableFilters({ config, filters, className, defaultExpanded = fal
|
|
|
122
122
|
<SelectItem value="all">All</SelectItem>
|
|
123
123
|
{filteredOptions.map((option: string) => (
|
|
124
124
|
<SelectItem key={option} value={option}>
|
|
125
|
-
{option === 'null' ? 'Not Set' : option}
|
|
125
|
+
{option === 'null' ? 'Not Set' : (filter.optionLabels?.[option] ?? option)}
|
|
126
126
|
</SelectItem>
|
|
127
127
|
))}
|
|
128
128
|
</SelectContent>
|
|
@@ -164,6 +164,9 @@ export interface FilterItem {
|
|
|
164
164
|
label: string
|
|
165
165
|
type?: 'chips' | 'dropdown' | 'search' | 'checkbox'
|
|
166
166
|
options?: string[]
|
|
167
|
+
/** What each option reads as on screen, keyed by option. The option itself
|
|
168
|
+
* stays the value the filter holds, so a URL or API key is never a label. */
|
|
169
|
+
optionLabels?: Record<string, string>
|
|
167
170
|
multiple?: boolean
|
|
168
171
|
}
|
|
169
172
|
|