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: soft deleted records are read only #8198

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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 @@ -36,6 +36,7 @@ export const useRecordBoardRecordGqlFields = ({

const recordGqlFields: Record<string, any> = {
id: true,
deletedAt: true,
...Object.fromEntries(
visibleFieldDefinitions.map((visibleFieldDefinition) => [
visibleFieldDefinition.metadata.fieldName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export const useRecordTableRecordGqlFields = ({

const recordGqlFields: Record<string, any> = {
id: true,
deletedAt: true,
...Object.fromEntries(
visibleTableColumns.map((column) => [column.metadata.fieldName, true]),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ export const FieldsCard = ({
objectNameSingular !== CoreObjectNameSingular.Task &&
fieldMetadataItem.name !== 'taskTargets',
);
const isReadOnly = objectMetadataItem.isRemote;
const isReadOnly =
objectMetadataItem.isRemote || isDefined(recordFromStore?.deletedAt);

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export const SummaryCard = ({

const { Icon, IconColor } = useGetStandardObjectIcon(objectNameSingular);
const isMobile = useIsMobile() || isInRightDrawer;
const isReadOnly = objectMetadataItem.isRemote;
const isReadOnly =
objectMetadataItem.isRemote || isDefined(recordFromStore?.deletedAt);

if (isNewRightDrawerItemLoading || !isDefined(recordFromStore)) {
return <ShowPageSummaryCardSkeletonLoader />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { css } from '@emotion/react';
import styled from '@emotion/styled';
import { motion } from 'framer-motion';
import { useCallback, useContext } from 'react';
import { useRecoilValue } from 'recoil';
import {
AnimatedEaseInOut,
IconChevronDown,
Expand Down Expand Up @@ -32,6 +33,7 @@ import { PropertyBox } from '@/object-record/record-inline-cell/property-box/com
import { InlineCellHotkeyScope } from '@/object-record/record-inline-cell/types/InlineCellHotkeyScope';
import { RecordDetailRecordsListItem } from '@/object-record/record-show/record-detail-section/components/RecordDetailRecordsListItem';
import { RecordValueSetterEffect } from '@/object-record/record-store/components/RecordValueSetterEffect';
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
import { ObjectRecord } from '@/object-record/types/ObjectRecord';
import { isFieldCellSupported } from '@/object-record/utils/isFieldCellSupported';
import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown';
Expand All @@ -40,6 +42,7 @@ import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown';
import { DropdownScope } from '@/ui/layout/dropdown/scopes/DropdownScope';
import { MenuItem } from '@/ui/navigation/menu-item/components/MenuItem';
import { RelationDefinitionType } from '~/generated-metadata/graphql';
import { isDefined } from '~/utils/isDefined';

const StyledListItem = styled(RecordDetailRecordsListItem)<{
isDropdownOpen?: boolean;
Expand Down Expand Up @@ -84,7 +87,7 @@ export const RecordDetailRelationRecordsListItem = ({
onClick,
relationRecord,
}: RecordDetailRelationRecordsListItemProps) => {
const { fieldDefinition } = useContext(FieldContext);
const { fieldDefinition, recordId } = useContext(FieldContext);

const {
relationFieldMetadataId,
Expand Down Expand Up @@ -181,7 +184,11 @@ export const RecordDetailRelationRecordsListItem = ({
[isExpanded],
);

const canEdit = !isFieldMetadataReadOnly(fieldDefinition.metadata);
const record = useRecoilValue(recordStoreFamilyState(recordId));

const canEdit =
!isFieldMetadataReadOnly(fieldDefinition.metadata) &&
!isDefined(record?.deletedAt);

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { FilterQueryParams } from '@/views/hooks/internal/useViewFromQueryParams
import { View } from '@/views/types/View';
import { ViewFilterOperand } from '@/views/types/ViewFilterOperand';
import { RelationDefinitionType } from '~/generated-metadata/graphql';
import { isDefined } from '~/utils/isDefined';

type RecordDetailRelationSectionProps = {
loading: boolean;
Expand Down Expand Up @@ -158,7 +159,9 @@ export const RecordDetailRelationSection = ({
recordId,
});

const canEdit = !isFieldMetadataReadOnly(fieldDefinition.metadata);
const canEdit =
!isFieldMetadataReadOnly(fieldDefinition.metadata) &&
!isDefined(record?.deletedAt);

if (loading) return null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ import { useTheme } from '@emotion/react';
import { Draggable } from '@hello-pangea/dnd';
import { ReactNode, useContext, useEffect } from 'react';
import { useInView } from 'react-intersection-observer';
import { useRecoilValue } from 'recoil';
import { useRecoilState, useRecoilValue } from 'recoil';

import { getBasePathToShowPage } from '@/object-metadata/utils/getBasePathToShowPage';
import { RecordIndexRootPropsContext } from '@/object-record/record-index/contexts/RecordIndexRootPropsContext';
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
import { RecordTableContext } from '@/object-record/record-table/contexts/RecordTableContext';
import { RecordTableRowContext } from '@/object-record/record-table/contexts/RecordTableRowContext';
import { useRecordTableStates } from '@/object-record/record-table/hooks/internal/useRecordTableStates';
import { RecordTableTr } from '@/object-record/record-table/record-table-row/components/RecordTableTr';
import { RecordTableWithWrappersScrollWrapperContext } from '@/ui/utilities/scroll/contexts/ScrollWrapperContexts';
import { isDefined } from '~/utils/isDefined';

export const RecordTableRowWrapper = ({
recordId,
Expand All @@ -35,6 +37,10 @@ export const RecordTableRowWrapper = ({
RecordTableWithWrappersScrollWrapperContext,
);

const [recordFromStore] = useRecoilState<any>(
recordStoreFamilyState(recordId),
);

const { ref: elementRef, inView } = useInView({
root: scrollWrapperRef.ref.current?.querySelector(
'[data-overlayscrollbars-viewport]',
Expand Down Expand Up @@ -82,7 +88,9 @@ export const RecordTableRowWrapper = ({
}) + recordId,
objectNameSingular: objectMetadataItem.nameSingular,
isSelected: currentRowSelected,
isReadOnly: objectMetadataItem.isRemote ?? false,
isReadOnly:
objectMetadataItem.isRemote ||
isDefined(recordFromStore?.deletedAt),
isPendingRow,
isDragging: draggableSnapshot.isDragging,
dragHandleProps: draggableProvided.dragHandleProps,
Expand Down
Loading