Skip to content

Commit

Permalink
Merge branch 'main' of github.com:twentyhq/twenty into search-at-work…
Browse files Browse the repository at this point in the history
…space-creation
  • Loading branch information
ijreilly committed Oct 7, 2024
2 parents e0f93f0 + 7bdbbcf commit 0515f62
Show file tree
Hide file tree
Showing 34 changed files with 467 additions and 117 deletions.
Original file line number Diff line number Diff line change
@@ -1,42 +1,25 @@
import { useFavorites } from '@/favorites/hooks/useFavorites';
import { useFilteredObjectMetadataItemsForWorkspaceFavorites } from '@/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites';
import { NavigationDrawerSectionForObjectMetadataItems } from '@/object-metadata/components/NavigationDrawerSectionForObjectMetadataItems';
import { NavigationDrawerSectionForObjectMetadataItemsSkeletonLoader } from '@/object-metadata/components/NavigationDrawerSectionForObjectMetadataItemsSkeletonLoader';
import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilteredObjectMetadataItems';
import { useIsPrefetchLoading } from '@/prefetch/hooks/useIsPrefetchLoading';
import { usePrefetchedData } from '@/prefetch/hooks/usePrefetchedData';
import { PrefetchKey } from '@/prefetch/types/PrefetchKey';
import { View } from '@/views/types/View';

