Skip to content

Commit

Permalink
v1.168.0
Browse files Browse the repository at this point in the history
  • Loading branch information
varovaro committed May 27, 2024
2 parents 0c70346 + 1e42b01 commit f12dbbc
Show file tree
Hide file tree
Showing 16 changed files with 313 additions and 95 deletions.
57 changes: 0 additions & 57 deletions app/react/App.tsx

This file was deleted.

23 changes: 23 additions & 0 deletions app/react/App/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -1908,6 +1908,10 @@ input[type="range"]::-ms-fill-lower {
height: 35px;
}

.h-\[37px\] {
height: 37px;
}

.h-\[532px\] {
height: 532px;
}
Expand Down Expand Up @@ -2114,6 +2118,10 @@ input[type="range"]::-ms-fill-lower {
width: 17px;
}

.w-\[37px\] {
width: 37px;
}

.w-auto {
width: auto;
}
Expand Down Expand Up @@ -2192,6 +2200,10 @@ input[type="range"]::-ms-fill-lower {
max-width: 120px;
}

.max-w-\[188px\] {
max-width: 188px;
}

.max-w-lg {
max-width: 32rem;
}
Expand Down Expand Up @@ -2693,6 +2705,11 @@ input[type="range"]::-ms-fill-lower {
border-color: rgb(157 23 77 / var(--tw-border-opacity));
}

.border-gray-100 {
--tw-border-opacity: 1;
border-color: rgb(243 244 246 / var(--tw-border-opacity));
}

.border-gray-200 {
--tw-border-opacity: 1;
border-color: rgb(229 231 235 / var(--tw-border-opacity));
Expand Down Expand Up @@ -3522,6 +3539,12 @@ input[type="range"]::-ms-fill-lower {
outline-style: solid;
}

.ring-0 {
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color);
box-shadow: var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow, 0 0 #0000);
}

.ring-indigo-100 {
--tw-ring-opacity: 1;
--tw-ring-color: rgb(229 237 255 / var(--tw-ring-opacity));
Expand Down
110 changes: 110 additions & 0 deletions app/react/V2/Components/Forms/ColorPicker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/* eslint-disable react/jsx-props-no-spreading */
import React, { useState, useEffect } from 'react';
import { Popover } from '@headlessui/react';
import { InputField } from 'app/V2/Components/Forms';

type ColorPickerProps = {
name: string;
onChange?: (color: string) => void;
value?: string;
className?: string;
hasErrors?: boolean;
};

const defaultColors = [
'#C03B22',
'#D9534F',
'#E91E63',
'#A03AB1',
'#6F46B8',
'#3F51B5',
'#2196F3',
'#37BDCF',
'#359990',
'#5CB85C',
'#8BC34A',
'#CDDC39',
'#CCBC2F',
'#F0AD4E',
'#EC9920',
'#E46841',
'#795548',
'#9E9E9E',
'#607D8B',
];

const ColorPicker = ({
name,
className,
onChange,
hasErrors,
value = defaultColors[0],
}: ColorPickerProps) => {
const [localValue, setLocalValue] = useState(value);

useEffect(() => {
setLocalValue(value);
}, [value]);

const changeColor = (color: string) => {
setLocalValue(color);
if (onChange) {
onChange(color);
}
};

const dynamicStyles = hasErrors ? 'border-error-300' : 'border-gray-100';

return (
<div className={`${className}`}>
<Popover className="">
<Popover.Button
className={`w-[37px] h-[37px] border cursor-pointer rounded-lg ring-0 ${dynamicStyles}`}
>
<div
data-testid="colorpicker-button"
className="m-auto rounded-md w-7 h-7"
style={{ backgroundColor: localValue }}
/>
</Popover.Button>
<Popover.Panel
as="div"
className="flex flex-col gap-2 p-2 bg-white rounded-md shadow max-w-[188px] z-10 m-2"
>
<ul className="flex flex-wrap gap-2" data-testid="colorpicker-popover">
{defaultColors.map((color: string) => (
<li key={color}>
<button
type="button"
className="w-full cursor-pointer"
onClick={() => changeColor(color)}
>
<span className="sr-only">{color}</span>
<div
data-testid="colorpicker-button"
className="m-auto rounded-sm w-7 h-7"
style={{ backgroundColor: color }}
/>
</button>
</li>
))}
</ul>
<InputField
id={name}
type="text"
name={name}
value={localValue.slice(1)}
preText="#"
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
changeColor(`#${e.target.value}`);
}}
className="w-full"
hasErrors={hasErrors}
/>
</Popover.Panel>
</Popover>
</div>
);
};

