Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

table: improving related resources pagination and related packages links #111

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@geo-knowledge-hub/geo-components-react",
"version": "0.5.2",
"version": "0.5.3",
"main": "dist/cjs/index.js",
"browser": "dist/cjs/index.js",
"module": "dist/esm/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React, { useMemo } from 'react';
import { PaginableTable } from '../../moldure';

import _get from 'lodash/get';
import _head from 'lodash/head';
import _last from 'lodash/last';
import _isNil from 'lodash/isNil';
import _sortBy from 'lodash/sortBy';
import _groupBy from 'lodash/groupBy';
Expand Down Expand Up @@ -54,8 +54,8 @@ export const RelatedPackagesTable = ({ tableData }) => {
};
});

// Getting the title from the first version
const rowFirstVersion = _head(_sortBy(rowVersions));
// Getting the title from the latest version
const rowLastVersion = _last(_sortBy(rowVersions));

return (
<Grid>
Expand All @@ -76,7 +76,9 @@ export const RelatedPackagesTable = ({ tableData }) => {
mobile={14}
tablet={11}
>
<p>{rowFirstVersion.title}</p>
<a href={rowLastVersion.url}>
{rowLastVersion.title}
</a>
</Grid.Column>
<Grid.Column
widescreen={4}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,18 @@ const SEARCH_OPTIONS = {
*/
export const RelatedResourceTable = ({
records,
packageId,
resourceTypeDefinitions,
paginationSizes,
transitionProps,
}) => {
// default config
const defaultPageSize = paginationSizes[0];

// search state
const [paginationConfig, setPaginationConfig] = useState({
currentPage: 1,
pageSize: 3,
pageSize: defaultPageSize,
});
const [searchBarContent, setSearchBarContent] = useState('');
const [activeResourceType, setActiveResourceType] = useState(null);
Expand Down Expand Up @@ -127,6 +131,9 @@ export const RelatedResourceTable = ({
records: {
data: records,
},
package: {
id: packageId
}
}}
>
<TypeSelectorCard />
Expand Down Expand Up @@ -175,11 +182,13 @@ export const RelatedResourceTable = ({

RelatedResourceTable.propTypes = {
records: PropTypes.array.isRequired,
paginationSizes: PropTypes.array,
packageId: PropTypes.string.isRequired,
paginationSizes: PropTypes.array.isRequired,
transitionProps: PropTypes.object,
};

RelatedResourceTable.defaultProps = {
packageId: "#",
paginationSizes: [3, 5, 10, 15, 50, 100],
transitionProps: {
type: 'fade down',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ export const RecordList = () => {
const indexContext = useContext(IndexContext);

const records = indexContext.searchContext.index.results;
const packageId = indexContext.package.id;

return (
<>
{records.length > 0 ? (
<Segment attached="bottom">
<Item.Group divided>
{records.map((record) => (
<RecordListItem key={record.id} recordData={record} />
<RecordListItem key={record.id} recordData={record} packageId={packageId} />
))}
</Item.Group>
</Segment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ describe('RecordList tests', () => {
results: relatedRecordsData,
},
},
package: {
id: "#"
}
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import './RecordListItem.css';
/**
* Record Item component for the Record List
*/
export const RecordListItem = ({ recordData }) => {
export const RecordListItem = ({ recordData, packageId }) => {
// extracting the informations
const creators = _get(recordData, 'ui.creators.creators', null);
const publicationDate = _get(
Expand Down Expand Up @@ -45,10 +45,10 @@ export const RecordListItem = ({ recordData }) => {
const recordId = _get(recordData, 'id', null);
const recordUrlPrefix = isPackage ? 'packages' : 'records';

let recordUrl = `/${recordUrlPrefix}/${recordId}`;
let recordUrl = `/${recordUrlPrefix}/${recordId}?package=${packageId}`;

if (isDraft) {
recordUrl = `${recordUrl}?preview=1&navigate=1`;
recordUrl = `${recordUrl}&preview=1&navigate=1`;
}

const accessStatusID = _get(recordData, 'ui.access_status.id', null);
Expand Down