-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#845 Fix table invalidation for classes with required properties
- Loading branch information
Showing
8 changed files
with
117 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...a-browser/src/components/forms/NewForm/CustomCreateActions/CustomForms/NewDriveDialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
browser/data-browser/src/views/TablePage/useTableInvalidation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Resource, StoreEvents, useStore } from '@tomic/react'; | ||
import { useCallback, useEffect, useState } from 'react'; | ||
import { | ||
CursorMode, | ||
useTableEditorContext, | ||
} from '../../components/TableEditor/TableEditorContext'; | ||
|
||
export function useTableInvalidation( | ||
resource: Resource, | ||
invalidateTable: () => void, | ||
) { | ||
const store = useStore(); | ||
const { cursorMode } = useTableEditorContext(); | ||
|
||
const [markedForInvalidation, setMarkedForInvalidation] = useState(false); | ||
|
||
const onEnter = useCallback(() => { | ||
if (markedForInvalidation) { | ||
invalidateTable(); | ||
} | ||
}, [invalidateTable, markedForInvalidation]); | ||
|
||
useEffect(() => { | ||
if (markedForInvalidation && cursorMode !== CursorMode.Edit) { | ||
invalidateTable(); | ||
} | ||
}, [markedForInvalidation, cursorMode]); | ||
|
||
// The first time a resource is saved, mark it for invalidation | ||
useEffect(() => { | ||
return store.on(StoreEvents.ResourceSaved, r => { | ||
if (!markedForInvalidation && r.subject === resource.subject) { | ||
setMarkedForInvalidation(true); | ||
} | ||
}); | ||
}, [resource, store, markedForInvalidation]); | ||
|
||
return onEnter; | ||
} |