Skip to content

Commit

Permalink
feat: proper handling of the updated asset
Browse files Browse the repository at this point in the history
  • Loading branch information
illfixit committed Aug 5, 2024
1 parent f0551c5 commit 9b1dba8
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/app/core/services/asset-data-source-mapper-legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ export class AssetDataSourceMapperLegacy {
buildDataSourceOrNullLegacy(
formValue: AssetDatasourceFormValue,
): UiDataSource | null {
if (formValue.dataAddressType === 'Unchanged') {
if (
!formValue?.dataAddressType ||
formValue.dataAddressType === 'Unchanged'
) {
return null;
}
return this.buildDataSourceLegacy(formValue);
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/validators/url-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const urlValidator: ValidatorFn = (
): ValidationErrors | null => {
const value: string = control.value;

if (!value.length || validUrlPattern.test(value)) {
if (!value?.length || validUrlPattern.test(value)) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export class AssetEditDialogComponent implements OnDestroy {
takeUntil(this.ngOnDestroy$),
tap(() => {
this.notificationService.showInfo('Successfully saved asset');
console.log('Successfully saved asset', formValue);
}),
catchError((error) => {
console.error('Failed saving asset!', error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export class AssetEditDialogFormMapper {
private emptyEditDatasource(): AssetDatasourceFormValue {
return {
...this.emptyHttpDatasource(),
dataAddressType: 'Http',
dataAddressType: 'Unchanged',
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class AssetPageComponent implements OnInit, OnDestroy {

onAssetClick(asset: UiAssetMapped) {
const onAssetEditClick: OnAssetEditClickFn = (asset, onAssetUpdated) => {
this.onEdit(asset);
this.onEdit(asset, onAssetUpdated);
};

const buildDialogData = (asset: UiAssetMapped) =>
Expand All @@ -85,11 +85,24 @@ export class AssetPageComponent implements OnInit, OnDestroy {
});
}

onEdit(asset: UiAssetMapped) {
onEdit(
asset: UiAssetMapped,
onAssetUpdated: (updatedDialogData: any) => void,
) {
this.assetEditDialogService
.showEditDialog(asset, this.ngOnDestroy$)
.subscribe((result) => {
if (result?.refreshedList) {
onAssetUpdated(
this.assetDetailDialogDataService.assetDetailsEditable(
result.asset,
{
onAssetEditClick: () => {
this.onEdit(result.asset, onAssetUpdated);
},
},
),
);
this.refresh();
}
});
Expand Down

0 comments on commit 9b1dba8

Please sign in to comment.