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

feat: [Registry] Better search #21

Merged
merged 39 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
edc4c63
init
mohandast52 Apr 1, 2024
748a72d
remove goerli
mohandast52 Apr 2, 2024
23a540b
add grapql package
mohandast52 Apr 2, 2024
8bdb0e7
add useSubgraph
mohandast52 Apr 2, 2024
edad7fb
useListAllUnits
mohandast52 Apr 2, 2024
bd906d6
update query
mohandast52 Apr 2, 2024
f258525
update ListComponents
mohandast52 Apr 2, 2024
54f270f
update hooks for search, middleware update, table column fix
mohandast52 Apr 2, 2024
ba61937
listAgents
mohandast52 Apr 2, 2024
e406c38
update for service
mohandast52 Apr 3, 2024
e85fdce
update service list
mohandast52 Apr 3, 2024
6428372
add extra column and update Search button
mohandast52 Apr 3, 2024
b9a6cd4
agent list and search
mohandast52 Apr 3, 2024
aaed88b
agent fixes
mohandast52 Apr 3, 2024
7c7dd19
agent fixes
mohandast52 Apr 3, 2024
0b9d063
update serviceList (move to hooks folder, etc)
mohandast52 Apr 3, 2024
0606d06
bring back goerli
mohandast52 Apr 3, 2024
e02f353
build fix
mohandast52 Apr 4, 2024
2db3081
minor changes
mohandast52 Apr 4, 2024
acd60d2
column updates
mohandast52 Apr 4, 2024
577625a
test updates
mohandast52 Apr 5, 2024
ba86580
test-case fixes
mohandast52 Apr 5, 2024
32483c9
tiny
mohandast52 Apr 5, 2024
8b0a5e1
fixes for service
mohandast52 Apr 6, 2024
b510443
comment out services changes
mohandast52 Apr 6, 2024
daf79fe
add condition for mainnet in useHelpers
mohandast52 Apr 8, 2024
fa96df5
address Oak's comment
mohandast52 Apr 8, 2024
2414555
fixes
mohandast52 Apr 8, 2024
73d7f2a
add custom for agents
mohandast52 Apr 8, 2024
cdf9285
fix tests
mohandast52 Apr 8, 2024
04f10f5
services fix
mohandast52 Apr 8, 2024
9d6e29d
on input search and hide description for service
mohandast52 Apr 8, 2024
811c459
address some comments
mohandast52 Apr 9, 2024
4069101
address few comments
mohandast52 Apr 9, 2024
555f06b
address review comments
mohandast52 Apr 9, 2024
ffb02ce
address comments
mohandast52 Apr 10, 2024
49b8912
move to ts
mohandast52 Apr 10, 2024
05b8cc1
other changes
mohandast52 Apr 10, 2024
f15d10a
test-cases asycn
mohandast52 Apr 10, 2024
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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ NEXT_PUBLIC_ARBITRUM_URL=__value__
NEXT_PUBLIC_ARBITRUM_SEPOLIA_URL=__value__
NEXT_PUBLIC_WALLET_PROJECT_ID=__URL__
NEXT_PUBLIC_SOLANA_MAINNET_BETA_URL=__value__
NEXT_PUBLIC_AUTONOLAS_SUB_GRAPH_URL=__URL__

# autonolas-registry-frontend
NEXT_PUBLIC_REGISTRY_URL=__value__
Expand Down
39 changes: 22 additions & 17 deletions apps/autonolas-registry/common-util/Details/index.jsx
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a component with a single export, please move to components folder and name Details.jsx

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently used by agents, components, and services, so I've kept it in the common-utils. Any reason to move it to components folder instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, so...

the components folder is for reusable components i.e. this Details component, used by multiple others

the pages folder should be reserved for specific pages that pull in reusable components to create the expected page

the common-utils or utils folders should be for helper functions, i.e. string parsers, converters, object manipulation .etc, perhaps constants, though I tend to put it outside of utils folder to seperate concerns

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your point, but my approach differs slightly:

  • page simply imports the core components. I believe if we start adding the core components here, it will become too large to maintain, especially since they tend to grow in size.
  • components is for core components such as Agents, Services, etc.
  • common-util is intended for common components that can be used by other core components. For example components that can be used in Agents, Services, etc
  • utils is reserved for constants, but we could potentially move it to common-util.

I think eventually, the truly reusable components will be moved to feature libraries in NX, such as the login component, utility functions, etc.

Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import { useState, useCallback } from 'react';
import PropTypes from 'prop-types';
import capitalize from 'lodash/capitalize';
import {
Row, Col, Button, Typography,
} from 'antd';
import { Row, Col, Button, Typography } from 'antd';
import { get } from 'lodash';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import { get } from 'lodash';
import get from 'lodash/get';

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, sure. Does it add any improvements?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, there's a small difference
image

using this plugin: https://marketplace.visualstudio.com/items?itemName=ambar.bundle-size

