1212trait SharpAssertions
1313{
1414 private BreadcrumbBuilder $ breadcrumbBuilder ;
15+ private ?string $ filterKey = null ;
1516
1617 /**
1718 * @deprecated use withSharpBreadcrumb() instead
@@ -42,28 +43,36 @@ public function withSharpBreadcrumb(Closure $callback): self
4243 return $ this ;
4344 }
4445
45- public function deleteFromSharpShow ( string $ entityClassNameOrKey , $ instanceId )
46+ public function withSharpGlobalFilterKeys ( array | string $ filterKeys ): self
4647 {
47- URL ::defaults (['filterKey ' => GlobalFilters::$ defaultKey ]);
48+ $ this ->filterKey = collect ((array ) $ filterKeys )
49+ ->implode (GlobalFilters::$ valuesUrlSeparator );
50+
51+ return $ this ;
52+ }
53+
54+ public function deleteFromSharpShow (string $ entityClassNameOrKey , mixed $ instanceId )
55+ {
56+ URL ::defaults (['filterKey ' => $ this ->filterKey ?: GlobalFilters::$ defaultKey ]);
4857
4958 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
5059
5160 return $ this
5261 ->delete (
5362 route (
5463 'code16.sharp.show.delete ' , [
55- $ this ->breadcrumbBuilder ( $ entityKey )
56- ->generateUri (),
57- $ entityKey ,
58- $ instanceId ,
64+ ' filterKey ' => $ this ->filterKey ,
65+ ' parentUri ' => $ this -> breadcrumbBuilder ( $ entityKey ) ->generateUri (),
66+ ' entityKey ' => $ entityKey ,
67+ ' instanceId ' => $ instanceId ,
5968 ]
6069 ),
6170 );
6271 }
6372
64- public function deleteFromSharpList (string $ entityClassNameOrKey , $ instanceId )
73+ public function deleteFromSharpList (string $ entityClassNameOrKey , mixed $ instanceId )
6574 {
66- URL ::defaults (['filterKey ' => GlobalFilters::$ defaultKey ]);
75+ URL ::defaults (['filterKey ' => $ this -> filterKey ?: GlobalFilters::$ defaultKey ]);
6776
6877 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
6978
@@ -74,12 +83,18 @@ public function deleteFromSharpList(string $entityClassNameOrKey, $instanceId)
7483 $ this ->breadcrumbBuilder ($ entityKey )
7584 ),
7685 )
77- ->delete (route ('code16.sharp.api.list.delete ' , [$ entityKey , $ instanceId ]));
86+ ->delete (
87+ route ('code16.sharp.api.list.delete ' , [
88+ 'filterKey ' => $ this ->filterKey ,
89+ 'entityKey ' => $ entityKey ,
90+ 'instanceId ' => $ instanceId ,
91+ ])
92+ );
7893 }
7994
80- public function getSharpForm (string $ entityClassNameOrKey , $ instanceId = null )
95+ public function getSharpForm (string $ entityClassNameOrKey , mixed $ instanceId = null )
8196 {
82- URL ::defaults (['filterKey ' => GlobalFilters::$ defaultKey ]);
97+ URL ::defaults (['filterKey ' => $ this -> filterKey ?: GlobalFilters::$ defaultKey ]);
8398
8499 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
85100
@@ -89,26 +104,26 @@ public function getSharpForm(string $entityClassNameOrKey, $instanceId = null)
89104 ? route (
90105 'code16.sharp.form.edit ' ,
91106 [
92- $ this ->breadcrumbBuilder ( $ entityKey )
93- ->generateUri (),
94- $ entityKey ,
95- $ instanceId ,
107+ ' filterKey ' => $ this ->filterKey ,
108+ ' parentUri ' => $ this -> breadcrumbBuilder ( $ entityKey ) ->generateUri (),
109+ ' entityKey ' => $ entityKey ,
110+ ' instanceId ' => $ instanceId ,
96111 ]
97112 )
98113 : route (
99114 'code16.sharp.form.create ' ,
100115 [
101- $ this ->breadcrumbBuilder ( $ entityKey )
102- ->generateUri (),
103- $ entityKey ,
116+ ' filterKey ' => $ this ->filterKey ,
117+ ' parentUri ' => $ this -> breadcrumbBuilder ( $ entityKey ) ->generateUri (),
118+ ' entityKey ' => $ entityKey ,
104119 ]
105120 ),
106121 );
107122 }
108123
109124 public function getSharpSingleForm (string $ entityClassNameOrKey )
110125 {
111- URL ::defaults (['filterKey ' => GlobalFilters::$ defaultKey ]);
126+ URL ::defaults (['filterKey ' => $ this -> filterKey ?: GlobalFilters::$ defaultKey ]);
112127
113128 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
114129
@@ -117,28 +132,28 @@ public function getSharpSingleForm(string $entityClassNameOrKey)
117132 route (
118133 'code16.sharp.form.edit ' ,
119134 [
120- $ this ->breadcrumbBuilder ( $ entityKey )
121- ->generateUri (),
122- $ entityKey ,
135+ ' filterKey ' => $ this ->filterKey ,
136+ ' parentUri ' => $ this -> breadcrumbBuilder ( $ entityKey ) ->generateUri (),
137+ ' entityKey ' => $ entityKey ,
123138 ]
124139 )
125140 );
126141 }
127142
128143 public function updateSharpForm (string $ entityClassNameOrKey , $ instanceId , array $ data )
129144 {
130- URL ::defaults (['filterKey ' => GlobalFilters::$ defaultKey ]);
145+ URL ::defaults (['filterKey ' => $ this -> filterKey ?: GlobalFilters::$ defaultKey ]);
131146
132147 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
133148
134149 return $ this
135150 ->post (
136151 route (
137152 'code16.sharp.form.update ' , [
138- $ this ->breadcrumbBuilder ( $ entityKey )
139- ->generateUri (),
140- $ entityKey ,
141- $ instanceId ,
153+ ' filterKey ' => $ this ->filterKey ,
154+ ' parentUri ' => $ this -> breadcrumbBuilder ( $ entityKey ) ->generateUri (),
155+ ' entityKey ' => $ entityKey ,
156+ ' instanceId ' => $ instanceId ,
142157 ]
143158 ),
144159 $ data ,
@@ -147,17 +162,17 @@ public function updateSharpForm(string $entityClassNameOrKey, $instanceId, array
147162
148163 public function updateSharpSingleForm (string $ entityClassNameOrKey , array $ data )
149164 {
150- URL ::defaults (['filterKey ' => GlobalFilters::$ defaultKey ]);
165+ URL ::defaults (['filterKey ' => $ this -> filterKey ?: GlobalFilters::$ defaultKey ]);
151166
152167 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
153168
154169 return $ this
155170 ->post (
156171 route (
157172 'code16.sharp.form.update ' , [
158- $ this ->breadcrumbBuilder ( $ entityKey )
159- ->generateUri (),
160- $ entityKey ,
173+ ' filterKey ' => $ this ->filterKey ,
174+ ' parentUri ' => $ this -> breadcrumbBuilder ( $ entityKey ) ->generateUri (),
175+ ' entityKey ' => $ entityKey ,
161176 ]
162177 ),
163178 $ data ,
@@ -166,7 +181,7 @@ public function updateSharpSingleForm(string $entityClassNameOrKey, array $data)
166181
167182 public function getSharpShow (string $ entityClassNameOrKey , $ instanceId )
168183 {
169- URL ::defaults (['filterKey ' => GlobalFilters::$ defaultKey ]);
184+ URL ::defaults (['filterKey ' => $ this -> filterKey ?: GlobalFilters::$ defaultKey ]);
170185
171186 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
172187
@@ -175,18 +190,18 @@ public function getSharpShow(string $entityClassNameOrKey, $instanceId)
175190 route (
176191 'code16.sharp.show.show ' ,
177192 [
178- $ this ->breadcrumbBuilder ( $ entityKey )
179- ->generateUri (),
180- $ entityKey ,
181- $ instanceId ,
193+ ' filterKey ' => $ this ->filterKey ,
194+ ' parentUri ' => $ this -> breadcrumbBuilder ( $ entityKey ) ->generateUri (),
195+ ' entityKey ' => $ entityKey ,
196+ ' instanceId ' => $ instanceId ,
182197 ]
183198 ),
184199 );
185200 }
186201
187202 public function storeSharpForm (string $ entityClassNameOrKey , array $ data )
188203 {
189- URL ::defaults (['filterKey ' => GlobalFilters::$ defaultKey ]);
204+ URL ::defaults (['filterKey ' => $ this -> filterKey ?: GlobalFilters::$ defaultKey ]);
190205
191206 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
192207
@@ -195,9 +210,9 @@ public function storeSharpForm(string $entityClassNameOrKey, array $data)
195210 route (
196211 'code16.sharp.form.store ' ,
197212 [
198- $ this ->breadcrumbBuilder ( $ entityKey )
199- ->generateUri (),
200- $ entityKey ,
213+ ' filterKey ' => $ this ->filterKey ,
214+ ' parentUri ' => $ this -> breadcrumbBuilder ( $ entityKey ) ->generateUri (),
215+ ' entityKey ' => $ entityKey ,
201216 ]
202217 ),
203218 $ data ,
@@ -211,7 +226,7 @@ public function callSharpInstanceCommandFromList(
211226 array $ data = [],
212227 ?string $ commandStep = null
213228 ) {
214- URL ::defaults (['filterKey ' => GlobalFilters::$ defaultKey ]);
229+ URL ::defaults (['filterKey ' => $ this -> filterKey ?: GlobalFilters::$ defaultKey ]);
215230
216231 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
217232
@@ -242,7 +257,7 @@ public function callSharpInstanceCommandFromShow(
242257 array $ data = [],
243258 ?string $ commandStep = null
244259 ) {
245- URL ::defaults (['filterKey ' => GlobalFilters::$ defaultKey ]);
260+ URL ::defaults (['filterKey ' => $ this -> filterKey ?: GlobalFilters::$ defaultKey ]);
246261
247262 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
248263
@@ -272,7 +287,7 @@ public function callSharpEntityCommandFromList(
272287 array $ data = [],
273288 ?string $ commandStep = null
274289 ) {
275- URL ::defaults (['filterKey ' => GlobalFilters::$ defaultKey ]);
290+ URL ::defaults (['filterKey ' => $ this -> filterKey ?: GlobalFilters::$ defaultKey ]);
276291
277292 $ entityKey = $ this ->resolveEntityKey ($ entityClassNameOrKey );
278293
@@ -283,9 +298,7 @@ public function callSharpEntityCommandFromList(
283298 return $ this
284299 ->withHeader (
285300 SharpBreadcrumb::CURRENT_PAGE_URL_HEADER ,
286- $ this ->buildCurrentPageUrl (
287- $ this ->breadcrumbBuilder ($ entityKey )
288- ),
301+ $ this ->buildCurrentPageUrl ($ this ->breadcrumbBuilder ($ entityKey ))
289302 )
290303 ->postJson (
291304 route ('code16.sharp.api.list.command.entity ' , compact ('entityKey ' , 'commandKey ' )),
@@ -313,8 +326,9 @@ private function buildCurrentPageUrl(BreadcrumbBuilder $builder): string
313326 {
314327 return url (
315328 sprintf (
316- '/%s/%s ' ,
329+ '/%s/%s/%s ' ,
317330 sharp ()->config ()->get ('custom_url_segment ' ),
331+ sharp ()->context ()->globalFilterUrlSegmentValue (),
318332 $ builder ->generateUri ()
319333 )
320334 );
0 commit comments