-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UIORGS-355 Display all versions in change log in fourth pane
- Loading branch information
1 parent
53cecbb
commit d467f8f
Showing
10 changed files
with
168 additions
and
0 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
107 changes: 107 additions & 0 deletions
107
src/Organizations/OrganizationVersion/OrganizationVersion.js
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,107 @@ | ||
import get from 'lodash/get'; | ||
import { | ||
memo, | ||
useCallback, | ||
} from 'react'; | ||
import ReactRouterPropTypes from 'react-router-prop-types'; | ||
|
||
import { | ||
useOrganization, | ||
VersionHistoryPane, | ||
VersionView, | ||
VersionViewContextProvider, | ||
} from '@folio/stripes-acq-components'; | ||
import { TitleManager } from '@folio/stripes/core'; | ||
|
||
import { | ||
ORGANIZATION_VERSIONS_VIEW_ROUTE, | ||
ORGANIZATIONS_ROUTE, | ||
VIEW_ORG_DETAILS, | ||
} from '../../common/constants'; | ||
import { HIDDEN_FIELDS_FOR_VERSION_HISTORY } from '../constants'; | ||
import { useOrganizationVersions } from './hooks'; | ||
|
||
const OrganizationVersion = ({ | ||
history, | ||
location, | ||
match, | ||
}) => { | ||
const { id: organizationId, versionId } = match.params; | ||
const snapshotPath = 'organizationSnapshot.map'; | ||
|
||
const { | ||
isLoading: isOrganizationLoading, | ||
organization, | ||
} = useOrganization(organizationId); | ||
|
||
const onHistoryClose = useCallback(() => history.push({ | ||
pathname: `${VIEW_ORG_DETAILS}${organizationId}`, | ||
search: location.search, | ||
}), [history, location.search, organizationId]); | ||
|
||
const onVersionClose = useCallback(() => history.push({ | ||
pathname: ORGANIZATIONS_ROUTE, | ||
search: location.search, | ||
}), [history, location.search]); | ||
|
||
const onSelectVersion = useCallback((_versionId) => { | ||
history.push({ | ||
pathname: `${ORGANIZATION_VERSIONS_VIEW_ROUTE}/${_versionId}`, | ||
search: location.search, | ||
}); | ||
}, [history, location.search]); | ||
|
||
const { | ||
versions, | ||
isLoading: isHistoryLoading, | ||
} = useOrganizationVersions(organizationId, { | ||
onSuccess: ({ organizationAuditEvents }) => { | ||
if (!versionId && organizationAuditEvents[0]?.id) onSelectVersion(organizationAuditEvents[0].id); | ||
}, | ||
}); | ||
|
||
const isVersionLoading = ( | ||
isOrganizationLoading || isHistoryLoading | ||
); | ||
|
||
return ( | ||
<VersionViewContextProvider | ||
snapshotPath={snapshotPath} | ||
versions={versions} | ||
versionId={versionId} | ||
> | ||
<TitleManager record={organization?.name} /> | ||
<VersionView | ||
id="organization" | ||
dismissible | ||
isLoading={isVersionLoading} | ||
onClose={onVersionClose} | ||
paneTitle={organization?.name} | ||
tags={get(organization, 'tags.tagList', [])} | ||
versionId={versionId} | ||
> | ||
{/* TODO: https://folio-org.atlassian.net/browse/UIORGS-356 */} | ||
</VersionView> | ||
|
||
<VersionHistoryPane | ||
currentVersion={versionId} | ||
id="organization" | ||
isLoading={isHistoryLoading} | ||
onClose={onHistoryClose} | ||
onSelectVersion={onSelectVersion} | ||
snapshotPath={snapshotPath} | ||
labelsMap={{}} | ||
versions={versions} | ||
hiddenFields={HIDDEN_FIELDS_FOR_VERSION_HISTORY} | ||
/> | ||
</VersionViewContextProvider> | ||
); | ||
}; | ||
|
||
OrganizationVersion.propTypes = { | ||
history: ReactRouterPropTypes.history, | ||
location: ReactRouterPropTypes.location, | ||
match: ReactRouterPropTypes.match, | ||
}; | ||
|
||
export default memo(OrganizationVersion); |
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 @@ | ||
export { useOrganizationVersions } from './useOrganizationVersions'; |
1 change: 1 addition & 0 deletions
1
src/Organizations/OrganizationVersion/hooks/useOrganizationVersions/index.js
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 @@ | ||
export { useOrganizationVersions } from './useOrganizationVersions'; |
34 changes: 34 additions & 0 deletions
34
...rganizations/OrganizationVersion/hooks/useOrganizationVersions/useOrganizationVersions.js
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,34 @@ | ||
import { useQuery } from 'react-query'; | ||
|
||
import { | ||
useNamespace, | ||
useOkapiKy, | ||
} from '@folio/stripes/core'; | ||
|
||
import { AUDIT_ACQ_EVENTS_API } from '@folio/stripes-acq-components'; | ||
|
||
const DEFAULT_DATA = []; | ||
|
||
export const useOrganizationVersions = (organizationId, options = {}) => { | ||
const ky = useOkapiKy(); | ||
const [namespace] = useNamespace({ key: 'organization-versions' }); | ||
|
||
const searchParams = { | ||
sortBy: 'event_date', | ||
sortOrder: 'desc', | ||
}; | ||
|
||
const { isLoading, data } = useQuery( | ||
[namespace, organizationId], | ||
({ signal }) => ky.get(`${AUDIT_ACQ_EVENTS_API}/organization/${organizationId}`, { signal, searchParams }).json(), | ||
{ | ||
enabled: Boolean(organizationId), | ||
...options, | ||
}, | ||
); | ||
|
||
return { | ||
isLoading, | ||
versions: data?.organizationAuditEvents || DEFAULT_DATA, | ||
}; | ||
}; |
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 @@ | ||
export { default as OrganizationVersion } from './OrganizationVersion'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const NOTES_ROUTE = '/organizations/notes'; | ||
export const ORGANIZATIONS_ROUTE = '/organizations'; | ||
export const VIEW_ORG_DETAILS = '/organizations/view/'; | ||
export const ORGANIZATION_VERSIONS_VIEW_ROUTE = `${VIEW_ORG_DETAILS}:id/versions`; |