Skip to content

Commit

Permalink
New isDirty aliases. (#3915)
Browse files Browse the repository at this point in the history
  • Loading branch information
lbwexler authored Feb 4, 2025
1 parent f50a194 commit 072f825
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* Introduced a new "JSON Search" feature to the Hoist Admin Console, accessible from the Config,
User Preference, and JSON Blob tabs. Supports searching JSON values stored within these objects
to filter and match data using JSON Path expressions.
* New aliases `StoreRecord.isDirty`, `Store.dirtyRecords`, and `Store.isDirty` provide a more
consistent API in the data package.

### 🐞 Bug Fixes

Expand Down
6 changes: 3 additions & 3 deletions admin/tabs/userData/roles/editor/form/RoleFormModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ export class RoleFormModel extends HoistModel {
@computed
get hasDirtyMembers(): boolean {
return (
this.usersGridModel.store.isModified ||
this.directoryGroupsGridModel.store.isModified ||
this.rolesGridModel.store.isModified
this.usersGridModel.store.isDirty ||
this.directoryGroupsGridModel.store.isDirty ||
this.rolesGridModel.store.isDirty
);
}

Expand Down
16 changes: 13 additions & 3 deletions data/Store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ export class Store extends HoistBase {
// sourced from the server / source of record and are coming in as committed.
this._committed = this._committed.withTransaction(rsTransaction);

if (this.isModified) {
if (this.isDirty) {
// If this store had pre-existing local modifications, apply the updates over that
// local state. This might (or might not) effectively overwrite those local changes,
// so we normalize against the newly updated committed state to verify if any local
Expand Down Expand Up @@ -662,8 +662,13 @@ export class Store extends HoistBase {
}

/** Records modified locally since they were last loaded. */
get dirtyRecords(): StoreRecord[] {
return this.allRecords.filter(it => it.isDirty);
}

/** Alias for {@link Store.dirtyRecords} */
get modifiedRecords(): StoreRecord[] {
return this.allRecords.filter(it => it.isModified);
return this.dirtyRecords;
}

/**
Expand Down Expand Up @@ -696,10 +701,15 @@ export class Store extends HoistBase {

/** True if the store has changes which need to be committed. */
@computed
get isModified(): boolean {
get isDirty(): boolean {
return this._current !== this._committed;
}

/** Alias for {@link Store.isDirty} */
get isModified(): boolean {
return this.isDirty;
}

/**
* Set a filter on this store.
*
Expand Down
7 changes: 6 additions & 1 deletion data/StoreRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,15 @@ export class StoreRecord {
}

/** True if the StoreRecord has been modified since it was last committed. */
get isModified(): boolean {
get isDirty(): boolean {
return this.committedData && this.committedData !== this.data;
}

/** Alias for {@link StoreRecord.isDirty} */
get isModified(): boolean {
return this.isDirty;
}

/** False if the StoreRecord has been added or modified. */
get isCommitted(): boolean {
return this.committedData === this.data;
Expand Down

0 comments on commit 072f825

Please sign in to comment.