Skip to content

Commit

Permalink
Merge branch 'main' into fix/fix-lines-not-wrapping-sanction-check-match
Browse files Browse the repository at this point in the history
  • Loading branch information
ChibiBlasphem authored Mar 4, 2025
2 parents 5963257 + 7f3d1c5 commit d7ac1cf
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/app-builder/src/components/ExternalLink.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import clsx from 'clsx';
import { forwardRef } from 'react';
import { cn } from 'ui-design-system';

export const linkClasses =
'hover:text-purple-60 focus:text-purple-60 font-semibold lowercase text-purple-65 hover:underline focus:underline';
Expand All @@ -9,7 +9,7 @@ export const ExternalLink = forwardRef<HTMLAnchorElement, React.ComponentPropsWi
return (
<a
ref={ref}
className={clsx(linkClasses, className)}
className={cn(linkClasses, className)}
target="_blank"
rel="noopener noreferrer"
{...otherProps}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { type AstNode, NewEmptyTriggerAstNode } from '@app-builder/models';
import {
type AstNode,
isUndefinedAstNode,
NewEmptyTriggerAstNode,
NewUndefinedAstNode,
} from '@app-builder/models';
import { useCurrentRuleValidationRule } from '@app-builder/routes/_builder+/scenarios+/$scenarioId+/i+/$iterationId+/_layout';
import { useTriggerValidationFetcher } from '@app-builder/routes/ressources+/scenarios+/$scenarioId+/$iterationId+/validate-with-given-trigger-or-rule';
import { useEditorMode } from '@app-builder/services/editor';
import { useAstNodeEditor, useValidateAstNode } from '@app-builder/services/editor/ast-editor';
import { useGetScenarioErrorMessage } from '@app-builder/services/validation';
import { useEffect } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { hasSubObject } from 'remeda';
import { Button } from 'ui-design-system';
import { useStore } from 'zustand';

import { AstBuilder, type AstBuilderProps } from '../AstBuilder';
Expand Down Expand Up @@ -41,11 +48,13 @@ export const FieldTrigger = ({
iterationId: string;
options: AstBuilderProps['options'];
}) => {
const { t } = useTranslation(['scenarios']);
const editor = useEditorMode();

const astEditorStore = useAstNodeEditor({
initialAstNode: trigger ?? NewEmptyTriggerAstNode(),
initialAstNode: trigger ?? NewUndefinedAstNode(),
});
const isTriggerNull = isUndefinedAstNode(astEditorStore.getState().rootAstNode);

const astNode = useStore(astEditorStore, (state) => state.rootAstNode);

Expand All @@ -57,10 +66,52 @@ export const FieldTrigger = ({
onChange?.(hasSubObject(NewEmptyTriggerAstNode(), astNode) ? undefined : astNode);
}, [astNode, onChange]);

const handleAddTrigger = () => {
astEditorStore.setState({
rootAstNode: NewEmptyTriggerAstNode(),
});
};

const handleDeleteTrigger = () => {
astEditorStore.setState({
rootAstNode: NewUndefinedAstNode(),
});
};

return (
<div onBlur={onBlur}>
<AstBuilder viewOnly={editor === 'view'} astEditorStore={astEditorStore} options={options} />
{type === 'rule' ? <EvaluationErrorsWrapper /> : null}
<div onBlur={onBlur} className="flex flex-col gap-4">
{isTriggerNull ? (
<div className="border-blue-58 bg-blue-96 text-blue-58 text-s flex items-center rounded border p-2">
<span>
<Trans
t={t}
i18nKey="scenarios:trigger.trigger_object.no_trigger"
values={{ objectType: options.triggerObjectType }}
/>
</span>
</div>
) : (
<AstBuilder
viewOnly={editor === 'view'}
astEditorStore={astEditorStore}
options={options}
/>
)}
{type === 'rule' ? (
<EvaluationErrorsWrapper />
) : (
<div className="flex justify-end">
{isTriggerNull ? (
<Button type="button" variant="secondary" onClick={handleAddTrigger}>
{t('scenarios:trigger.trigger_object.add_trigger')}
</Button>
) : (
<Button type="button" variant="secondary" onClick={handleDeleteTrigger}>
{t('scenarios:trigger.trigger_object.delete_trigger')}
</Button>
)}
</div>
)}
</div>
);
};
10 changes: 8 additions & 2 deletions packages/app-builder/src/constants/sanction-check-entity.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ExternalLink } from '@app-builder/components/ExternalLink';
import { type SanctionCheckEntitySchema } from '@app-builder/models/sanction-check';

export type PropertyDataType = 'string' | 'country' | 'url' | 'date';
export type PropertyDataType = 'string' | 'country' | 'url' | 'date' | 'wikidataId';
export type PropertyForSchema<
Schema extends SanctionCheckEntitySchema,
_R = never,
Expand Down Expand Up @@ -169,7 +169,7 @@ const propertyMetadata = {
weakAlias: { type: 'string' },
website: { type: 'url' },
weight: { type: 'string' },
wikidataId: { type: 'string' },
wikidataId: { type: 'wikidataId' },
} satisfies Record<SanctionCheckEntityProperty, { type: PropertyDataType }>;

export function getSanctionEntityProperties(schema: SanctionCheckEntitySchema) {
Expand Down Expand Up @@ -212,6 +212,12 @@ export function createPropertyTransformer(ctx: { language: string; formatLanguag
}
case 'date':
return <time dateTime={value}>{intlDate.format(new Date(value))}</time>;
case 'wikidataId':
return (
<ExternalLink href={`https://wikidata.org/wiki/${value}`} className="normal-case">
{value}
</ExternalLink>
);
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const editSanctionFormSchema = z.object({
z.literal('decline'),
z.literal('block_and_review'),
]),
triggerRule: z.any().nullish(),
triggerRule: z.any(),
query: z
.object({
name: z.any().nullish(),
Expand Down

0 comments on commit d7ac1cf

Please sign in to comment.