@archbase/components 4.0.35 → 4.0.36

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@archbase/components",
3
- "version": "4.0.35",
3
+ "version": "4.0.36",
4
4
  "description": "UI Components for Archbase React v3 - Form editors, data visualization, and business components",
5
5
  "author": "Edson Martins <edsonmartins2005@gmail.com>",
6
6
  "license": "MIT",
@@ -118,9 +118,9 @@
118
118
  "vis-timeline": "^7.7.3",
119
119
  "xlsx": "^0.18.5",
120
120
  "yet-another-react-lightbox": "^3.21.0",
121
- "@archbase/core": "4.0.35",
122
- "@archbase/data": "4.0.35",
123
- "@archbase/layout": "4.0.35"
121
+ "@archbase/core": "4.0.36",
122
+ "@archbase/data": "4.0.36",
123
+ "@archbase/layout": "4.0.36"
124
124
  },
125
125
  "devDependencies": {
126
126
  "@types/d3": "^7.4.3",
@@ -135,6 +135,8 @@ export interface ArchbaseAsyncSelectProps<T, ID, O> {
135
135
  converter?: (value: O) => any;
136
136
  /** Function que busca o valor original antes de converter pelo valor de retorno do converter */
137
137
  getConvertedOption?: (value: any) => Promise<O>;
138
+ /** Função que determina se uma opção individual está desabilitada */
139
+ isOptionDisabled?: (option: O) => boolean;
138
140
  }
139
141
  function buildOptions<O>(
140
142
  initialOptions: O[],
@@ -210,7 +212,8 @@ export function ArchbaseAsyncSelect<T, ID, O>({
210
212
  innerRef,
211
213
  onSearchChange,
212
214
  converter,
213
- getConvertedOption
215
+ getConvertedOption,
216
+ isOptionDisabled,
214
217
  }: ArchbaseAsyncSelectProps<T, ID, O>) {
215
218
  const forceUpdate = useForceUpdate();
216
219
 
@@ -539,7 +542,11 @@ export function ArchbaseAsyncSelect<T, ID, O>({
539
542
  {filteredOptions.slice(0, limit ? limit : filteredOptions.length).map((option) => {
540
543
  const {key, ...rest} = option
541
544
  return (
542
- <Combobox.Option value={option.value} key={option.key}>
545
+ <Combobox.Option
546
+ value={option.value}
547
+ key={option.key}
548
+ disabled={isOptionDisabled ? isOptionDisabled(option.origin) : false}
549
+ >
543
550
  {ItemComponent ? <ItemComponent {...rest} /> : option.label}
544
551
  </Combobox.Option>
545
552
  )
@@ -117,6 +117,8 @@ export interface ArchbaseSelectProps<T, ID, O> {
117
117
  * Por exemplo: (id) => fetchObjectById(id) para converter ID de volta ao objeto
118
118
  */
119
119
  getConvertedOption?: (value: any) => Promise<O>
120
+ /** Função que determina se uma opção individual está desabilitada */
121
+ isOptionDisabled?: (option: O) => boolean
120
122
  }
121
123
 
122
124
  function buildGroupOptions(
@@ -248,7 +250,8 @@ export function ArchbaseSelect<T, ID, O>({
248
250
  classNames,
249
251
  styles,
250
252
  converter,
251
- getConvertedOption
253
+ getConvertedOption,
254
+ isOptionDisabled,
252
255
  }: ArchbaseSelectProps<T, ID, O>) {
253
256
  const forceUpdate = useForceUpdate();
254
257
 
@@ -282,7 +285,7 @@ export function ArchbaseSelect<T, ID, O>({
282
285
  const contextError = validationContext?.getError(fieldKey);
283
286
 
284
287
  const currentOptions: any[] = useMemo(() => {
285
- return buildOptions<O>(
288
+ const opts = buildOptions<O>(
286
289
  options,
287
290
  initialOptions,
288
291
  children,
@@ -290,6 +293,19 @@ export function ArchbaseSelect<T, ID, O>({
290
293
  getOptionValue,
291
294
  optionsLabelField
292
295
  )
296
+ if (!isOptionDisabled) return opts
297
+ return opts.map((opt: any) => {
298
+ if (opt.group !== undefined) {
299
+ return {
300
+ ...opt,
301
+ items: opt.items.map((item: any) => ({
302
+ ...item,
303
+ disabled: isOptionDisabled(item.origin ?? item),
304
+ })),
305
+ }
306
+ }
307
+ return { ...opt, disabled: isOptionDisabled(opt.origin ?? opt) }
308
+ })
293
309
  }, [
294
310
  updateCounter,
295
311
  options,
@@ -297,7 +313,8 @@ export function ArchbaseSelect<T, ID, O>({
297
313
  children,
298
314
  getOptionLabel,
299
315
  getOptionValue,
300
- optionsLabelField
316
+ optionsLabelField,
317
+ isOptionDisabled,
301
318
  ])
302
319
 
303
320
  const handleConverter = (value) => {
Binary file