export const WorkspaceFavorites = () => {
const { records: views } = usePrefetchedData<View>(PrefetchKey.AllViews);
const loading = useIsPrefetchLoading();

const { workspaceFavorites } = useFavorites();

const workspaceFavoriteIds = new Set(
workspaceFavorites.map((favorite) => favorite.recordId),
);

const favoriteViewObjectMetadataIds = views.reduce<string[]>((acc, view) => {
if (workspaceFavoriteIds.has(view.id)) {
acc.push(view.objectMetadataId);
}
return acc;
}, []);

const { objectMetadataItems } = useFilteredObjectMetadataItems();

const objectMetadataItemsToDisplay = objectMetadataItems.filter((item) =>
favoriteViewObjectMetadataIds.includes(item.id),
);
const { activeObjectMetadataItems: objectMetadataItemsToDisplay } =
useFilteredObjectMetadataItemsForWorkspaceFavorites();

const loading = useIsPrefetchLoading();
if (loading) {
return <NavigationDrawerSectionForObjectMetadataItemsSkeletonLoader />;
}

return (
<NavigationDrawerSectionForObjectMetadataItems
sectionTitle={'Workspace Favorites'}
sectionTitle={'Workspace'}
objectMetadataItems={objectMetadataItemsToDisplay}
views={views}
isRemote={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { IconSearch, IconSettings } from 'twenty-ui';
import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu';
import { CurrentWorkspaceMemberFavorites } from '@/favorites/components/CurrentWorkspaceMemberFavorites';
import { WorkspaceFavorites } from '@/favorites/components/WorkspaceFavorites';
import { NavigationDrawerOpenedSection } from '@/object-metadata/components/NavigationDrawerOpenedSection';
import { NavigationDrawerSectionForObjectMetadataItemsWrapper } from '@/object-metadata/components/NavigationDrawerSectionForObjectMetadataItemsWrapper';
import { NavigationDrawerItem } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerItem';
import { NavigationDrawerSection } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerSection';
Expand Down Expand Up @@ -44,6 +45,8 @@ export const MainNavigationDrawerItems = () => {
</NavigationDrawerSection>
)}

{isWorkspaceFavoriteEnabled && <NavigationDrawerOpenedSection />}

<CurrentWorkspaceMemberFavorites />

{isWorkspaceFavoriteEnabled ? (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { useFavorites } from '@/favorites/hooks/useFavorites';
import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilteredObjectMetadataItems';
import { usePrefetchedData } from '@/prefetch/hooks/usePrefetchedData';
import { PrefetchKey } from '@/prefetch/types/PrefetchKey';
import { View } from '@/views/types/View';

export const useFilteredObjectMetadataItemsForWorkspaceFavorites = () => {
const { records: views } = usePrefetchedData<View>(PrefetchKey.AllViews);

const { workspaceFavorites } = useFavorites();

const workspaceFavoriteIds = new Set(
workspaceFavorites.map((favorite) => favorite.recordId),
);

const favoriteViewObjectMetadataIds = new Set(
views.reduce<string[]>((acc, view) => {
if (workspaceFavoriteIds.has(view.id)) {
acc.push(view.objectMetadataId);
}
return acc;
}, []),
);

const { activeObjectMetadataItems } = useFilteredObjectMetadataItems();

const activeObjectMetadataItemsInWorkspaceFavorites =
activeObjectMetadataItems.filter((item) =>
favoriteViewObjectMetadataIds.has(item.id),
);

return {
activeObjectMetadataItems: activeObjectMetadataItemsInWorkspaceFavorites,
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { useParams } from 'react-router-dom';

import { useFilteredObjectMetadataItemsForWorkspaceFavorites } from '@/navigation/hooks/useObjectMetadataItemsInWorkspaceFavorites';
import { NavigationDrawerSectionForObjectMetadataItems } from '@/object-metadata/components/NavigationDrawerSectionForObjectMetadataItems';
import { NavigationDrawerSectionForObjectMetadataItemsSkeletonLoader } from '@/object-metadata/components/NavigationDrawerSectionForObjectMetadataItemsSkeletonLoader';
import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilteredObjectMetadataItems';
import { useIsPrefetchLoading } from '@/prefetch/hooks/useIsPrefetchLoading';
import { usePrefetchedData } from '@/prefetch/hooks/usePrefetchedData';
import { PrefetchKey } from '@/prefetch/types/PrefetchKey';
import { View } from '@/views/types/View';

export const NavigationDrawerOpenedSection = () => {
const { activeObjectMetadataItems } = useFilteredObjectMetadataItems();
const filteredActiveObjectMetadataItems = activeObjectMetadataItems.filter(
(item) => !item.isRemote,
);

const { records: views } = usePrefetchedData<View>(PrefetchKey.AllViews);
const loading = useIsPrefetchLoading();

const currentObjectNamePlural = useParams().objectNamePlural;

const { activeObjectMetadataItems: workspaceFavoritesObjectMetadataItems } =
useFilteredObjectMetadataItemsForWorkspaceFavorites();

if (!currentObjectNamePlural) {
return;
}

const objectMetadataItem = filteredActiveObjectMetadataItems.find(
(item) => item.namePlural === currentObjectNamePlural,
);

if (!objectMetadataItem) {
return;
}

const shouldDisplayObjectInOpenedSection =
!workspaceFavoritesObjectMetadataItems
.map((item) => item.id)
.includes(objectMetadataItem.id);

if (loading) {
return <NavigationDrawerSectionForObjectMetadataItemsSkeletonLoader />;
}

return (
shouldDisplayObjectInOpenedSection && (
<NavigationDrawerSectionForObjectMetadataItems
sectionTitle={'Opened'}
objectMetadataItems={[objectMetadataItem]}
views={views}
isRemote={false}
/>
)
);
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import styled from '@emotion/styled';
import { DropResult } from '@hello-pangea/dnd';
import { useState } from 'react';
import { Controller, useFormContext } from 'react-hook-form';
import { IconPlus } from 'twenty-ui';
import { z } from 'zod';
Expand Down Expand Up @@ -79,7 +78,6 @@ const StyledButton = styled(LightButton)`
export const SettingsDataModelFieldSelectForm = ({
fieldMetadataItem,
}: SettingsDataModelFieldSelectFormProps) => {
const [focusedOptionId, setFocusedOptionId] = useState('');
const { initialDefaultValue, initialOptions } =
useSelectSettingsFormInitialValues({ fieldMetadataItem });

Expand Down Expand Up @@ -190,10 +188,6 @@ export const SettingsDataModelFieldSelectForm = ({
const newOptions = getOptionsWithNewOption();

setFormValue('options', newOptions);

const lastOptionId = newOptions[newOptions.length - 1].id;

setFocusedOptionId(lastOptionId);
};

return (
Expand Down Expand Up @@ -227,7 +221,7 @@ export const SettingsDataModelFieldSelectForm = ({
<SettingsDataModelFieldSelectFormOptionRow
key={option.id}
option={option}
focused={focusedOptionId === option.id}
isNewRow={index === options.length - 1}
onChange={(nextOption) => {
const nextOptions = toSpliced(
options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type SettingsDataModelFieldSelectFormOptionRowProps = {
onRemoveAsDefault?: () => void;
onInputEnter?: () => void;
option: FieldMetadataItemOption;
focused?: boolean;
isNewRow?: boolean;
};

const StyledRow = styled.div`
Expand Down Expand Up @@ -67,7 +67,7 @@ export const SettingsDataModelFieldSelectFormOptionRow = ({
onRemoveAsDefault,
onInputEnter,
option,
focused,
isNewRow,
}: SettingsDataModelFieldSelectFormOptionRowProps) => {
const theme = useTheme();

Expand Down Expand Up @@ -129,10 +129,11 @@ export const SettingsDataModelFieldSelectFormOptionRow = ({
value: getOptionValueFromLabel(label),
})
}
focused={focused}
RightIcon={isDefault ? IconCheck : undefined}
maxLength={OPTION_VALUE_MAXIMUM_LENGTH}
onInputEnter={handleInputEnter}
autoFocusOnMount={isNewRow}
autoSelectOnMount={isNewRow}
/>
<Dropdown
dropdownId={dropdownIds.actions}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { H2Title } from 'twenty-ui';
import { Section } from '@/ui/layout/section/components/Section';
import { TextInput } from '@/ui/input/components/TextInput';
import { ServerlessFunctionNewFormValues } from '@/settings/serverless-functions/hooks/useServerlessFunctionUpdateFormState';
import { TextArea } from '@/ui/input/components/TextArea';
import { TextInput } from '@/ui/input/components/TextInput';
import { Section } from '@/ui/layout/section/components/Section';
import styled from '@emotion/styled';
import { ServerlessFunctionNewFormValues } from '@/settings/serverless-functions/hooks/useServerlessFunctionUpdateFormState';
import { H2Title } from 'twenty-ui';

const StyledInputsContainer = styled.div`
display: flex;
Expand All @@ -25,7 +25,7 @@ export const SettingsServerlessFunctionNewForm = ({
<TextInput
placeholder="Name"
fullWidth
focused
autoFocusOnMount
value={formValues.name}
onChange={onChange('name')}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { FieldCurrencyValue } from '@/object-record/record-field/types/FieldMeta
import { SETTINGS_FIELD_CURRENCY_CODES } from '@/settings/data-model/constants/SettingsFieldCurrencyCodes';
import { formatAmount } from '~/utils/format/formatAmount';
import { isDefined } from '~/utils/isDefined';
import { isUndefinedOrNull } from '~/utils/isUndefinedOrNull';

type CurrencyDisplayProps = {
currencyValue: FieldCurrencyValue | null | undefined;
Expand All @@ -29,10 +30,9 @@ export const CurrencyDisplay = ({ currencyValue }: CurrencyDisplayProps) => {
? SETTINGS_FIELD_CURRENCY_CODES[currencyValue?.currencyCode]?.Icon
: null;

const amountToDisplay =
currencyValue?.amountMicros != null
? currencyValue?.amountMicros / 1000000
: null;
const amountToDisplay = isUndefinedOrNull(currencyValue?.amountMicros)
? null
: currencyValue?.amountMicros / 1000000;

if (!shouldDisplayCurrency) {
return <StyledEllipsisDisplay>{0}</StyledEllipsisDisplay>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export const CurrencyInput = ({
placeholder={placeholder}
autoFocus={autoFocus}
value={value}
unmask
/>
</StyledContainer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,17 @@ export type TextInputProps = TextInputV2ComponentProps & {
disableHotkeys?: boolean;
onInputEnter?: () => void;
dataTestId?: string;
focused?: boolean;
autoFocusOnMount?: boolean;
autoSelectOnMount?: boolean;
};

export const TextInput = ({
onFocus,
onBlur,
onInputEnter,
disableHotkeys = false,
focused,
autoFocusOnMount,
autoSelectOnMount,
dataTestId,
...props
}: TextInputProps) => {
Expand All @@ -31,11 +33,17 @@ export const TextInput = ({
const [isFocused, setIsFocused] = useState(false);

useEffect(() => {
if (focused === true) {
if (autoFocusOnMount === true) {
inputRef.current?.focus();
setIsFocused(true);
}
}, [focused]);
}, [autoFocusOnMount]);

useEffect(() => {
if (autoSelectOnMount === true) {
inputRef.current?.select();
}
}, [autoSelectOnMount]);

const {
goBackToPreviousHotkeyScope,
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { DataSourceService } from 'src/engine/metadata-modules/data-source/data-
import { FieldMetadataService } from 'src/engine/metadata-modules/field-metadata/field-metadata.service';
import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity';
import { ObjectMetadataService } from 'src/engine/metadata-modules/object-metadata/object-metadata.service';
import { shouldSeedWorkspaceFavorite } from 'src/engine/utils/should-seed-workspace-favorite';
import { WorkspaceDataSourceService } from 'src/engine/workspace-datasource/workspace-datasource.service';
import { viewPrefillData } from 'src/engine/workspace-manager/standard-objects-prefill-data/view';
import { STANDARD_OBJECT_IDS } from 'src/engine/workspace-manager/workspace-sync-metadata/constants/standard-object-ids';
Expand Down Expand Up @@ -219,7 +220,14 @@ export class DataSeedWorkspaceCommand extends CommandRunner {

await seedWorkspaceFavorites(
viewDefinitionsWithId
.filter((view) => view.key === 'INDEX')
.filter(
(view) =>
view.key === 'INDEX' &&
shouldSeedWorkspaceFavorite(
view.objectMetadataId,
objectMetadataMap,
),
)
.map((view) => view.id),
entityManager,
dataSourceMetadata.schema,
Expand Down
Loading

0 comments on commit 0515f62

Please sign in to comment.