Skip to content

Commit c7996df

Browse files
committed
refactor: changes & rebase
1 parent 9f76ff9 commit c7996df

File tree

11 files changed

+40
-97
lines changed

11 files changed

+40
-97
lines changed

src/Autocomplete/assets/dist/controller.js

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
import { Controller } from '@hotwired/stimulus';
22
import TomSelect from 'tom-select';
33

4-
/******************************************************************************
5-
Copyright (c) Microsoft Corporation.
6-
7-
Permission to use, copy, modify, and/or distribute this software for any
8-
purpose with or without fee is hereby granted.
9-
10-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16-
PERFORMANCE OF THIS SOFTWARE.
17-
***************************************************************************** */
18-
19-
function __classPrivateFieldGet(receiver, state, kind, f) {
20-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
21-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
22-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
4+
/******************************************************************************
5+
Copyright (c) Microsoft Corporation.
6+
7+
Permission to use, copy, modify, and/or distribute this software for any
8+
purpose with or without fee is hereby granted.
9+
10+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16+
PERFORMANCE OF THIS SOFTWARE.
17+
***************************************************************************** */
18+
19+
function __classPrivateFieldGet(receiver, state, kind, f) {
20+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
21+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
22+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
2323
}
2424

2525
var _instances, _getCommonConfig, _createAutocomplete, _createAutocompleteWithHtmlContents, _createAutocompleteWithRemoteData, _stripTags, _mergeObjects, _createTomSelect, _dispatchEvent;
@@ -131,7 +131,7 @@ _instances = new WeakSet(), _getCommonConfig = function _getCommonConfig() {
131131
const url = this.getUrl(query);
132132
fetch(url)
133133
.then(response => response.json())
134-
.then(json => { this.setNextUrl(query, json.next_page); callback(json.results.options || json.results, json.results.optgroups || []); })
134+
.then(json => { this.setNextUrl(query, json.next_page); callback(json.results.options, json.results.optgroups || []); })
135135
.catch(() => callback());
136136
},
137137
shouldLoad: function (query) {

src/Autocomplete/assets/src/controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export default class extends Controller {
141141
fetch(url)
142142
.then(response => response.json())
143143
// important: next_url must be set before invoking callback()
144-
.then(json => { this.setNextUrl(query, json.next_page); callback(json.results.options || json.results, json.results.optgroups || []) })
144+
.then(json => { this.setNextUrl(query, json.next_page); callback(json.results.options, json.results.optgroups || []) })
145145
.catch(() => callback());
146146
},
147147
shouldLoad: function (query: string) {

src/Autocomplete/assets/test/controller.test.ts

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -87,71 +87,6 @@ describe('AutocompleteController', () => {
8787
expect(tomSelect.input).toBe(getByTestId(container, 'main-element'));
8888
});
8989

90-
it('connect with ajax URL BC data', async () => {
91-
const container = mountDOM(`
92-
<label for="the-select">Items</label>
93-
<select
94-
id="the-select"
95-
data-testid="main-element"
96-
data-controller="check autocomplete"
97-
data-autocomplete-url-value="/path/to/autocomplete"
98-
></select>
99-
`);
100-
101-
application = startStimulus();
102-
103-
await waitFor(() => {
104-
expect(getByTestId(container, 'main-element')).toHaveClass('connected');
105-
});
106-
107-
// initial Ajax request on focus
108-
fetchMock.mock(
109-
'/path/to/autocomplete?query=',
110-
JSON.stringify({
111-
results: [
112-
{
113-
value: 3,
114-
text: 'salad'
115-
},
116-
]
117-
}),
118-
);
119-
120-
fetchMock.mock(
121-
'/path/to/autocomplete?query=foo',
122-
JSON.stringify({
123-
results: [
124-
{
125-
value: 1,
126-
text: 'pizza'
127-
},
128-
{
129-
value: 2,
130-
text: 'popcorn'
131-
}
132-
]
133-
}),
134-
);
135-
136-
const tomSelect = getByTestId(container, 'main-element').tomSelect;
137-
const controlInput = tomSelect.control_input;
138-
139-
// wait for the initial Ajax request to finish
140-
userEvent.click(controlInput);
141-
await waitFor(() => {
142-
expect(container.querySelectorAll('.option[data-selectable]')).toHaveLength(1);
143-
});
144-
145-
// typing was not properly triggering, for some reason
146-
//userEvent.type(controlInput, 'foo');
147-
controlInput.value = 'foo';
148-
controlInput.dispatchEvent(new Event('input'));
149-
150-
await waitFor(() => {
151-
expect(container.querySelectorAll('.option[data-selectable]')).toHaveLength(2);
152-
});
153-
});
154-
15590
it('connect with ajax URL', async () => {
15691
const container = mountDOM(`
15792
<label for="the-select">Items</label>

src/Autocomplete/src/AutocompleteResults.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
final class AutocompleteResults
1515
{
1616
/**
17-
* @param list<array{label: string, value: mixed}> $results
17+
* @param list<array{text: string, value: mixed, group_by?: string}> $options
18+
* @param list<array{label: string, value: string}> $optgroups
1819
*/
1920
public function __construct(
20-
public array $results,
21+
public array $options,
22+
public array $optgroups,
2123
public bool $hasNextPage,
2224
) {
2325
}

src/Autocomplete/src/Controller/EntityAutocompleteController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __invoke(string $alias, Request $request): Response
5252
}
5353

5454
return new JsonResponse([
55-
'results' => $data->results,
55+
'results' => ['options' => $data->options, 'optgroups' => $data->optgroups],
5656
'next_page' => $nextPage,
5757
]);
5858
}

src/Autocomplete/src/DependencyInjection/AutocompleteExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ private function registerBasicServices(ContainerBuilder $container): void
8383
->register('ux.autocomplete.results_executor', AutocompleteResultsExecutor::class)
8484
->setArguments([
8585
new Reference('ux.autocomplete.doctrine_registry_wrapper'),
86+
new Reference('property_accessor'),
8687
new Reference('security.helper', ContainerInterface::NULL_ON_INVALID_REFERENCE),
8788
])
8889
;

src/Autocomplete/src/EntityAutocompleterInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function getValue(object $entity): mixed;
4848
public function isGranted(Security $security): bool;
4949

5050
/**
51-
* Return Form option by name.
51+
* Return group_by option.
5252
*/
53-
public function getFormOption(string $name): mixed;
53+
public function getGroupBy(): mixed;
5454
}

src/Autocomplete/src/Form/WrappedEntityTypeAutocompleter.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,12 @@ public function isGranted(Security $security): bool
112112
throw new \InvalidArgumentException('Invalid passed to the "security" option: it must be the boolean true, a string role or a callable.');
113113
}
114114

115-
public function getFormOption(string $name): mixed
115+
public function getGroupBy(): mixed
116+
{
117+
return $this->getFormOption('group_by');
118+
}
119+
120+
private function getFormOption(string $name): mixed
116121
{
117122
$form = $this->getForm();
118123
$formOptions = $form['autocomplete']->getConfig()->getOptions();

src/Autocomplete/tests/Fixtures/Autocompleter/CustomGroupByProductAutocompleter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
class CustomGroupByProductAutocompleter extends CustomProductAutocompleter
1414
{
15-
public function getFormOption(string $name): mixed
15+
public function getGroupBy(): mixed
1616
{
17-
return 'group_by' === $name ? 'category.name' : null;
17+
return 'category.name';
1818
}
1919
}

src/Autocomplete/tests/Fixtures/Autocompleter/CustomProductAutocompleter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public function isGranted(Security $security): bool
5959
return true;
6060
}
6161

62-
public function getFormOption(string $name): mixed
62+
public function getGroupBy(): mixed
6363
{
6464
return null;
6565
}

0 commit comments

Comments
 (0)