Skip to content

Commit

Permalink
Add all create/edit/delete fonctionality to the lists and to the list…
Browse files Browse the repository at this point in the history
… value with the new design (#56)
  • Loading branch information
balzdur authored Jul 17, 2023
2 parents 1e0a6f3 + 7c4a70b commit d7fc246
Show file tree
Hide file tree
Showing 39 changed files with 989 additions and 255 deletions.
3 changes: 3 additions & 0 deletions packages/app-builder/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"search": "Search",
"errors.unknown": "An unknown error as occured",
"errors.edit.forbidden_not_draft": "You can only edit a draft version of a scenario.",
"errors.list.duplicate_list_name": "A list with this name already exist",
"cancel": "Cancel",
"save": "Save",
"delete": "Delete",
"close": "Close",
"clipboard.copy": "Copied in clipboard: {{value}}",
"empty_scenario_iteration_list": "Reach out to Marble to create your first scenario draft."
Expand Down
19 changes: 17 additions & 2 deletions packages/app-builder/public/locales/en/lists.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
{
"name": "Name",
"description": "Description",
"values": "Values",
"value_one": "Value",
"value_other": "Values",
"used_in_scenarios": "Used in the following scenarios:",
"other_scenarios_one": "+{{count}} other",
"other_scenarios_other": "+{{count}} others",
"show_less": "show less",
"empty_custom_lists_list": "Reach out to Marble to create your first list.",
"empty_custom_list_values_list": "Reach out to Marble to create your first list value."
"empty_custom_list_values_list": "Create your first list value to see it here.",
"create_list.title": "New List",
"create_list.name_placeholder": "Add a name to your list",
"create_list.description_placeholder": "Add a description",
"create_list.button_accept": "Create new list",
"edit_list.title": "Edit",
"edit_list.button": "Edit",
"delete_list.button": "Delete this list",
"create_value.title": "New value",
"create_value.value_placeholder": "Add a new value to your list",
"delete_list.title": "Delete this list",
"delete_list.content": "Your are about to delete this list. This action is irreversible, do you want to proceed ?",
"delete_value.title": "Delete this value",
"delete_value.value_content": "You are about to delete the value",
"delete_value.no_return": "This action is irreversible, do you want to proceed ?"
}
5 changes: 4 additions & 1 deletion packages/app-builder/public/locales/fr/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
"close": "Fermer",
"errors.unknown": "Une erreur inconnue s'est produite",
"errors.edit.forbidden_not_draft": "Vous ne pouvez modifier qu'une version brouillon d'un scénario.",
"errors.list.duplicate_list_name": "Une liste avec ce nom existe déjà",
"search": "Recherche",
"empty_scenario_iteration_list": "Contactez Marble pour créer votre premier brouillon de scénario."
"empty_scenario_iteration_list": "Contactez Marble pour créer votre premier brouillon de scénario.",
"delete": "Supprimer",
"save": "Sauvegarder"
}
19 changes: 17 additions & 2 deletions packages/app-builder/public/locales/fr/lists.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
{
"description": "Description",
"name": "Nom",
"values": "Valeurs",
"other_scenarios_one": "{{count}} autre",
"other_scenarios_other": "{{count}} autres",
"show_less": "Montrer moins",
"used_in_scenarios": "Utilisé dans les scénarios suivants :",
"empty_custom_lists_list": "Contactez Marble pour créer votre première liste.",
"empty_custom_list_values_list": "Contactez Marble pour créer votre première valeur."
"create_value.title": "Nouvelle valeur",
"create_value.value_placeholder": "Ajouter une nouvelle valeur à votre liste",
"create_list.button_accept": "Creer une nouvelle liste",
"value_other": "Valeurs",
"value_one": "Valeur",
"edit_list.title": "Editer",
"edit_list.button": "Editer",
"delete_list.button": "Supprimer cette liste",
"delete_list.title": "Supprimer cette liste",
"delete_list.content": "Vous allez supprimer cette liste. Cette action est irréversible, voulez-vous continuer ?",
"delete_value.title": "Supprimer cette valeur",
"delete_value.value_content": "Vous allez supprimer cette valeur",
"delete_value.no_return": "Cette action est irréversible, voulez vous continuer ?",
"create_list.title": "Nouvelle liste",
"create_list.name_placeholder": "Ajouter un nom à cette liste",
"create_list.description_placeholder": "Ajouter une description",
"empty_custom_list_values_list": "Créez votre première valeur de liste pour la voir ici."
}
2 changes: 1 addition & 1 deletion packages/app-builder/src/components/Edit/EditAstNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { Combobox, Select } from '@ui-design-system';
import { forwardRef, useCallback, useState } from 'react';
import { useFormContext } from 'react-hook-form';

