Skip to content

Commit

Permalink
feat: working trash filter button
Browse files Browse the repository at this point in the history
  • Loading branch information
magrinj committed Aug 12, 2024
1 parent 6a20b52 commit 1e2e094
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import { useGetCurrentView } from '@/views/hooks/useGetCurrentView';
import { ViewType } from '@/views/types/ViewType';
import { useLocation } from 'react-router-dom';
import { useSetRecoilState } from 'recoil';
import { useCombinedViewFilters } from '@/views/hooks/useCombinedViewFilters';
import { useHandleToggleTrashColumnFilter } from '@/object-record/record-index/hooks/useHandleToggleTrashColumnFilter';

type RecordIndexOptionsMenu = 'fields' | 'hiddenFields';
Expand All @@ -62,8 +61,6 @@ export const RecordIndexOptionsDropdownContent = ({
RecordIndexOptionsMenu | undefined
>(undefined);

const { upsertCombinedViewFilter } = useCombinedViewFilters();

const resetMenu = () => setCurrentMenu(undefined);

const handleSelectMenu = (option: RecordIndexOptionsMenu) => {
Expand Down Expand Up @@ -163,7 +160,10 @@ export const RecordIndexOptionsDropdownContent = ({
text={displayedExportProgress(progress)}
/>
<MenuItem
onClick={handleToggleTrashColumnFilter}
onClick={() => {
handleToggleTrashColumnFilter();
closeDropdown();
}}
LeftIcon={IconTrash}
text="Trash"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ export const VariantFilterChip = ({ viewFilter }: VariantFilterChipProps) => {
const { getIcon } = useIcons();

const handleRemoveClick = () => {
// FixMe: Why it's not working ?
removeCombinedViewFilter(viewFilter.fieldMetadataId);
removeCombinedViewFilter(viewFilter.id);
};

const variant = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,6 @@ export const ViewBarDetails = ({
return null;
}

console.log(
'currentViewWithCombinedFiltersAndSorts?.viewFilters: ',
currentViewWithCombinedFiltersAndSorts?.viewFilters,
);

return (
<StyledBar>
<StyledFilterContainer>
Expand All @@ -171,6 +166,7 @@ export const ViewBarDetails = ({
key={viewFilter.fieldMetadataId}
// Why do we have two types, Filter and ViewFilter?
// Why key defition is already present in the Filter type and added on the fly here with mapViewFiltersToFilters ?
// Also as filter is spread into viewFilter, definition is present
// FixMe: Ugly hack to make it work
viewFilter={viewFilter as unknown as Filter}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Injectable } from '@nestjs/common';
import { FieldMetadataInterface } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata.interface';

import { stringifyWithoutKeyQuote } from 'src/engine/api/graphql/workspace-query-builder/utils/stringify-without-key-quote.util';
import { isDefined } from 'src/utils/is-defined';

import { ArgsAliasFactory } from './args-alias.factory';

Expand All @@ -20,8 +21,9 @@ export class ArgsStringFactory {
}
if (softDeletable) {
initialArgs.filter = {
deletedAt: { is: 'NULL' },
...initialArgs.filter,
and: [initialArgs.filter, { deletedAt: { is: 'NULL' } }].filter(
isDefined,
),
};
}
let argsString = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ export class FieldsStringFactory {
): Promise<string> {
const selectedFields: Partial<Record> = graphqlFields(info);

console.log('selectedFields', JSON.stringify(selectedFields, null, 2));

const res = await this.createFieldsStringRecursive(
info,
selectedFields,
Expand All @@ -40,8 +38,6 @@ export class FieldsStringFactory {
withSoftDeleted ?? false,
);

console.log('res', res);

return res;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,6 @@ export class FindManyQueryFactory {
!options.withSoftDeleted && !!options.objectMetadataItem.isSoftDeletable,
);

console.log(
'argsString',
args,
argsString,
options.withSoftDeleted,
options.objectMetadataItem.isSoftDeletable,
);

return `
query {
${computeObjectTargetTable(options.objectMetadataItem)}Collection${
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,6 @@ export class RelationFieldAliasFactory {
) {
const args = getFieldArgumentsByKey(info, fieldKey);

// If the referenced object is soft deletable, we need to filter out the deleted objects
if (!withSoftDeleted && referencedObjectMetadata.isSoftDeletable) {
args.filter = {
deletedAt: { is: 'NULL' },
...args.filter,
};
}

const argsString = this.argsStringFactory.create(
args,
referencedObjectMetadata.fields ?? [],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { RecordFilter } from 'src/engine/api/graphql/workspace-query-builder/interfaces/record.interface';

import { isDefined } from 'src/utils/is-defined';

export const withSoftDeleted = <T extends RecordFilter>(
filter: T | undefined | null,
): boolean => {
if (!isDefined(filter)) {
return false;
}

if (Array.isArray(filter)) {
return filter.some((item) => withSoftDeleted(item));
}

for (const [key, value] of Object.entries(filter)) {
if (key === 'deletedAt') {
return true;
}

if (typeof value === 'object') {
return withSoftDeleted(value);
}
}

return false;
};
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.
import { computeObjectTargetTable } from 'src/engine/utils/compute-object-target-table.util';
import { isQueryTimeoutError } from 'src/engine/utils/query-timeout.util';
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
import { withSoftDeleted } from 'src/engine/api/graphql/workspace-query-runner/utils/with-soft-deleted.util';

import {
PGGraphQLMutation,
Expand Down Expand Up @@ -110,7 +111,7 @@ export class WorkspaceQueryRunnerService {
computedArgs,
{
...options,
withSoftDeleted: !!args.filter?.deletedAt,
withSoftDeleted: withSoftDeleted(args.filter),
},
);

Expand Down Expand Up @@ -164,7 +165,7 @@ export class WorkspaceQueryRunnerService {
computedArgs,
{
...options,
withSoftDeleted: !!args.filter?.deletedAt,
withSoftDeleted: withSoftDeleted(args.filter),
},
);

Expand Down

0 comments on commit 1e2e094

Please sign in to comment.