Skip to content

Commit

Permalink
Fix a bug where edit link is still visible when it is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed Oct 31, 2023
1 parent 847c642 commit 56a0682
Showing 1 changed file with 29 additions and 59 deletions.
88 changes: 29 additions & 59 deletions functions/internals/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,24 +249,24 @@ export async function syncMainView({
interface toMainViewArgs {
isDebugMode: boolean;
manualEntryPermitted: boolean;
canAccessAdminFeature: () => Promise<boolean>;
view: ModalView;
offset: number;
language: string;
item: SavedAttributes<TE>;
holidays: () => Promise<SavedAttributes<PH> | undefined>;
canAccessAdminFeature: () => Promise<boolean>;
yyyymmdd: string | undefined;
}
export async function toMainView(
{
isDebugMode,
manualEntryPermitted,
canAccessAdminFeature,
view,
offset,
language,
item,
holidays,
canAccessAdminFeature,
yyyymmdd,
}: toMainViewArgs,
): Promise<ModalView> {
Expand All @@ -276,11 +276,11 @@ export async function toMainView(
view.blocks = await mainViewBlocks({
isDebugMode,
manualEntryPermitted,
canAccessAdminFeature,
offset,
language,
item,
holidays,
canAccessAdminFeature,
yyyymmdd,
});
return view;
Expand All @@ -289,21 +289,21 @@ export async function toMainView(
interface mainViewBlocksArgs {
isDebugMode: boolean;
manualEntryPermitted: boolean;
canAccessAdminFeature: () => Promise<boolean>;
offset: number;
language: string;
item: SavedAttributes<TE>;
canAccessAdminFeature: () => Promise<boolean>;
holidays: () => Promise<SavedAttributes<PH> | undefined>;
yyyymmdd: string | undefined;
}
export async function mainViewBlocks({
isDebugMode,
manualEntryPermitted,
canAccessAdminFeature,
offset,
language,
item,
holidays,
canAccessAdminFeature,
yyyymmdd,
}: mainViewBlocksArgs): Promise<AnyModalBlock[]> {
const entries = (item.work_entries || []).map((e) => {
Expand Down Expand Up @@ -357,69 +357,39 @@ export async function mainViewBlocks({
typeLabel = i18n(Label.TimeOff, language);
emoji = Emoji.TimeOff;
}
if (end === "" || end === undefined) {
const options: PlainTextOption[] = [];
if (manualEntryPermitted) {
options.push({
"text": {
"type": "plain_text",
"text": i18n(Label.Edit, language),
},
"value": `edit___${entry}`,
});
}
const options: PlainTextOption[] = [];
if (manualEntryPermitted) {
options.push({
"text": {
"type": "plain_text",
"text": i18n(Label.Delete, language),
},
"value": `delete___${entry}`,
});

entryBlocks.push({
"type": "section",
"text": {
"type": "mrkdwn",
"text": `*${emoji} ${typeLabel}:* ${start} -`,
},
"accessory": {
"type": "overflow",
"action_id": ActionId.EditOrDeleteEntry,
"options": options,
"text": i18n(Label.Edit, language),
},
"value": `edit___${entry}`,
});
}
options.push({
"text": {
"type": "plain_text",
"text": i18n(Label.Delete, language),
},
"value": `delete___${entry}`,
});
if (end === undefined) end === "";
const label = `*${emoji} ${typeLabel}:* ${start} - ${end}`;
entryBlocks.push({
"type": "section",
"text": { "type": "mrkdwn", "text": label },
"accessory": {
"type": "overflow",
"action_id": ActionId.EditOrDeleteEntry,
"options": options,
},
});
if (end === "" || end === undefined) {
if (type === EntryType.BreakTime) {
breakTime = true;
}
businessHours = true;
} else {
entryBlocks.push({
"type": "section",
"text": {
"type": "mrkdwn",
"text": `*${emoji} ${typeLabel}:* ${start} - ${end}`,
},
"accessory": {
"type": "overflow",
"action_id": ActionId.EditOrDeleteEntry,
"options": [
{
"text": {
"type": "plain_text",
"text": i18n(Label.Edit, language),
},
"value": `edit___${entry}`,
},
{
"text": {
"type": "plain_text",
"text": i18n(Label.Delete, language),
},
"value": `delete___${entry}`,
},
],
},
});
}
}

Expand Down

0 comments on commit 56a0682

Please sign in to comment.