import { FormControl, FormField, FormItem } from '../Form';
import { useGetOperatorLabel } from '../Scenario/Formula/Operators';
import { FormControl, FormField, FormItem } from './Form';

export function EditAstNode({ name }: { name: string }) {
const { getFieldState, formState } = useFormContext();
Expand Down
4 changes: 2 additions & 2 deletions packages/app-builder/src/components/Edit/RemoveButton.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type ButtonProps } from '@ui-design-system';
import { Trash } from '@ui-icons';
import { Delete } from '@ui-icons';
import clsx from 'clsx';
import * as React from 'react';

Expand All @@ -18,7 +18,7 @@ export const RemoveButton = React.forwardRef<HTMLButtonElement, ButtonProps>(
tabIndex={-1}
ref={ref}
>
<Trash />
<Delete />
</button>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { type AstNode, NewAstNode, NoConstant } from '@app-builder/models';
import { Button, Input } from '@ui-design-system';
import { useFieldArray } from 'react-hook-form';

import { FormControl, FormField, FormItem, FormLabel } from './Form';
import { FormControl, FormField, FormItem, FormLabel } from '../Form';
import { RemoveButton } from './RemoveButton';

export function WildEditAstNode<TName extends string>({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
type ControllerProps,
type FieldPath,
type FieldValues,
FormProvider,
useFormContext,
} from 'react-hook-form';

Expand Down Expand Up @@ -168,6 +167,5 @@ export {
FormItem,
FormLabel,
FormMessage,
FormProvider,
useFormField,
};
1 change: 1 addition & 0 deletions packages/app-builder/src/components/Form/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './FormField';
16 changes: 8 additions & 8 deletions packages/app-builder/src/components/MarbleToaster.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { getClientEnv } from '@app-builder/utils/environment.client';
import { use } from 'i18next';
import { useEffect } from 'react';
import { toast, Toaster } from 'react-hot-toast';
import { useTranslation } from 'react-i18next';
Expand All @@ -13,6 +12,7 @@ const toastMessageScema = z.object({
'common:errors.unknown',
'common:empty_scenario_iteration_list',
'common:errors.edit.forbidden_not_draft',
'common:errors.list.duplicate_list_name',
]),
});

Expand All @@ -38,17 +38,17 @@ export function MarbleToaster({
}) {
const { t } = useTranslation(['common']);

const type = toastMessage?.type;
const message = toastMessage?.messageKey
? t(toastMessage.messageKey)
: undefined;

useEffect(() => {
const type = toastMessage?.type;
const message = toastMessage?.messageKey
? t(toastMessage.messageKey)
: undefined;

if (!type || !message) {
return;
}
toast[type](getMessage(message));
}, [message, type]);
}, [t, toastMessage]);

return <Toaster position="bottom-center" />;
}
Expand All @@ -62,7 +62,7 @@ function getMessage(message: string) {
<div className="flex flex-col gap-1">
<p className="text-s text-grey-100">{message}</p>
<p className="text-grey-50 text-xs">
In dev, toast are displayed twice due to strict mode
In dev, toast may be displayed twice due to strict mode
</p>
</div>
);
Expand Down
9 changes: 9 additions & 0 deletions packages/app-builder/src/repositories/http-errors.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { type HttpError } from 'oazapfts';

export function isHttpError(error: unknown): error is HttpError {
return error instanceof Error && 'status' in error;
}

export function isStatusConflictHttpError(error: unknown): error is HttpError {
return isHttpError(error) && error.status === 409;
}
1 change: 1 addition & 0 deletions packages/app-builder/src/repositories/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './editor';
export * from './http-errors';
export * from './repositories';
Loading

0 comments on commit d7fc246

Please sign in to comment.