Skip to content

Commit 44b3254

Browse files
authored
Merge pull request #11 from MuckRock/v0.7.0
v0.7.0
2 parents 4e6159b + c894f0d commit 44b3254

File tree

18 files changed

+371
-84
lines changed

18 files changed

+371
-84
lines changed

.github/workflows/unit_tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
env:
3434
MYSQL_DATABASE: wordpress_test
3535
MYSQL_ROOT_PASSWORD: root
36-
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
36+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
3737

3838
steps:
3939
- uses: actions/checkout@v4
@@ -65,7 +65,7 @@ jobs:
6565
6666
- name: Install WP test suite
6767
run: |
68-
mysql -u root -proot -h mysql -P 3306 -e "DROP DATABASE IF EXISTS wordpress_test;"
68+
mysql --skip-ssl -u root -proot -h mysql -P 3306 -e "DROP DATABASE IF EXISTS wordpress_test;"
6969
bash ./bin/install-wp-tests.sh wordpress_test root 'root' mysql ${{ matrix.wp-version }}
7070
7171
- name: Run PHPUnit with coverage

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.svn
22
.DS_Store
3+
node_modules
34

45
# WordPress Dev Environment
56
src/wordpress
@@ -9,4 +10,7 @@ dist
910
**/vendor
1011

1112
# Testing
12-
.phpunit.cache
13+
.phpunit.cache
14+
15+
# Claude Code
16+
CLAUDE.md

README.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ To embed a note, use any note-specific URL. Notes ignore `width/height` and alwa
4545

4646
[documentcloud url="https://www.documentcloud.org/documents/282753-lefler-thesis.html#document/p1/a53674"]
4747

48+
To control which view is displayed by default, use the `mode` parameter:
49+
50+
[documentcloud url="https://www.documentcloud.org/documents/282753-lefler-thesis.html" mode="notes"]
51+
[documentcloud url="https://www.documentcloud.org/documents/282753-lefler-thesis.html" mode="text"]
52+
[documentcloud url="https://www.documentcloud.org/documents/282753-lefler-thesis.html" mode="grid"]
53+
4854
Here's the full list of embed options you can pass via shortcode attributes; some are specific to the type of resource you're embedding.
4955

5056

@@ -55,10 +61,8 @@ Here's the full list of embed options you can pass via shortcode attributes; som
5561

5662
### Documents only:
5763

58-
- `height` (integer): Height (in pixels) of the embed.
59-
- `width` (integer): Width (in pixels) of the embed. If used, will implicitly set `responsive="false"`.
60-
- `responsive` (boolean): Use responsive layout, which dynamically adjusts width to fill content area. Defaults `true`.
61-
- `responsive_offset` (integer): Distance (in pixels) to vertically offset the viewer for some responsive embeds.
64+
- `height` (integer): Maximum height (in pixels) of the embed.
65+
- `width` (integer): Maximum width (in pixels) of the embed.
6266
- `page` (integer): Page number to have the document scroll to by default.
6367
- `note` (integer): ID of the note that the document should highlight by default.
6468
- `notes` (boolean): Hide or show notes.
@@ -67,6 +71,7 @@ Here's the full list of embed options you can pass via shortcode attributes; som
6771
- `pdf` (boolean): Hide or show link to download original PDF.
6872
- `text` (boolean): Hide or show text tab.
6973
- `zoom` (boolean): Hide or show zoom slider.
74+
- `mode` (string): Display mode for the document viewer. Valid values: `document`, `notes`, `text`, `grid`. Controls which view is shown by default.
7075
- `format` (string): Indicate to the theme that this is a wide asset by setting this to `wide`. Defaults `normal`.
7176

7277
Or as a Gutenberg Block :
@@ -153,7 +158,7 @@ docker compose exec -it testing bash
153158
cd src/documentcloud/blocks
154159

155160
# 3. Install Node modules
156-
npm i
161+
npm i --force
157162

158163
# 4. Now the container is ready to run Jest tests
159164
npm test
@@ -171,6 +176,12 @@ To create a new release:
171176

172177
## Changelog
173178

179+
### 0.7.0
180+
* Removes the `responsive` and `responsive_offset` options.
181+
All embeds are rendered responsively, so this option is now deprecated.
182+
The `height` and `width` of the embed can still be limited with their respective options, but the embeds will respond to the size of their container.
183+
* Add `mode` parameter to control document viewer display mode. Valid values: `document`, `notes`, `text`, `grid`.
184+
174185
### 0.6.0
175186
* Add Gutenberg block for embedding DocumentCloud documents resonating a functionality similar to the shortcode.
176187
* Update the shortcode to support the following attributes

