Skip to content

Commit

Permalink
Merge branch 'master' into issue-27393-edit-content-expose-editableAs…
Browse files Browse the repository at this point in the history
…Text-even-if-not-present
  • Loading branch information
jcastro-dotcms authored Jan 24, 2024
2 parents 6540478 + 3afdf5a commit 3869d73
Show file tree
Hide file tree
Showing 17 changed files with 193 additions and 166 deletions.
1 change: 1 addition & 0 deletions core-web/libs/dotcms-scss/angular/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,5 @@ code {
background-color: $color-accessible-text-purple-bg;
padding: $spacing-0 $spacing-1;
font-family: $font-code;
line-break: anywhere;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</div>

<div class="preview-metadata__container">
<span class="preview-metadata_header">{{ metadata.name }}</span>
<span class="preview-metadata_header">{{ title }}</span>
<div class="preview-metadata" *ngIf="metadata.width && metadata.height">
<i class="pi pi-arrows-alt"></i>
<span>{{ metadata.width }} x {{ metadata.height }}</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ export class DotBinaryFieldPreviewComponent implements OnChanges {
return this.tempFile?.metadata || this.contentletMetadata;
}

get title(): string {
return this.contentlet?.fileName || this.metadata.name;
}

get contentletMetadata(): DotFileMetadata {
const { metaData = '', fieldVariable = '' } = this.contentlet;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,10 @@ describe('DotEditContentBinaryFieldComponent', () => {
const spyEmit = jest.spyOn(spectator.component.valueUpdated, 'emit');
spectator.detectChanges();
store.setTempFile(TEMP_FILE_MOCK);
expect(spyEmit).toHaveBeenCalledWith(TEMP_FILE_MOCK.id);
expect(spyEmit).toHaveBeenCalledWith({
value: TEMP_FILE_MOCK.id,
fileName: TEMP_FILE_MOCK.fileName
});
});

it('should not emit new value is is equal to current value', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ import { InputTextModule } from 'primeng/inputtext';
import { delay, filter, skip, tap } from 'rxjs/operators';

import { DotLicenseService, DotMessageService } from '@dotcms/data-access';
import {
DotCMSBaseTypesContentTypes,
DotCMSContentTypeField,
DotCMSContentlet,
DotCMSTempFile
} from '@dotcms/dotcms-models';
import { DotCMSContentTypeField, DotCMSContentlet, DotCMSTempFile } from '@dotcms/dotcms-models';
import {
DotDropZoneComponent,
DotMessagePipe,
Expand Down Expand Up @@ -90,7 +85,7 @@ export class DotEditContentBinaryFieldComponent
@Input() contentlet: DotCMSContentlet;
@Input() imageEditor = false;

@Output() valueUpdated = new EventEmitter<string>();
@Output() valueUpdated = new EventEmitter<{ value: string; fileName: string }>();
@ViewChild('inputFile') inputFile: ElementRef;

private onChange: (value: string) => void;
Expand All @@ -111,13 +106,6 @@ export class DotEditContentBinaryFieldComponent
return this.field.variable;
}

private get metaDataKey(): string {
const { baseType } = this.contentlet;
const isFileAsset = baseType === DotCMSBaseTypesContentTypes.FILEASSET;

return isFileAsset ? 'metaData' : this.variable + 'MetaData';
}

get value(): string {
return this.contentlet?.[this.variable] ?? this.field.defaultValue;
}
Expand All @@ -144,11 +132,11 @@ export class DotEditContentBinaryFieldComponent
this.dotBinaryFieldStore.value$
.pipe(
skip(1),
filter((value) => value !== this.value)
filter(({ value }) => value !== this.value)
)
.subscribe((value) => {
.subscribe(({ value, fileName }) => {
this.tempId = value; // If the value changes, it means that a new file was uploaded
this.valueUpdated.emit(value);
this.valueUpdated.emit({ value, fileName });

if (this.onChange) {
this.onChange(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ describe('DotBinaryFieldStore', () => {

// Skip initial state
store.value$.pipe(skip(1)).subscribe((value) => {
expect(value).toBe(TEMP_FILE_MOCK.id);
expect(value).toEqual({
value: TEMP_FILE_MOCK.id,
fileName: TEMP_FILE_MOCK.fileName
});
done();
});

Expand Down Expand Up @@ -197,7 +200,7 @@ describe('DotBinaryFieldStore', () => {

const NEW_BINARY_FIELD_CONTENTLET = {
...BINARY_FIELD_CONTENTLET,
fileAsset: '12345',
fileAssetVersion: '12345',
metaData
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { from, Observable, of } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';

import { switchMap, tap, map, catchError } from 'rxjs/operators';
import { switchMap, tap, map, catchError, distinctUntilChanged } from 'rxjs/operators';

import { DotLicenseService, DotUploadService } from '@dotcms/data-access';
import { DotCMSContentlet, DotCMSTempFile } from '@dotcms/dotcms-models';
Expand Down Expand Up @@ -53,7 +53,10 @@ export class DotBinaryFieldStore extends ComponentStore<BinaryFieldState> {
isLoading: state.status === BinaryFieldStatus.UPLOADING
}));

readonly value$ = this.select((state) => state.value);
readonly value$ = this.select(({ value, tempFile }) => ({
value,
fileName: tempFile?.fileName
})).pipe(distinctUntilChanged((previous, current) => previous.value === current.value));

constructor(
private readonly dotUploadService: DotUploadService,
Expand Down Expand Up @@ -177,10 +180,10 @@ export class DotBinaryFieldStore extends ComponentStore<BinaryFieldState> {
return contentlet$.pipe(
tap(() => this.setUploading()),
switchMap((contentlet) => {
const { fileAsset, metaData, fieldVariable } = contentlet;
const { fileAssetVersion, metaData, fieldVariable } = contentlet;
const metadata = metaData || contentlet[`${fieldVariable}MetaData`];
const { contentType: mimeType, editableAsText, name } = metadata || {};
const contentURL = fileAsset || contentlet[fieldVariable];
const contentURL = fileAssetVersion || contentlet[`${fieldVariable}Version`];
const obs$ = editableAsText ? this.getFileContent(contentURL) : of('');

return obs$.pipe(
Expand Down
2 changes: 1 addition & 1 deletion core-web/libs/sdk/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"next": "14.0.4",
"react": "^18",
"react-dom": "^18",
"@dotcms/react": "0.0.1-alpha.4",
"@dotcms/react": "0.0.1-alpha.5",
"@dotcms/client": "0.0.1-alpha.4"
},
"description": "Official NextJS library to render a dotCMS page.",
Expand Down
2 changes: 1 addition & 1 deletion core-web/libs/sdk/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dotcms/react",
"version": "0.0.1-alpha.4",
"version": "0.0.1-alpha.5",
"peerDependencies": {
"react": "^18",
"react-dom": "^18",
Expand Down
52 changes: 28 additions & 24 deletions core-web/libs/sdk/react/src/lib/components/Column/Column.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -46,50 +46,54 @@
grid-column-start: 12;
}

.col-span-1 {
grid-column: span 1 / span 1;
.col-end-1 {
grid-column-end: 1;
}

.col-span-2 {
grid-column: span 2 / span 2;
.col-end-2 {
grid-column-end: 2;
}

.col-span-3 {
grid-column: span 3 / span 3;
.col-end-3 {
grid-column-end: 3;
}

.col-span-4 {
grid-column: span 4 / span 4;
.col-end-4 {
grid-column-end: 4;
}

.col-span-5 {
grid-column: span 5 / span 5;
.col-end-5 {
grid-column-end: 5;
}

.col-span-6 {
grid-column: span 6 / span 6;
.col-end-6 {
grid-column-end: 6;
}

.col-span-7 {
grid-column: span 7 / span 7;
.col-end-7 {
grid-column-end: 7;
}

.col-span-8 {
grid-column: span 8 / span 8;
.col-end-8 {
grid-column-end: 8;
}

.col-span-9 {
grid-column: span 9 / span 9;
.col-end-9 {
grid-column-end: 9;
}

.col-span-10 {
grid-column: span 10 / span 10;
.col-end-10 {
grid-column-end: 10;
}

.col-span-11 {
grid-column: span 11 / span 11;
.col-end-11 {
grid-column-end: 11;
}

.col-span-12 {
grid-column: span 12 / span 12;
.col-end-12 {
grid-column-end: 12;
}

.col-end-13 {
grid-column-end: 13;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('Column', () => {

it('applies the correct width and start classes based on props', () => {
const columnElement = screen.getByTestId('column');
expect(columnElement).toHaveClass('col-span-6');
expect(columnElement).toHaveClass('col-end-9');
expect(columnElement).toHaveClass('col-start-3');
});

Expand Down
7 changes: 5 additions & 2 deletions core-web/libs/sdk/react/src/lib/components/Column/Column.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ export function Column({ column }: ColumnProps) {
const { isInsideEditor } = useContext<PageProviderContext | null>(
PageContext
) as PageProviderContext;
const { widthClass, startClass } = getPositionStyleClasses(column.width, column.leftOffset);
const { startClass, endClass } = getPositionStyleClasses(
column.leftOffset,
column.width + column.leftOffset
);

const combinedClasses = combineClasses([
styles[widthClass],
styles[endClass],
styles[startClass],
column.styleClass
]);
Expand Down
39 changes: 20 additions & 19 deletions core-web/libs/sdk/react/src/lib/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { ContainerData, PageProviderContext } from '../components/PageProvider/PageProvider';

const widthClassMap: Record<number, string> = {
1: 'col-span-1',
2: 'col-span-2',
3: 'col-span-3',
4: 'col-span-4',
5: 'col-span-5',
6: 'col-span-6',
7: 'col-span-7',
8: 'col-span-8',
9: 'col-span-9',
10: 'col-span-10',
11: 'col-span-11',
12: 'col-span-12'
const endClassMap: Record<number, string> = {
1: 'col-end-1',
2: 'col-end-2',
3: 'col-end-3',
4: 'col-end-4',
5: 'col-end-5',
6: 'col-end-6',
7: 'col-end-7',
8: 'col-end-8',
9: 'col-end-9',
10: 'col-end-10',
11: 'col-end-11',
12: 'col-end-12',
13: 'col-end-13'
};

const statrClassMap: Record<number, string> = {
const startClassMap: Record<number, string> = {
1: 'col-start-1',
2: 'col-start-2',
3: 'col-start-3',
Expand Down Expand Up @@ -145,12 +146,12 @@ export const getContainersData = (

export const combineClasses = (classes: string[]) => classes.filter(Boolean).join(' ');

export const getPositionStyleClasses = (width: number, leftOffset: number) => {
const widthClass = widthClassMap[width];
const startClass = statrClassMap[leftOffset];
export const getPositionStyleClasses = (start: number, end: number) => {
const startClass = startClassMap[start];
const endClass = endClassMap[end];

return {
widthClass,
startClass
startClass,
endClass
};
};
15 changes: 14 additions & 1 deletion dotCMS/src/assembly/descriptor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,20 @@
<fileMode>0755</fileMode>
<directoryMode>0755</directoryMode>
</fileSet>
<fileSet>
<directory>${assembly-directory}/conf</directory>
<outputDirectory>temp</outputDirectory>
<excludes>
<exclude>**/*</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>${assembly-directory}/conf</directory>
<outputDirectory>/logs</outputDirectory>
<excludes>
<exclude>**/*</exclude>
</excludes>
</fileSet>
<fileSet>
<directory>${assembly-directory}</directory>
<outputDirectory></outputDirectory>
Expand All @@ -47,7 +61,6 @@
<exclude>**/felix-cache/**</exclude>
<exclude>**/webapps/cargorpc/**</exclude>
<exclude>**/work/**</exclude>
<exclude>**/temp/**</exclude>
<exclude>**/logs/**</exclude>
<exclude>**/lib/**</exclude>
<exclude>**/shared/**</exclude>
Expand Down
Loading

0 comments on commit 3869d73

Please sign in to comment.