Skip to content

Commit

Permalink
fix(console): support fuzzy search (#2221)
Browse files Browse the repository at this point in the history
* fix(console): support fuzzy search

* fix(console): encodeURIComponent is wrong
  • Loading branch information
jo-hnny authored Jan 5, 2023
1 parent d43e460 commit 10c8b2c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 35 deletions.
1 change: 1 addition & 0 deletions web/console/helpers/urlUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export const reduceK8sQueryString = ({
restfulPath?: string;
}) => {
const queryString = Object.entries(k8sQueryObj)
.filter(([_, value]) => value !== undefined)
.map(([key, value]) => {
// 也许value是object,即labelSelector 或者 fieldSelector
value = isObject(value)
Expand Down
51 changes: 18 additions & 33 deletions web/console/src/modules/cluster/WebAPI/K8sResourceAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,42 +201,27 @@ export async function fetchResourceList(

// 如果是主动清空 或者 resourceInfo 为空,都不需要发请求
if (!isClearData && !isEmpty(resourceInfo)) {
let k8sUrl = '';
let k8sUrl = reduceK8sRestfulPath({
resourceInfo,
namespace,
specificName: isNeedSpecific ? specificName : '',
clusterId,
meshId,
extraResource
});
// 如果有搜索字段的话
if (search) {
k8sUrl = reduceK8sRestfulPath({
resourceInfo,
namespace,
specificName: isNeedSpecific ? search : '',
clusterId,
meshId,
extraResource
});
} else {
k8sUrl = reduceK8sRestfulPath({
resourceInfo,
namespace,
specificName: isNeedSpecific ? specificName : '',
clusterId,
meshId,
extraResource
});
}

// 这里是去拼接,是否需要在k8s url后面拼接一些queryString
if (isContinue && !search) {
if (isContinue) {
const { pageSize } = paging;
k8sQueryObj = JSON.parse(
JSON.stringify(
Object.assign(
{
limit: pageSize,
continue: continueToken ? continueToken : undefined,
labelSelector
},
k8sQueryObj
)
)

k8sQueryObj = Object.assign(
{
limit: pageSize,
continue: continueToken ? continueToken : undefined,
labelSelector,
fieldSelector: search ? `metadata.name=${search}` : undefined
},
k8sQueryObj
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,6 @@ export class ResourceActionPanel extends React.Component<RootProps, ResouceActio
searchBoxLength: finalTags.length
});

if (finalTags.length <= 0) return;

const { actions } = this.props;

// 这里是控制tagSearch的展示
Expand Down

0 comments on commit 10c8b2c

Please sign in to comment.