Skip to content

Commit

Permalink
Use a different diff library
Browse files Browse the repository at this point in the history
  • Loading branch information
fongsean committed Sep 21, 2023
1 parent 6747224 commit 44c4ab6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 62 deletions.
6 changes: 3 additions & 3 deletions apps/smart-forms-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
},
"homepage": "https://github.com/aehrc/smart-forms#readme",
"dependencies": {
"@aehrc/sdc-assemble": "^1.0.2",
"@aehrc/sdc-populate": "^1.0.4",
"@aehrc/smart-forms-renderer": "^0.7.2",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.10.8",
Expand Down Expand Up @@ -66,8 +68,6 @@
"react-router-dom": "6.15.0",
"react-spinners": "^0.13.8",
"react-to-print": "^2.14.13",
"@aehrc/sdc-assemble": "^1.0.2",
"@aehrc/sdc-populate": "^1.0.4",
"simplebar-react": "^3.2.4",
"usehooks-ts": "^2.9.1",
"zustand": "^4.4.1"
Expand Down Expand Up @@ -104,8 +104,8 @@
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"jest": "^29.6.4",
"eslint-plugin-storybook": "^0.6.13",
"jest": "^29.6.4",
"prettier": "^3.0.3",
"storybook": "^7.4.2",
"ts-jest": "^29.1.1",
Expand Down
6 changes: 1 addition & 5 deletions apps/smart-forms-app/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@ import svgr from 'vite-plugin-svgr';

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), svgr()],
define: {
'process.argv': process.argv, // temporary solution for json-diff & vite combination (see: https://github.com/andreyvit/json-diff/issues/123)
'process.env': {} // temporary solution for json-diff & vite combination (see: https://github.com/andreyvit/json-diff/issues/123)
}
plugins: [react(), svgr()]
});
62 changes: 14 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions packages/smart-forms-renderer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"homepage": "https://github.com/aehrc/smart-forms#readme",
"dependencies": {
"json-diff": "^1.0.6",
"deep-diff": "^1.0.2",
"@iconify/react": "^4.1.1",
"dayjs": "^1.11.9",
"fhirclient": "^2.5.2",
Expand Down Expand Up @@ -63,7 +63,7 @@
"@testing-library/react": "^14.0.0",
"@testing-library/react-hooks": "^7.0.2",
"@types/jest": "^29.5.4",
"@types/json-diff": "^1.0.0",
"@types/deep-diff": "^1.0.2",
"@types/react": "^18.2.18",
"@types/react-dom": "^18.2.7",
"jest": "^29.6.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { create } from 'zustand';
import type { QuestionnaireResponse } from 'fhir/r4';
import { emptyResponse } from '../utils/emptyResource';
import cloneDeep from 'lodash.clonedeep';
import { diff } from 'json-diff';
import type { Diff } from 'deep-diff';
import { diff } from 'deep-diff';

export interface UseQuestionnaireResponseStoreType {
sourceResponse: QuestionnaireResponse;
updatableResponse: QuestionnaireResponse;
formChangesHistory: object[];
formChangesHistory: (Diff<QuestionnaireResponse, QuestionnaireResponse>[] | null)[];
buildSourceResponse: (response: QuestionnaireResponse) => void;
setUpdatableResponseAsPopulated: (populatedResponse: QuestionnaireResponse) => void;
updateResponse: (updatedResponse: QuestionnaireResponse) => void;
Expand All @@ -27,14 +28,14 @@ const useQuestionnaireResponseStore = create<UseQuestionnaireResponseStoreType>(
}));
},
setUpdatableResponseAsPopulated: (populatedResponse: QuestionnaireResponse) => {
const formChanges = diff(get().updatableResponse, populatedResponse, { full: true });
const formChanges = diff(get().updatableResponse, populatedResponse) ?? null;
set(() => ({
updatableResponse: populatedResponse,
formChangesHistory: [...get().formChangesHistory, formChanges]
}));
},
updateResponse: (updatedResponse: QuestionnaireResponse) => {
const formChanges = diff(get().updatableResponse, updatedResponse, { full: true });
const formChanges = diff(get().updatableResponse, updatedResponse) ?? null;
set(() => ({
updatableResponse: updatedResponse,
formChangesHistory: [...get().formChangesHistory, formChanges]
Expand Down

0 comments on commit 44c4ab6

Please sign in to comment.