bin/install-wp-tests.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ recreate_db() {
130130
shopt -s nocasematch
131131
if [[ $1 =~ ^(y|yes)$ ]]
132132
then
133-
mysqladmin drop $DB_NAME -f --user="$DB_USER" --password="$DB_PASS"$EXTRA
133+
mysqladmin drop $DB_NAME -f --skip-ssl --user="$DB_USER" --password="$DB_PASS"$EXTRA
134134
create_db
135135
echo "Recreated the database ($DB_NAME)."
136136
else
@@ -140,7 +140,7 @@ recreate_db() {
140140
}
141141

142142
create_db() {
143-
mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA
143+
mysqladmin create $DB_NAME --skip-ssl --user="$DB_USER" --password="$DB_PASS"$EXTRA
144144
}
145145

146146
install_db() {
@@ -166,7 +166,7 @@ install_db() {
166166
fi
167167

168168
# create database
169-
if [ $(mysql --user="$DB_USER" --password="$DB_PASS"$EXTRA --execute='show databases;' | grep ^$DB_NAME$) ]
169+
if [ $(mysql --skip-ssl --user="$DB_USER" --password="$DB_PASS"$EXTRA --execute='show databases;' | grep ^$DB_NAME$) ]
170170
then
171171
echo "Reinstalling will delete the existing test database ($DB_NAME)"
172172
read -p 'Are you sure you want to proceed? [y/N]: ' DELETE_EXISTING_DB
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
{
2-
"extends": [
3-
"plugin:@wordpress/eslint-plugin/recommended"
4-
],
2+
"extends": [ "plugin:@wordpress/eslint-plugin/recommended" ],
53
"parserOptions": {
6-
"ecmaVersion": 2021,
4+
"ecmaVersion": 2021,
75
"sourceType": "module",
86
"ecmaFeatures": {
9-
"jsx": true
10-
}
11-
},
7+
"jsx": true
8+
}
9+
},
1210
"env": {
13-
"browser": true,
11+
"browser": true,
1412
"es6": true
15-
},
13+
},
1614
"rules": {
17-
// Any custom rules you want to add or override
18-
}
15+
// Any custom rules you want to add or override
16+
}
1917
}

src/documentcloud/blocks/__mocks__/@wordpress/components.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,31 @@ export const ToggleControl = ( { label, checked, onChange } ) => {
4040
</div>
4141
);
4242
};
43+
export const SelectControl = ( { label, value, options, onChange, help } ) => {
44+
const id = label
45+
? `select-control-${ label.replace( /\s+/g, '-' ).toLowerCase() }`
46+
: 'select-control-undefined';
47+
return (
48+
<div>
49+
{ label && <label htmlFor={ id }>{ label }</label> }
50+
<select
51+
id={ id }
52+
value={ value || '' }
53+
onChange={ ( e ) => onChange( e.target.value ) }
54+
>
55+
{ options &&
56+
options.map( ( option ) => (
57+
<option key={ option.value } value={ option.value }>
58+
{ option.label }
59+
</option>
60+
) ) }
61+
</select>
62+
{ help && (
63+
<p className="components-base-control__help">{ help }</p>
64+
) }
65+
</div>
66+
);
67+
};
4368
export const Placeholder = ( { children, instructions } ) => (
4469
<div>
4570
{ instructions && <p>{ instructions }</p> }

src/documentcloud/blocks/__tests__/edit.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe( 'DocumentCloud Block Edit Component', () => {
1717
fullscreen: false,
1818
onlyshoworg: false,
1919
pdf: false,
20+
mode: 'document',
2021
style: '',
2122
embeddedHtml: '',
2223
};
@@ -264,4 +265,28 @@ describe( 'DocumentCloud Block Edit Component', () => {
264265
} );
265266
expect( mockSetAttributes ).toHaveBeenCalledWith( { pdf: true } );
266267
} );
268+
269+
// Test: Mode selector calls setAttributes when changed
270+
it( 'calls setAttributes when mode selector is changed', () => {
271+
const attributesWithUrl = {
272+
...defaultAttributes,
273+
url: 'https://www.documentcloud.org/documents/282753-lefler-thesis/',
274+
};
275+
276+
render(
277+
<Edit
278+
attributes={ attributesWithUrl }
279+
setAttributes={ mockSetAttributes }
280+
/>
281+
);
282+
283+
// Find the mode selector
284+
const modeSelector = screen.getByLabelText( 'Default Viewer Mode' );
285+
286+
// Change the mode to 'notes'
287+
fireEvent.change( modeSelector, { target: { value: 'notes' } } );
288+
289+
// Check that setAttributes is called with the new mode
290+
expect( mockSetAttributes ).toHaveBeenCalledWith( { mode: 'notes' } );
291+
} );
267292
} );

src/documentcloud/blocks/__tests__/utils.test.js

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
getOEmbedApiUrl,
55
parseDocumentCloudUrl,
66
cleanDocumentCloudUrl,
7+
validateMode,
78
} from '../src/documentcloud/utils/utils';
89

