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

fix: shareview should not set search index relative #1266

Merged
merged 1 commit into from
Jan 22, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const SearchButton = (props: ISearchButtonProps) => {
const { data: tableActivatedIndex } = useQuery({
queryKey: ['table-index', tableId],
queryFn: () => getTableActivatedIndex(baseId!, tableId!).then(({ data }) => data),
enabled: !shareView,
});

useHotkeys(
Expand Down Expand Up @@ -279,6 +280,7 @@ export const SearchButton = (props: ISearchButtonProps) => {
value={fieldId}
hideNotMatchRow={hideNotMatchRow}
onChange={onFieldChangeHandler}
shareView={shareView}
ref={searchCommandRef}
onHideSwitchChange={(checked) => {
setLsHideNotMatchRow(checked);
Expand Down Expand Up @@ -310,6 +312,7 @@ export const SearchButton = (props: ISearchButtonProps) => {
rowCount &&
rowCount > RecommendedIndexRow &&
shouldAlert &&
!shareView &&
!tableActivatedIndex?.includes(TableIndex.search) &&
e.target.value
) {
Expand Down
134 changes: 69 additions & 65 deletions apps/nextjs-app/src/features/app/blocks/view/search/SearchCommand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ interface ISearchCommand {
hideNotMatchRow?: boolean;
onHideSwitchChange: (hideNotMatchRow?: boolean) => void;
onChange: (fieldIds: string[] | null) => void;
shareView?: boolean;
}

export interface ISearchCommandRef {
Expand All @@ -57,7 +58,7 @@ enum ActionType {
}

export const SearchCommand = forwardRef<ISearchCommandRef, ISearchCommand>((props, ref) => {
const { onChange, value, hideNotMatchRow, onHideSwitchChange } = props;
const { onChange, value, hideNotMatchRow, onHideSwitchChange, shareView } = props;
const { t } = useTranslation(['common', 'table']);
const fields = useFields();
const view = useView();
Expand Down Expand Up @@ -85,6 +86,7 @@ export const SearchCommand = forwardRef<ISearchCommandRef, ISearchCommand>((prop
const { data: tableActivatedIndex } = useQuery({
queryKey: ['table-index', tableId],
queryFn: () => getTableActivatedIndex(baseId!, tableId!).then(({ data }) => data),
enabled: !shareView,
});

const enabledSearchIndex = tableActivatedIndex?.includes(TableIndex.search);
Expand All @@ -93,7 +95,7 @@ export const SearchCommand = forwardRef<ISearchCommandRef, ISearchCommand>((prop
queryKey: ['table-abnormal-index', baseId, tableId, TableIndex.search],
queryFn: () =>
getTableAbnormalIndex(baseId!, tableId!, TableIndex.search).then(({ data }) => data),
enabled: enabledSearchIndex,
enabled: Boolean(enabledSearchIndex && !shareView),
});

const { mutateAsync: toggleIndexFn, isLoading } = useMutation({
Expand Down Expand Up @@ -277,80 +279,82 @@ export const SearchCommand = forwardRef<ISearchCommandRef, ISearchCommand>((prop
)}
</div>

<div className="flex items-center justify-between pl-1">
<div className="flex flex-1 items-center gap-1">
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<div className="flex items-center gap-0.5 text-sm">
{t('actions.tableIndex')}
<HelpCircle />
</div>
</TooltipTrigger>
<TooltipContent className="max-w-80 text-wrap break-words" sideOffset={5}>
{t('table:table.index.description', { rowCount: RecommendedIndexRow })}
</TooltipContent>
</Tooltip>
</TooltipProvider>
{enabledSearchIndex && !!searchAbnormalIndex?.length && (
{!shareView && (
<div className="flex items-center justify-between pl-1">
<div className="flex flex-1 items-center gap-1">
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<div className="flex items-center gap-0.5">
<Button
size={'xs'}
variant={'destructive'}
className="flex h-6 items-center gap-0.5"
onClick={async () => {
if (shouldAlert) {
setAlertVisible(true);
setActionType(ActionType.repair);
return;
}
await repairIndexFn(TableIndex.search);
}}
>
{t('table:table.index.repair')}
{repairIndexLoading || getAbnormalLoading ? (
<Spin className="size-3" />
) : null}
</Button>
<div className="flex items-center gap-0.5 text-sm">
{t('actions.tableIndex')}
<HelpCircle />
</div>
</TooltipTrigger>
<TooltipContent className="text-wrap break-words" sideOffset={5}>
{t('table:table.index.repairTip')}
<TooltipContent className="max-w-80 text-wrap break-words" sideOffset={5}>
{t('table:table.index.description', { rowCount: RecommendedIndexRow })}
</TooltipContent>
</Tooltip>
</TooltipProvider>
)}
</div>
{enabledSearchIndex && !!searchAbnormalIndex?.length && (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<div className="flex items-center gap-0.5">
<Button
size={'xs'}
variant={'destructive'}
className="flex h-6 items-center gap-0.5"
onClick={async () => {
if (shouldAlert) {
setAlertVisible(true);
setActionType(ActionType.repair);
return;
}
await repairIndexFn(TableIndex.search);
}}
>
{t('table:table.index.repair')}
{repairIndexLoading || getAbnormalLoading ? (
<Spin className="size-3" />
) : null}
</Button>
</div>
</TooltipTrigger>
<TooltipContent className="text-wrap break-words" sideOffset={5}>
{t('table:table.index.repairTip')}
</TooltipContent>
</Tooltip>
</TooltipProvider>
)}
</div>

<div>
<Label
htmlFor={'search-index'}
className="flex flex-1 cursor-pointer items-center justify-between truncate p-2"
>
<div className="flex h-7 items-center gap-1">
<div className="flex items-center gap-1">
{isLoading ? <Spin className="size-3" /> : null}
<Switch
id={'search-index'}
className="scale-75"
checked={enabledSearchIndex}
onCheckedChange={async (val) => {
if (val && shouldAlert) {
setAlertVisible(true);
setActionType(ActionType.create);
return;
}
baseId && tableId && (await toggleIndexFn(TableIndex.search));
}}
/>
<div>
<Label
htmlFor={'search-index'}
className="flex flex-1 cursor-pointer items-center justify-between truncate p-2"
>
<div className="flex h-7 items-center gap-1">
<div className="flex items-center gap-1">
{isLoading ? <Spin className="size-3" /> : null}
<Switch
id={'search-index'}
className="scale-75"
checked={enabledSearchIndex}
onCheckedChange={async (val) => {
if (val && shouldAlert) {
setAlertVisible(true);
setActionType(ActionType.create);
return;
}
baseId && tableId && (await toggleIndexFn(TableIndex.search));
}}
/>
</div>
</div>
</div>
</Label>
</Label>
</div>
</div>
</div>
)}

<AlertDialog open={alertVisible} onOpenChange={setAlertVisible}>
<AlertDialogContent>
Expand Down
Loading