@archbase/components 4.0.34 → 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.34",
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.34",
122
- "@archbase/data": "4.0.34",
123
- "@archbase/layout": "4.0.34"
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) => {
@@ -17,6 +17,25 @@ const formatDate = (date: Date | null): string => {
17
17
  return date.toLocaleDateString();
18
18
  };
19
19
 
20
+ // Formata uma data para "YYYY-MM-DD" em horário LOCAL (DatePickerInput do Mantine 9 é string-based).
21
+ // Usar toISOString() aqui desloca o dia em fusos negativos (ex.: 21:00 BRT vira o dia seguinte em UTC).
22
+ const toLocalDateInputValue = (date: Date | null): string | null => {
23
+ if (!date) return null;
24
+ const year = date.getFullYear();
25
+ const month = (date.getMonth() + 1).toString().padStart(2, '0');
26
+ const day = date.getDate().toString().padStart(2, '0');
27
+ return `${year}-${month}-${day}`;
28
+ };
29
+
30
+ // Aplica a data selecionada ("YYYY-MM-DD") preservando a hora já existente (ou a atual), em horário local.
31
+ const applyDateInputValue = (value: string | null, current: Date | null): Date | null => {
32
+ if (!value) return null;
33
+ const [year, month, day] = value.split('-').map(Number);
34
+ const result = current ? new Date(current.getTime()) : new Date();
35
+ result.setFullYear(year, month - 1, day);
36
+ return result;
37
+ };
38
+
20
39
  // Função para formatar o intervalo de datas para exibição resumida (versão curta para o botão)
21
40
  const formatDateRange = (start: Date | null, end: Date | null): string => {
22
41
  if (!start || !end) return 'Selecionar intervalo';
@@ -176,9 +195,7 @@ export const ArchbaseTimeRangeSelector: FC<ArchbaseTimeRangeSelectorProps> = (pr
176
195
 
177
196
  // Atualizar o estado quando o defaultRangeValue muda
178
197
  useEffect(() => {
179
- console.log('[TimeRangeSelector] useEffect defaultRangeValue=%s, selectedRange=%s', defaultRangeValue, selectedRange);
180
198
  if (defaultRangeValue !== undefined) {
181
- console.log('[TimeRangeSelector] setSelectedRange(%s)', defaultRangeValue);
182
199
  // Atualizar o selectedRange
183
200
  setSelectedRange(defaultRangeValue);
184
201
 
@@ -236,7 +253,6 @@ export const ArchbaseTimeRangeSelector: FC<ArchbaseTimeRangeSelectorProps> = (pr
236
253
 
237
254
  // Manipular a mudança de range (predefinido ou customizado)
238
255
  const handleRangeChange = (value: string | null) => {
239
- console.log('[TimeRangeSelector] handleRangeChange value=%s', value);
240
256
  setSelectedRange(value);
241
257
 
242
258
  // Se não for range customizado, aplicar imediatamente
@@ -343,8 +359,8 @@ export const ArchbaseTimeRangeSelector: FC<ArchbaseTimeRangeSelectorProps> = (pr
343
359
  <Group grow mt="xs">
344
360
  <DatePickerInput
345
361
  label="Data inicial"
346
- value={customRange.start ? customRange.start.toISOString().split('T')[0] : null}
347
- onChange={(date: string | null) => setCustomRange(prev => ({ ...prev, start: date ? new Date(date) : null }))}
362
+ value={toLocalDateInputValue(customRange.start)}
363
+ onChange={(date: string | null) => setCustomRange(prev => ({ ...prev, start: applyDateInputValue(date, prev.start) }))}
348
364
  style={{ flex: 1 }}
349
365
  popoverProps={{ withinPortal: false, closeOnClickOutside: false }}
350
366
  />
@@ -365,8 +381,8 @@ export const ArchbaseTimeRangeSelector: FC<ArchbaseTimeRangeSelectorProps> = (pr
365
381
  <Group grow mt="xs">
366
382
  <DatePickerInput
367
383
  label="Data final"
368
- value={customRange.end ? customRange.end.toISOString().split('T')[0] : null}
369
- onChange={(date: string | null) => setCustomRange(prev => ({ ...prev, end: date ? new Date(date) : null }))}
384
+ value={toLocalDateInputValue(customRange.end)}
385
+ onChange={(date: string | null) => setCustomRange(prev => ({ ...prev, end: applyDateInputValue(date, prev.end) }))}
370
386
  style={{ flex: 1 }}
371
387
  popoverProps={{ withinPortal: false, closeOnClickOutside: false }}
372
388
  />
Binary file