Skip to content

Commit

Permalink
Ensure empty label is written on tags
Browse files Browse the repository at this point in the history
- Tags must be set on initial create to be editable.
  • Loading branch information
sondreb committed Oct 20, 2024
1 parent bcaff8c commit 33b4393
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions app/src/app/apps/app/text/text.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ export class TextComponent implements OnDestroy {
abstract: entry.data.abstract,
background: entry.data.background,
collaborators: [],
labels: entry.data.labels ?? [],
labels: entry.data.labels ?? [''],
published: entry.record ? entry.record.published : entry.data.published,
image: entry.data.image,
};
Expand Down Expand Up @@ -316,15 +316,20 @@ export class TextComponent implements OnDestroy {

// delete data.published;

if (data.labels == null) {
data.labels = [];
}
// We must ensure we always initially save with tags, because we cannot edit
// a record that did not have any initial tags.
let tags = {
labels: [''],
};

// Only set labels on tags if there is any data. It will crash to attempt to save label with empty array.
if (data.labels && data.labels.length > 0) {
tags = {
labels: data.labels,
};
}
if (entry.record) {
// Will this work?
entry.record.tags.labels = data.labels;
// entry.record.tags.title = data.title;
// entry.record.tags.image = data.image ?? '';
entry.record.tags.labels = tags.labels;

const { status } = await entry.record.update({
data: data,
Expand All @@ -334,21 +339,21 @@ export class TextComponent implements OnDestroy {
console.log('Record status:', status);
await entry.record.send();
} else {
const { record, status } = await this.identity.web5.dwn.records.create({
const query: any = {
data: data,
message: {
tags,
published: published,
tags: {
// image: data.image ?? '',
// title: data.title,
labels: data.labels,
},
protocol: textDefinition.protocol,
protocolPath: 'entry',
schema: textDefinition.types.entry.schema,
dataFormat: textDefinition.types.entry.dataFormats[0],
},
});
};

console.log('QUERY:', query);

const { record, status } = await this.identity.web5.dwn.records.create(query);

console.log('Record created:', record);
console.log('Record status:', status);
Expand Down

0 comments on commit 33b4393

Please sign in to comment.