export { ColorPicker };
1 change: 1 addition & 0 deletions app/react/V2/Components/Forms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export type { MultiSelectProps } from './MultiSelect';
export type { SelectProps, OptionSchema } from './Select';
export { Checkbox } from './Checkbox';
export { EnableButtonCheckbox } from './EnableButtonCheckbox';
export { ColorPicker } from './ColorPicker';
export { DatePicker, DateRangePicker } from './DatePicker/DatePicker';
export { MultiselectList } from './MultiselectList';
13 changes: 6 additions & 7 deletions app/react/V2/Routes/Settings/IX/components/PDFSidepanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ import * as filesAPI from 'V2/api/files';
import * as entitiesAPI from 'V2/api/entities';
import { secondsToISODate } from 'V2/shared/dateHelpers';
import { Button, Sidepanel } from 'V2/Components/UI';
import { InputField } from 'V2/Components/Forms';
import { InputField, MultiselectList } from 'V2/Components/Forms';
import { PDF, selectionHandlers } from 'V2/Components/PDFViewer';
import { notificationAtom, thesaurisAtom } from 'V2/atoms';
import { MultiselectList } from 'V2/Components/Forms';
import { notificationAtom, thesauriAtom } from 'V2/atoms';
import { Highlights } from '../types';

interface PDFSidepanelProps {
Expand Down Expand Up @@ -147,7 +146,7 @@ const PDFSidepanel = ({
const [entity, setEntity] = useState<ClientEntitySchema>();
const [thesaurus, setThesaurus] = useState<any>();
const setNotifications = useSetAtom(notificationAtom);
const thesauris = useAtomValue(thesaurisAtom);
const thesauris = useAtomValue(thesauriAtom);

const templateId = suggestion?.entityTemplateId;
const propertyValue = getFormValue(suggestion, entity, property?.type);
Expand Down Expand Up @@ -404,7 +403,7 @@ const PDFSidepanel = ({
<Sidepanel.Body>
<form
id="ixpdfform"
className="flex flex-col h-full gap-4 pb-0"
className="flex flex-col gap-4 pb-0 h-full"
onSubmit={handleSubmit(onSubmit)}
>
<div ref={pdfContainerRef} className="md:m-auto md:w-[95%] grow">
Expand All @@ -430,7 +429,7 @@ const PDFSidepanel = ({
</div>
</form>{' '}
</Sidepanel.Body>
<Sidepanel.Footer className="py-0 border border-b-0 border-l-0 border-r-0 border-gray-200 border-t-1">
<Sidepanel.Footer className="py-0 border border-r-0 border-b-0 border-l-0 border-gray-200 border-t-1">
<div className="flex px-4 py-2">
<p className={selectionError ? 'text-pink-600 grow' : 'grow'}>
<Translate className="uppercase" context={templateId}>
Expand All @@ -443,7 +442,7 @@ const PDFSidepanel = ({
</span>
</div>
{labelInputIsOpen && renderLabel()}
<div className="flex justify-end gap-2 px-4 py-2 border border-b-0 border-l-0 border-r-0 border-gray-200 border-t-1">
<div className="flex gap-2 justify-end px-4 py-2 border border-r-0 border-b-0 border-l-0 border-gray-200 border-t-1">
<Button
type="button"
styling="outline"
Expand Down
4 changes: 2 additions & 2 deletions app/react/V2/Routes/Settings/IX/components/SuggestedValue.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { secondsToDate } from 'app/V2/shared/dateHelpers';
import { EntitySuggestionType } from 'shared/types/suggestionType';
import { ClientTemplateSchema } from 'app/istore';
import { Translate } from 'app/I18N';
import { thesaurisAtom } from 'app/V2/atoms';
import { thesauriAtom } from 'V2/atoms';

const SuggestedValue = ({
value,
Expand All @@ -28,7 +28,7 @@ const SuggestedValue = ({
modifiers: [{ name: 'arrow', options: { element: arrowElement } }],
});
const [popoverOpen, setPopoverOpen] = useState(false);
const thesauris = useAtomValue(thesaurisAtom);
const thesauris = useAtomValue(thesauriAtom);

let colorClass = '';
if (!suggestion || suggestion.suggestedValue === '') {
Expand Down
5 changes: 2 additions & 3 deletions app/react/V2/Routes/Settings/Thesauri/ThesaurusForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const ThesaurusForm = () => {
useEffect(() => {
if (thesaurus) {
const values = thesaurus.values || [];
console.log('values', values);
const valuesWithIds = values.map((value: ClientThesaurusValue) => ({
...value,
_id: `temp_${uniqueID()}`,
Expand Down Expand Up @@ -229,7 +228,7 @@ const ThesaurusForm = () => {
/>
<SettingsContent.Body>
<form onSubmit={handleSubmit(formSubmit)} id="edit-thesaurus">
<div data-testid="thesauri" className="border rounded-md shadow-sm border-gray-50">
<div data-testid="thesauri" className="rounded-md border border-gray-50 shadow-sm">
<div className="p-4">
<InputField
clearFieldAction={() => {}}
Expand All @@ -256,7 +255,7 @@ const ThesaurusForm = () => {
</SettingsContent.Body>
<SettingsContent.Footer className="bottom-0 bg-indigo-50">
{selectedThesaurusValue.length ? (
<div className="flex items-center gap-2">
<div className="flex gap-2 items-center">
<Button
type="button"
onClick={deleteSelected}
Expand Down
4 changes: 3 additions & 1 deletion app/react/V2/atoms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export { notificationAtom } from './notificationAtom';
export { settingsAtom } from './settingsAtom';
export { templatesAtom } from './templatesAtom';
export { translationsAtom } from './translationsAtom';
export { thesaurisAtom } from './thesaurisAtom';
export { thesauriAtom } from './thesauriAtom';
export { globalMatomoAtom } from './globalMatomoAtom';
export { userAtom } from './userAtom';
export type { AtomStoreData } from './store';
export type { notificationAtomType } from './notificationAtom';
46 changes: 43 additions & 3 deletions app/react/V2/atoms/store.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,57 @@
import { createStore } from 'jotai';
import { isClient } from 'app/utils';
import { store } from 'app/store';
import { ClientSettings, ClientThesaurus, ClientUserSchema } from 'app/apiResponseTypes';
import { ClientTemplateSchema } from 'app/istore';
import { globalMatomoAtom } from './globalMatomoAtom';
import { relationshipTypesAtom } from './relationshipTypes';
import { settingsAtom } from './settingsAtom';
import { templatesAtom } from './templatesAtom';
import { translationsAtom } from './translationsAtom';
import { userAtom } from './userAtom';
import { thesauriAtom } from './thesauriAtom';

type AtomStoreData = {
globalMatomo?: { url: string; id: string };
locale?: string;
settings?: ClientSettings;
thesauri?: ClientThesaurus[];
templates?: ClientTemplateSchema[];
user?: ClientUserSchema;
};

declare global {
interface Window {
__atomStoreData__?: { globalMatomo: { url: string; id: string } | undefined };
__atomStoreData__?: AtomStoreData;
}
}

const atomStore = createStore();

if (isClient && window.__atomStoreData__?.globalMatomo) {
atomStore.set(globalMatomoAtom, { ...window.__atomStoreData__?.globalMatomo });
if (isClient && window.__atomStoreData__) {
const { globalMatomo, locale, settings, thesauri, templates, user } = window.__atomStoreData__;

if (globalMatomo) atomStore.set(globalMatomoAtom, { ...globalMatomo });
if (settings) atomStore.set(settingsAtom, settings);
if (thesauri) atomStore.set(thesauriAtom, thesauri);
if (templates) atomStore.set(templatesAtom, templates);
atomStore.set(userAtom, user);
atomStore.set(translationsAtom, { locale: locale || 'en' });

//sync deprecated redux store
atomStore.sub(settingsAtom, () => {
const value = atomStore.get(settingsAtom);
store?.dispatch({ type: 'settings/collection/SET', value });
});
atomStore.sub(templatesAtom, () => {
const value = atomStore.get(templatesAtom);
store?.dispatch({ type: 'templates/SET', value });
});
atomStore.sub(relationshipTypesAtom, () => {
const value = atomStore.get(relationshipTypesAtom);
store?.dispatch({ type: 'relationTypes/SET', value });
});
}

export type { AtomStoreData };
export { atomStore };
Loading

0 comments on commit f12dbbc

Please sign in to comment.