Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit 5055f75

Browse files
committed
fixed issue (#204 (comment))
1 parent 69af029 commit 5055f75

File tree

3 files changed

+36
-13
lines changed

3 files changed

+36
-13
lines changed

packages/multieditor/src/multieditor/multieditor.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ export class Multieditor<
7676
Object.keys(
7777
_config.validationSchema as ValidationSchemaType<DataType>
7878
).forEach((key) => {
79-
const validationMethod = (
80-
_config.validationSchema as ValidationSchemaType<DataType>
81-
)[key];
79+
const validationMethod = (_config.validationSchema as ValidationSchemaType<
80+
DataType
81+
>)[key];
8282

8383
// If validation schema item is a Validator
8484
if (validationMethod instanceof Validator) {
@@ -294,6 +294,10 @@ export class Multieditor<
294294
/**
295295
* Assigns the specified new Status to the Item with the specified key/name identifier.
296296
*
297+
* However, if tracking of the particular Status is active,
298+
* the value is only tracked (not applied).
299+
* If the tracking has been finished the last tracked Status value should be applied to the Status.
300+
*
297301
* @public
298302
* @param itemKey - Key/Name identifier of the Item.
299303
* @param type - Status type
@@ -302,10 +306,13 @@ export class Multieditor<
302306
public setStatus(itemKey: ItemKey, type: StatusType, message: string): this {
303307
const item = this.getItem(itemKey);
304308
if (item == null) return this;
305-
item.status.set({
306-
type,
307-
message,
308-
});
309+
item.status.set(
310+
{
311+
type,
312+
message,
313+
},
314+
{ waitForTracking: true }
315+
);
309316
return this;
310317
}
311318

packages/multieditor/src/status/status.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { State, StateIngestConfigInterface } from '@agile-ts/core';
2-
import { copy, generateId } from '@agile-ts/utils';
2+
import { copy, defineConfig } from '@agile-ts/utils';
33
import { Item } from '../item';
44
import { StatusTracker } from './status.tracker';
55

@@ -43,12 +43,15 @@ export class Status<DataType = any> extends State<StatusValueType> {
4343
* @param value - New Status value
4444
* @param config - Configuration object
4545
*/
46-
public set(
47-
value: StatusValueType,
48-
config: StateIngestConfigInterface = {}
49-
): this {
46+
public set(value: StatusValueType, config: StatusSetInterface = {}): this {
47+
config = defineConfig(config, {
48+
waitForTracking: false,
49+
});
5050
if (value != null) this.statusTracker.tracked(value);
5151

52+
// Return when waiting for end of tracking to apply the last tracked change to the Status, if applicable
53+
if (config.waitForTracking && this.statusTracker.isTracking) return this;
54+
5255
// Ingest the Status with the new value into the runtime
5356
if (
5457
this.item == null || // Because on the initial set (when calling '.super') the Item isn't set
@@ -73,3 +76,14 @@ export interface StatusInterface {
7376
*/
7477
message: string;
7578
}
79+
80+
export interface StatusSetInterface extends StateIngestConfigInterface {
81+
/**
82+
* If tracking of the particular Status is active,
83+
* the value is only tracked (not applied).
84+
* If the tracking has been finished the last tracked Status value should be applied to the Status.
85+
* (See: https://github.com/agile-ts/agile/pull/204#issuecomment-925934647)
86+
* @default false
87+
*/
88+
waitForTracking?: boolean;
89+
}

packages/multieditor/src/validator/validator.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ export class Validator<DataType = any> {
7070

7171
// Handle tracked Statuses
7272
const trackedStatuses = item.status.statusTracker.getTrackedStatuses();
73-
if (trackedStatuses.length <= 0) editor.resetStatus(item._key);
73+
if (trackedStatuses.length > 0)
74+
item.status.set(trackedStatuses[trackedStatuses.length - 1]);
75+
else editor.resetStatus(item._key);
7476

7577
return isValid;
7678
}

0 commit comments

Comments
 (0)