not 100% sure if it's accurate post-build, but if it is then we should consider reducing where we can

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh, nice!

import { Loader, NA } from '@autonolas/frontend-library';

import { NAV_TYPES } from '../../util/constants';
import { useMetadata } from '../hooks/useMetadata';
import { useHelpers } from '../hooks';
import { typePropType } from '../propTypes';
import { IpfsHashGenerationModal } from '../List/IpfsHashGenerationModal';
import { useDetails } from './useDetails';
Expand All @@ -31,16 +30,16 @@ export const Details = ({
}) => {
const [isModalVisible, setIsModalVisible] = useState(false);

const {
isLoading, isOwner, info, ownerAddress, tokenUri, updateDetails,
} = useDetails({
id,
type,
getDetails,
getOwner,
getTokenUri,
});
const { nftImageUrl } = useMetadata(tokenUri);
const { isMainnet } = useHelpers();
const { isLoading, isOwner, info, ownerAddress, tokenUri, updateDetails } =
useDetails({
id,
type,
getDetails,
getOwner,
getTokenUri,
});
const { nftImageUrl, packageName } = useMetadata(tokenUri);

// Update button to be show only if the connected account is the owner
// and only for agent and component
Expand All @@ -58,10 +57,16 @@ export const Details = ({
<>
<Header>
<div>
<Text strong>{`${capitalize(type)} Name`}</Text>
<DetailsTitle level={2}>
{`${capitalize(type)} ID ${id}`}
</DetailsTitle>
{isMainnet ? (
<DetailsTitle level={3}>{packageName}</DetailsTitle>
) : (
<>
<Text strong>{`${capitalize(type)} Name`}</Text>
<DetailsTitle level={2}>
{`${capitalize(type)} ID ${id}`}
</DetailsTitle>
</>
)}
</div>

<div className="right-content">
Expand Down
120 changes: 120 additions & 0 deletions apps/autonolas-registry/common-util/List/ListTable/ListTable.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import PropTypes from 'prop-types';
import { Table } from 'antd';
import { Loader, useScreen } from '@autonolas/frontend-library';

import { TOTAL_VIEW_COUNT } from '../../../util/constants';
import { ListEmptyMessage } from '../ListCommon';
import { useHelpers } from '../../hooks';
import { convertTableRawData, getTableColumns } from './helpers';

export const ListTable = ({
isLoading,
type,
searchValue,
isPaginationRequired,
list,
total,
currentPage,
setCurrentPage,
isAccountRequired,
onViewClick,
onUpdateClick,
extra,
tableDataTestId,
}) => {
const { chainName, account, isSvm, chainId, isMainnet } = useHelpers();

/**
* no pagination on search as we won't know total beforehand
*/
const canShowPagination = isPaginationRequired ? !searchValue : false;
const { isMobile } = useScreen();

const { scrollX } = extra;

if (isLoading) {
if (isSvm) {
return <Loader />;
}

return (
<Loader
isAccountRequired={isAccountRequired}
account={account}
notConnectedMessage={`To see your ${type}s, connect wallet.`}
/>
);
}

const columns = getTableColumns(type, {
onViewClick,
onUpdateClick,
isMobile,
chainName,
chainId,
account,
isMainnet,
});
const dataSource = convertTableRawData(type, list, {
currentPage,
isMainnet,
});
const pagination = {
total,
current: currentPage,
defaultPageSize: canShowPagination ? TOTAL_VIEW_COUNT : total,
onChange: (e) => setCurrentPage(e),
showSizeChanger: false,
};

return (
<>
{list.length === 0 ? (
<ListEmptyMessage
type={type}
message={isSvm ? 'No services – do you have SOL in your wallet?' : ''}
/>
) : (
<Table
columns={columns}
dataSource={dataSource}
pagination={canShowPagination ? pagination : false}
scroll={{ x: scrollX }}
rowKey={(record) => `${type}-row-${record.id}`}
data-testid={tableDataTestId || `${type}-table`}
/>
)}
</>
);
};

ListTable.propTypes = {
type: PropTypes.string.isRequired,
searchValue: PropTypes.string.isRequired,
isPaginationRequired: PropTypes.bool,
isLoading: PropTypes.bool,
list: PropTypes.arrayOf(PropTypes.object),
total: PropTypes.number,
currentPage: PropTypes.number,
setCurrentPage: PropTypes.func,
isAccountRequired: PropTypes.bool,
onViewClick: PropTypes.func,
onUpdateClick: PropTypes.func,
tableDataTestId: PropTypes.string,
extra: PropTypes.shape({
scrollX: PropTypes.number,
}),
};

ListTable.defaultProps = {
isLoading: false,
isPaginationRequired: true,
list: [],
total: 0,
currentPage: 0,
setCurrentPage: () => {},
isAccountRequired: false,
onViewClick: () => {},
onUpdateClick: null,
extra: { scrollX: 1200 },
};
Loading
Loading