910
describe( 'DocumentCloud Utils', () => {
@@ -59,10 +60,10 @@ describe( 'DocumentCloud Utils', () => {
5960
onlyshoworg: false,
6061
pdf: true,
6162
style: 'custom-style',
62-
responsive: true,
63+
responsive: true, // Check that we ignore the responsive option
6364
};
6465
expect( getEmbedUrl( params ) ).toBe(
65-
'https://www.documentcloud.org/documents/123?embed=1&title=1&fullscreen=0&onlyshoworg=0&pdf=1&style=custom-style&responsive=1'
66+
'https://www.documentcloud.org/documents/123?embed=1&title=1&fullscreen=0&onlyshoworg=0&pdf=1&style=custom-style'
6667
);
6768
} );
6869

@@ -76,12 +77,63 @@ describe( 'DocumentCloud Utils', () => {
7677
onlyshoworg: true,
7778
pdf: false,
7879
style: 'border: 1px solid #000;',
79-
responsive: false,
80+
responsive: false, // Check that we ignore the responsive option
8081
};
8182
expect( getEmbedUrl( params ) ).toBe(
82-
'https://embed.documentcloud.org/documents/24479621-24-03-13-epic-motion-to-enforce-injunction?embed=1&title=0&fullscreen=1&onlyshoworg=1&pdf=0&style=border%3A%201px%20solid%20%23000%3B&responsive=0'
83+
'https://embed.documentcloud.org/documents/24479621-24-03-13-epic-motion-to-enforce-injunction?embed=1&title=0&fullscreen=1&onlyshoworg=1&pdf=0&style=border%3A%201px%20solid%20%23000%3B'
8384
);
8485
} );
86+
87+
it( 'should include valid mode parameter in embed URL', () => {
88+
// Validates that valid mode values are included in the embed URL
89+
const validModes = [ 'document', 'notes', 'text', 'grid' ];
90+
91+
validModes.forEach( ( mode ) => {
92+
const params = {
93+
useDocumentId: true,
94+
documentId: '123',
95+
mode: mode,
96+
};
97+
const result = getEmbedUrl( params );
98+
expect( result ).toContain( `mode=${ mode }` );
99+
} );
100+
} );
101+
102+
it( 'should exclude invalid mode parameter from embed URL', () => {
103+
// Validates that invalid mode values are not included in the embed URL
104+
const invalidModes = [
105+
'invalid',
106+
'foo',
107+
'bar',
108+
'',
109+
null,
110+
undefined,
111+
];
112+
113+
invalidModes.forEach( ( mode ) => {
114+
const params = {
115+
useDocumentId: true,
116+
documentId: '123',
117+
mode: mode,
118+
};
119+
const result = getEmbedUrl( params );
120+
if ( mode && mode !== '' ) {
121+
expect( result ).not.toContain( `mode=${ mode }` );
122+
}
123+
expect( result ).not.toContain( 'mode=' );
124+
} );
125+
} );
126+
127+
it( 'should not include mode parameter when not specified', () => {
128+
// Validates that no mode parameter is added when not specified
129+
const params = {
130+
useDocumentId: true,
131+
documentId: '123',
132+
title: true,
133+
};
134+
const result = getEmbedUrl( params );
135+
expect( result ).not.toContain( 'mode=' );
136+
} );
85137
} );
86138

87139
// Tests for getOEmbedApiUrl
@@ -143,4 +195,30 @@ describe( 'DocumentCloud Utils', () => {
143195
} );
144196
} );
145197
} );
198+
199+
// Tests for validateMode
200+
describe( 'validateMode', () => {
201+
it( 'should return valid mode values', () => {
202+
// Tests that valid mode values are returned unchanged
203+
const validModes = [ 'document', 'notes', 'text', 'grid' ];
204+
validModes.forEach( ( mode ) => {
205+
expect( validateMode( mode ) ).toBe( mode );
206+
} );
207+
} );
208+
209+
it( 'should return null for invalid mode values', () => {
210+
// Tests that invalid mode values return null
211+
const invalidModes = [
212+
'invalid',
213+
'foo',
214+
'bar',
215+
'',
216+
null,
217+
undefined,
218+
];
219+
invalidModes.forEach( ( mode ) => {
220+
expect( validateMode( mode ) ).toBeNull();
221+
} );
222+
} );
223+
} );
146224
} );

src/documentcloud/blocks/build/blocks-manifest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@
4949
'type' => 'boolean',
5050
'default' => null
5151
),
52+
'mode' => array(
53+
'type' => 'string',
54+
'default' => 'document'
55+
),
5256
'embeddedHtml' => array(
5357
'type' => 'string',
5458
'default' => ''

src/documentcloud/blocks/build/documentcloud/block.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
"type": "boolean",
4545
"default": null
4646
},
47+
"mode": {
48+
"type": "string",
49+
"default": "document"
50+
},
4751
"embeddedHtml": {
4852
"type": "string",
4953
"default": ""

0 commit comments

Comments
 (0)